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

Unified Diff: core/fpdfdoc/doc_formfield.cpp

Issue 2001783003: Get rid of CPDF_Object::GetArray(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.cpp ('k') | fpdfsdk/fpdfsave.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfdoc/doc_formfield.cpp
diff --git a/core/fpdfdoc/doc_formfield.cpp b/core/fpdfdoc/doc_formfield.cpp
index 84d9a52dac868d2b01bd6178a439af84a21601fe..9849fa1e35bd1632a14a48ad6cb7f63153878a49 100644
--- a/core/fpdfdoc/doc_formfield.cpp
+++ b/core/fpdfdoc/doc_formfield.cpp
@@ -893,56 +893,37 @@ FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value,
int CPDF_FormField::GetTopVisibleIndex() {
CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
- if (!pObj) {
- return 0;
- }
- return pObj->GetInteger();
+ return pObj ? pObj->GetInteger() : 0;
}
int CPDF_FormField::CountSelectedOptions() {
- CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I");
- if (!pObj) {
- return 0;
- }
- CPDF_Array* pArray = pObj->GetArray();
- if (!pArray) {
- return 0;
- }
- return static_cast<int>(pArray->GetCount());
+ CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
+ return pArray ? pArray->GetCount() : 0;
}
int CPDF_FormField::GetSelectedOptionIndex(int index) {
- CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I");
- if (!pObj) {
+ CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
+ if (!pArray)
return -1;
- }
- CPDF_Array* pArray = pObj->GetArray();
- if (!pArray) {
+
+ int iCount = pArray->GetCount();
+ if (iCount < 0 || index >= iCount)
return -1;
- }
- int iCount = static_cast<int>(pArray->GetCount());
- if (iCount > 0 && index < iCount) {
- return pArray->GetIntegerAt(index);
- }
- return -1;
+ return pArray->GetIntegerAt(index);
}
+
FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) {
- CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I");
- if (!pObj) {
- return FALSE;
- }
- CPDF_Array* pArray = pObj->GetArray();
- if (!pArray) {
+ CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
+ if (!pArray)
return FALSE;
- }
- size_t iCount = pArray->GetCount();
- for (size_t i = 0; i < iCount; i++) {
- if (pArray->GetIntegerAt(i) == iOptIndex) {
+
+ for (CPDF_Object* pObj : *pArray) {
+ if (pObj->GetInteger() == iOptIndex)
return TRUE;
- }
}
return FALSE;
}
+
FX_BOOL CPDF_FormField::SelectOption(int iOptIndex,
FX_BOOL bSelected,
FX_BOOL bNotify) {
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.cpp ('k') | fpdfsdk/fpdfsave.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698