Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Unified Diff: core/src/fpdfdoc/doc_formfield.cpp

Issue 1417933002: Add type cast definitions for CPDF_String. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfdoc/doc_formfield.cpp
diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp
index 9ef28836a183b2a346166b98a5d71acb7c531bf3..a6f0527300c002f481756a1a1feb8feb720312e0 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();
Lei Zhang 2015/10/21 16:55:56 This should still return 0 or 1, rather than true/
dsinclair 2015/10/21 17:08:05 Done.
+
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,18 @@ 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);
Tom Sepez 2015/10/21 17:12:50 nit: overparenthesized.
dsinclair 2015/10/21 17:40:01 Done.
+
if (pValue->IsNumber()) {
- if (pValue->GetString().IsEmpty()) {
+ if (pValue->GetString().IsEmpty())
return FALSE;
- }
- if (pValue->GetInteger() == index) {
+ if (pValue->GetInteger() == index)
Lei Zhang 2015/10/21 16:55:56 just return pValue->GetInteger() == index;
dsinclair 2015/10/21 17:08:05 Done.
return TRUE;
- }
return FALSE;
}
+
if (pValue->GetType() != PDFOBJ_ARRAY) {
return FALSE;
}
@@ -593,7 +582,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 +723,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);

Powered by Google App Engine
This is Rietveld 408576698