summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-21 13:55:38 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-21 13:55:38 -0400
commit1c77edb7b34e03787605b7965784cea38ef9f1d7 (patch)
tree621c8d67cb3d5fd72bceed59e2e5a39c6e037fbe /core/src/fpdfapi/fpdf_parser
parent53d3ab125ef583be8cfac907b308a6551b93067a (diff)
downloadpdfium-1c77edb7b34e03787605b7965784cea38ef9f1d7.tar.xz
Add type cast definitions for CPDF_Name.
This Cl adds ToName, CPDF_Object::AsName and CPDF_Object::IsName and updates the src to use them as needed. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1417823005 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp30
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp7
4 files changed, 26 insertions, 21 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 55c62e2878..cbbfbd7197 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -332,10 +332,9 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
{
CPDF_Object* pDecoder =
pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : NULL;
- if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY &&
- pDecoder->GetType() != PDFOBJ_NAME)) {
+ if (!pDecoder || (pDecoder->GetType() != PDFOBJ_ARRAY && !pDecoder->IsName()))
return FALSE;
- }
+
CPDF_Object* pParams =
pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms")) : NULL;
CFX_ByteStringArray DecoderList;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index b2dc924322..e3d9cd7291 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 AsString();
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 AsString()->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) {
@@ -68,9 +68,10 @@ CFX_ByteStringC CPDF_Object::GetConstString() const {
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());
+ case PDFOBJ_NAME: {
+ CFX_ByteString name = AsName()->m_Name;
+ return CFX_ByteStringC((const uint8_t*)name, name.GetLength());
+ }
case PDFOBJ_REFERENCE: {
CPDF_Reference* pRef = (CPDF_Reference*)(void*)this;
if (pRef->m_pObjList == NULL) {
@@ -178,7 +179,7 @@ void CPDF_Object::SetString(const CFX_ByteString& str) {
AsString()->m_String = str;
return;
case PDFOBJ_NAME:
- ((CPDF_Name*)this)->m_Name = str;
+ AsName()->m_Name = str;
return;
}
ASSERT(FALSE);
@@ -214,7 +215,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
case PDFOBJ_STRING:
return AsString()->Identical(pOther->AsString());
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:
@@ -257,7 +258,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
return new CPDF_String(pString->m_String, pString->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;
@@ -326,9 +327,8 @@ 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);
- }
+ if (const CPDF_Name* pName = AsName())
+ return PDF_DecodeText(pName->m_Name, pCharMap);
return CFX_WideString();
}
void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) {
@@ -357,6 +357,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;
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index d9a745393a..514380eeab 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -3807,8 +3807,9 @@ int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints,
return 0;
}
CPDF_Dictionary* pDict = pObj->GetDict();
- CPDF_Object* pName = pDict ? pDict->GetElement(FX_BSTRC("Type")) : NULL;
- if (pName && pName->GetType() == PDFOBJ_NAME) {
+ CPDF_Name* pName =
+ ToName(pDict ? pDict->GetElement(FX_BSTRC("Type")) : nullptr);
+ if (pName) {
if (pName->GetString() == FX_BSTRC("XRef")) {
m_Pos += m_parser.m_Syntax.SavePos();
xref_offset = pObj->GetDict()->GetInteger(FX_BSTRC("Prev"));
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index 84d1301c60..2c161a7dd4 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -372,12 +372,9 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
case PDFOBJ_NUMBER:
buf << " " << pObj->GetString();
break;
- case PDFOBJ_STRING: {
- CFX_ByteString str = pObj->GetString();
- FX_BOOL bHex = pObj->AsString()->IsHex();
- buf << PDF_EncodeString(str, bHex);
+ case PDFOBJ_STRING:
+ buf << PDF_EncodeString(pObj->GetString(), pObj->AsString()->IsHex());
break;
- }
case PDFOBJ_NAME: {
CFX_ByteString str = pObj->GetString();
buf << FX_BSTRC("/") << PDF_NameEncode(str);