diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-21 13:29:23 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-21 13:29:23 -0400 |
commit | 316eb864137a0b8eeb0d0d4d698ba83f4946a89c (patch) | |
tree | 9268f9369d9382ca3ee8f7496ab71394dfa9daef /core/src/fpdfapi/fpdf_parser | |
parent | 43ce9035a026c7b4f15aa938dc39444d9253ea9f (diff) | |
download | pdfium-316eb864137a0b8eeb0d0d4d698ba83f4946a89c.tar.xz |
Merge to XFA: Add type cast definitions for CPDF_String.
This Cl adds ToString, CPDF_Object::AsString and CPDF_Object::IsString and
updates the src to use them as needed.
BUG=pdfium:201
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1417933002 .
(cherry picked from commit 53d3ab125ef583be8cfac907b308a6551b93067a)
Review URL: https://codereview.chromium.org/1408323006 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp | 9 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 40 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp | 2 |
3 files changed, 30 insertions, 21 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp index 82bfbb56eb..c766dd397f 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp @@ -100,12 +100,10 @@ CFX_WideString CFDF_Document::GetWin32Path() const { CPDF_Dictionary* pDict = m_pRootDict ? m_pRootDict->GetDict(FX_BSTRC("FDF")) : NULL; CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NULL; - if (pFileSpec == NULL) { + if (!pFileSpec) return CFX_WideString(); - } - if (pFileSpec->GetType() == PDFOBJ_STRING) { + if (pFileSpec->IsString()) return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF"))); - } return FPDF_FileSpec_GetWin32Path(pFileSpec); } static CFX_WideString ChangeSlash(const FX_WCHAR* str) { @@ -138,7 +136,8 @@ void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec, } else { result = ChangeSlash(filepath.c_str()); } - if (pFileSpec->GetType() == PDFOBJ_STRING) { + + if (pFileSpec->IsString()) { pFileSpec->SetString(CFX_ByteString::FromUnicode(result)); } else if (CPDF_Dictionary* pFileDict = pFileSpec->AsDictionary()) { pFileDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result)); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index a83d0e47b6..a4bc0c2fa5 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -19,7 +19,7 @@ void CPDF_Object::Release() { void CPDF_Object::Destroy() { switch (m_Type) { case PDFOBJ_STRING: - delete (CPDF_String*)this; + delete AsString(); break; case PDFOBJ_NAME: delete (CPDF_Name*)this; @@ -44,7 +44,7 @@ CFX_ByteString CPDF_Object::GetString() const { case PDFOBJ_NUMBER: return AsNumber()->GetString(); case PDFOBJ_STRING: - return ((CPDF_String*)this)->m_String; + return AsString()->m_String; case PDFOBJ_NAME: return ((CPDF_Name*)this)->m_Name; case PDFOBJ_REFERENCE: { @@ -64,9 +64,10 @@ CFX_ByteString CPDF_Object::GetString() const { } CFX_ByteStringC CPDF_Object::GetConstString() const { switch (m_Type) { - case PDFOBJ_STRING: - return CFX_ByteStringC((const uint8_t*)((CPDF_String*)this)->m_String, - ((CPDF_String*)this)->m_String.GetLength()); + case PDFOBJ_STRING: { + CFX_ByteString str = AsString()->m_String; + return CFX_ByteStringC((const uint8_t*)str, str.GetLength()); + } case PDFOBJ_NAME: return CFX_ByteStringC((const uint8_t*)((CPDF_Name*)this)->m_Name, ((CPDF_Name*)this)->m_Name.GetLength()); @@ -174,7 +175,7 @@ void CPDF_Object::SetString(const CFX_ByteString& str) { AsNumber()->SetString(str); return; case PDFOBJ_STRING: - ((CPDF_String*)this)->m_String = str; + AsString()->m_String = str; return; case PDFOBJ_NAME: ((CPDF_Name*)this)->m_Name = str; @@ -211,7 +212,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const { case PDFOBJ_NUMBER: return AsNumber()->Identical(pOther->AsNumber()); case PDFOBJ_STRING: - return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); + return AsString()->Identical(pOther->AsString()); case PDFOBJ_NAME: return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); case PDFOBJ_ARRAY: @@ -251,9 +252,10 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer : pThis->m_Float); } - case PDFOBJ_STRING: - return new CPDF_String(((CPDF_String*)this)->m_String, - ((CPDF_String*)this)->IsHex()); + case PDFOBJ_STRING: { + const CPDF_String* pString = AsString(); + return new CPDF_String(pString->m_String, pString->IsHex()); + } case PDFOBJ_NAME: return new CPDF_Name(((CPDF_Name*)this)->m_Name); case PDFOBJ_ARRAY: { @@ -314,9 +316,9 @@ CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const { return Clone(); } CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { - if (m_Type == PDFOBJ_STRING) { - return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); - } + if (const CPDF_String* pString = AsString()) + return PDF_DecodeText(pString->m_String, pCharMap); + if (m_Type == PDFOBJ_STREAM) { CPDF_StreamAcc stream; stream.LoadAllData((CPDF_Stream*)this, FALSE); @@ -330,8 +332,8 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { return CFX_WideString(); } void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { - if (m_Type == PDFOBJ_STRING) { - ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); + if (CPDF_String* pString = AsString()) { + pString->m_String = PDF_EncodeText(pUnicodes, len); } else if (m_Type == PDFOBJ_STREAM) { CFX_ByteString result = PDF_EncodeText(pUnicodes, len); ((CPDF_Stream*)this) @@ -363,6 +365,14 @@ const CPDF_Number* CPDF_Object::AsNumber() const { return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr; } +CPDF_String* CPDF_Object::AsString() { + return IsString() ? static_cast<CPDF_String*>(this) : nullptr; +} + +const CPDF_String* CPDF_Object::AsString() const { + return IsString() ? static_cast<const CPDF_String*>(this) : nullptr; +} + CPDF_Number::CPDF_Number(int value) : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp index c34d8122f8..84d1301c60 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp @@ -374,7 +374,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { break; case PDFOBJ_STRING: { CFX_ByteString str = pObj->GetString(); - FX_BOOL bHex = ((CPDF_String*)pObj)->IsHex(); + FX_BOOL bHex = pObj->AsString()->IsHex(); buf << PDF_EncodeString(str, bHex); break; } |