From 316eb864137a0b8eeb0d0d4d698ba83f4946a89c Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 21 Oct 2015 13:29:23 -0400 Subject: 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 . --- core/src/fpdfdoc/doc_formfield.cpp | 50 ++++++++++++++------------------------ 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'core/src/fpdfdoc/doc_formfield.cpp') diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp index aafc17f65c..7e734b4e2f 100644 --- a/core/src/fpdfdoc/doc_formfield.cpp +++ b/core/src/fpdfdoc/doc_formfield.cpp @@ -425,18 +425,10 @@ int CPDF_FormField::CountSelectedItems() { return 0; } } - if (pValue->GetType() == PDFOBJ_STRING) { - if (pValue->GetString().IsEmpty()) { - return 0; - } - return 1; - } - if (pValue->IsNumber()) { - if (pValue->GetString().IsEmpty()) { - return 0; - } - return 1; - } + + if (pValue->IsString() || pValue->IsNumber()) + return pValue->GetString().IsEmpty() ? 0 : 1; + if (pValue->GetType() != PDFOBJ_ARRAY) { return 0; } @@ -454,10 +446,10 @@ int CPDF_FormField::GetSelectedIndex(int index) { return pValue->GetInteger(); CFX_WideString sel_value; - if (pValue->GetType() == PDFOBJ_STRING) { - if (index != 0) { + if (pValue->IsString()) { + if (index != 0) return -1; - } + sel_value = pValue->GetUnicodeText(); } else { if (pValue->GetType() != PDFOBJ_ARRAY) { @@ -535,21 +527,16 @@ FX_BOOL CPDF_FormField::IsItemSelected(int index) { return FALSE; } } - if (pValue->GetType() == PDFOBJ_STRING) { - if (pValue->GetUnicodeText() == opt_value) { - return TRUE; - } - return FALSE; - } + + if (pValue->IsString()) + return (pValue->GetUnicodeText() == opt_value); + if (pValue->IsNumber()) { - if (pValue->GetString().IsEmpty()) { + if (pValue->GetString().IsEmpty()) return FALSE; - } - if (pValue->GetInteger() == index) { - return TRUE; - } - return FALSE; + return (pValue->GetInteger() == index); } + if (pValue->GetType() != PDFOBJ_ARRAY) { return FALSE; } @@ -593,7 +580,7 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index, if (pValue != NULL) { if (m_Type == ListBox) { SelectOption(index, FALSE); - if (pValue->GetType() == PDFOBJ_STRING) { + if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) { m_pDict->RemoveAt("V"); } @@ -734,10 +721,9 @@ CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { if (pOption->GetType() == PDFOBJ_ARRAY) { pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index); } - if (pOption == NULL || pOption->GetType() != PDFOBJ_STRING) { - return CFX_WideString(); - } - return ((CPDF_String*)pOption)->GetUnicodeText(); + + CPDF_String* pString = ToString(pOption); + return pString ? pString->GetUnicodeText() : CFX_WideString(); } CFX_WideString CPDF_FormField::GetOptionLabel(int index) { return GetOptionText(index, 1); -- cgit v1.2.3