summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc/doc_formfield.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-21 13:29:23 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-21 13:29:23 -0400
commit316eb864137a0b8eeb0d0d4d698ba83f4946a89c (patch)
tree9268f9369d9382ca3ee8f7496ab71394dfa9daef /core/src/fpdfdoc/doc_formfield.cpp
parent43ce9035a026c7b4f15aa938dc39444d9253ea9f (diff)
downloadpdfium-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/fpdfdoc/doc_formfield.cpp')
-rw-r--r--core/src/fpdfdoc/doc_formfield.cpp50
1 files changed, 18 insertions, 32 deletions
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);