Chromium Code Reviews| Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
| diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
| index 59800dcd938107ecc8a49e93384ba179db71bfb8..cb558f039278cc13683067e912f73781da02b587 100644 |
| --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
| +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
| @@ -22,7 +22,7 @@ void CPDF_Object::Destroy() { |
| delete (CPDF_String*)this; |
| break; |
| case PDFOBJ_NAME: |
| - delete (CPDF_Name*)this; |
| + delete AsName(); |
| break; |
| case PDFOBJ_ARRAY: |
| delete (CPDF_Array*)this; |
| @@ -46,7 +46,7 @@ CFX_ByteString CPDF_Object::GetString() const { |
| case PDFOBJ_STRING: |
| return ((CPDF_String*)this)->m_String; |
| case PDFOBJ_NAME: |
| - return ((CPDF_Name*)this)->m_Name; |
| + return AsName()->m_Name; |
| case PDFOBJ_REFERENCE: { |
| CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
| if (pRef->m_pObjList == NULL) { |
| @@ -67,9 +67,11 @@ CFX_ByteStringC CPDF_Object::GetConstString() const { |
| case PDFOBJ_STRING: |
| return CFX_ByteStringC((const uint8_t*)((CPDF_String*)this)->m_String, |
| ((CPDF_String*)this)->m_String.GetLength()); |
| - case PDFOBJ_NAME: |
| - return CFX_ByteStringC((const uint8_t*)((CPDF_Name*)this)->m_Name, |
| - ((CPDF_Name*)this)->m_Name.GetLength()); |
| + case PDFOBJ_NAME: { |
| + const CPDF_Name* pName = AsName(); |
| + return CFX_ByteStringC((const uint8_t*)pName->m_Name, |
| + pName->m_Name.GetLength()); |
|
Tom Sepez
2015/10/21 17:26:18
nit: same comment as thestig in last cl about mayb
dsinclair
2015/10/21 17:52:41
Done.
|
| + } |
| case PDFOBJ_REFERENCE: { |
| CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; |
| if (pRef->m_pObjList == NULL) { |
| @@ -177,7 +179,7 @@ void CPDF_Object::SetString(const CFX_ByteString& str) { |
| ((CPDF_String*)this)->m_String = str; |
| return; |
| case PDFOBJ_NAME: |
| - ((CPDF_Name*)this)->m_Name = str; |
| + AsName()->m_Name = str; |
| return; |
| } |
| ASSERT(FALSE); |
| @@ -213,7 +215,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const { |
| case PDFOBJ_STRING: |
| return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); |
| case PDFOBJ_NAME: |
| - return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); |
| + return AsName()->Identical(pOther->AsName()); |
| case PDFOBJ_ARRAY: |
| return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); |
| case PDFOBJ_DICTIONARY: |
| @@ -255,7 +257,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, |
| return new CPDF_String(((CPDF_String*)this)->m_String, |
| ((CPDF_String*)this)->IsHex()); |
| case PDFOBJ_NAME: |
| - return new CPDF_Name(((CPDF_Name*)this)->m_Name); |
| + return new CPDF_Name(AsName()->m_Name); |
| case PDFOBJ_ARRAY: { |
| CPDF_Array* pCopy = new CPDF_Array(); |
| CPDF_Array* pThis = (CPDF_Array*)this; |
| @@ -324,10 +326,9 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { |
| PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); |
| return result; |
| } |
| - if (m_Type == PDFOBJ_NAME) { |
| - return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); |
| - } |
| - return CFX_WideString(); |
| + |
|
Tom Sepez
2015/10/21 17:26:17
nit: I might have not opted for the ? operator her
dsinclair
2015/10/21 17:52:41
Done.
|
| + const CPDF_Name* pName = AsName(); |
| + return pName ? PDF_DecodeText(pName->m_Name, pCharMap) : CFX_WideString(); |
| } |
| void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { |
| if (m_Type == PDFOBJ_STRING) { |
| @@ -355,6 +356,14 @@ const CPDF_Dictionary* CPDF_Object::AsDictionary() const { |
| return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr; |
| } |
| +CPDF_Name* CPDF_Object::AsName() { |
| + return IsName() ? static_cast<CPDF_Name*>(this) : nullptr; |
| +} |
| + |
| +const CPDF_Name* CPDF_Object::AsName() const { |
| + return IsName() ? static_cast<const CPDF_Name*>(this) : nullptr; |
| +} |
| + |
| CPDF_Number* CPDF_Object::AsNumber() { |
| return IsNumber() ? static_cast<CPDF_Number*>(this) : nullptr; |
| } |