From 2f2ffece124e4ed4b96d2846263015d4b5ad6c00 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 23 Jul 2015 14:42:09 -0700 Subject: Merge to XFA - else after returns. (cherry picked from commit 3c012fef2bb72c8ec1faa73e11ee35539b2559d6) Original Review URL: https://codereview.chromium.org/1243953004 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1239313005 . --- core/src/fpdfdoc/doc_form.cpp | 208 ++++++++++++++++++++---------------------- 1 file changed, 97 insertions(+), 111 deletions(-) (limited to 'core/src/fpdfdoc/doc_form.cpp') diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index 3740f41510..5a2bd1425b 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -357,12 +357,11 @@ static int CALLBACK EnumFontFamExProc( ENUMLOGFONTEXA *lpelfe, { if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@') != NULL) { return 1; - } else { - LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam; - memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA)); - pData->bFind = TRUE; - return 0; } + LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam; + memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA)); + pData->bFind = TRUE; + return 0; } static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf) { @@ -700,41 +699,39 @@ int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, const CFX_Byte { const FX_CHAR* ptr1 = name1; const FX_CHAR* ptr2 = name2; - if (name1.GetLength() != name2.GetLength()) { - int i = 0; - while (ptr1[i] == ptr2[i]) { - i ++; - } - if (i == name1.GetLength()) { - return 2; - } - if (i == name2.GetLength()) { - return 3; - } - return 0; - } else { + if (name1.GetLength() == name2.GetLength()) { return name1 == name2 ? 1 : 0; } + int i = 0; + while (ptr1[i] == ptr2[i]) { + i ++; + } + if (i == name1.GetLength()) { + return 2; + } + if (i == name2.GetLength()) { + return 3; + } + return 0; } int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, const CFX_WideString& name2) { const FX_WCHAR* ptr1 = name1.c_str(); const FX_WCHAR* ptr2 = name2.c_str(); - if (name1.GetLength() != name2.GetLength()) { - int i = 0; - while (ptr1[i] == ptr2[i]) { - i ++; - } - if (i == name1.GetLength()) { - return 2; - } - if (i == name2.GetLength()) { - return 3; - } - return 0; - } else { + if (name1.GetLength() == name2.GetLength()) { return name1 == name2 ? 1 : 0; } + int i = 0; + while (ptr1[i] == ptr2[i]) { + i ++; + } + if (i == name1.GetLength()) { + return 2; + } + if (i == name2.GetLength()) { + return 3; + } + return 0; } FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString &csFieldName) { @@ -903,115 +900,104 @@ CPDF_FormControl* CPDF_InterForm::GetControlByDict(CPDF_Dictionary* pWidgetDict) } FX_DWORD CPDF_InterForm::CountInternalFields(const CFX_WideString& csFieldName) const { - if (m_pFormDict == NULL) { + if (!m_pFormDict) { return 0; } CPDF_Array* pArray = m_pFormDict->GetArray("Fields"); - if (pArray == NULL) { + if (!pArray) { return 0; } if (csFieldName.IsEmpty()) { return pArray->GetCount(); - } else { - int iLength = csFieldName.GetLength(); - int iPos = 0; - CPDF_Dictionary* pDict = NULL; - while (pArray != NULL) { - CFX_WideString csSub; - if (iPos < iLength && csFieldName[iPos] == L'.') { - iPos ++; - } - while (iPos < iLength && csFieldName[iPos] != L'.') { - csSub += csFieldName[iPos ++]; - } - int iCount = pArray->GetCount(); - FX_BOOL bFind = FALSE; - for (int i = 0; i < iCount; i ++) { - pDict = pArray->GetDict(i); - if (pDict == NULL) { - continue; - } - CFX_WideString csT = pDict->GetUnicodeText("T"); - if (csT == csSub) { - bFind = TRUE; - break; - } - } - if (!bFind) { - return 0; + } + int iLength = csFieldName.GetLength(); + int iPos = 0; + CPDF_Dictionary* pDict = NULL; + while (pArray != NULL) { + CFX_WideString csSub; + if (iPos < iLength && csFieldName[iPos] == L'.') { + iPos ++; + } + while (iPos < iLength && csFieldName[iPos] != L'.') { + csSub += csFieldName[iPos ++]; + } + int iCount = pArray->GetCount(); + FX_BOOL bFind = FALSE; + for (int i = 0; i < iCount; i ++) { + pDict = pArray->GetDict(i); + if (pDict == NULL) { + continue; } - if (iPos >= iLength) { + CFX_WideString csT = pDict->GetUnicodeText("T"); + if (csT == csSub) { + bFind = TRUE; break; } - pArray = pDict->GetArray("Kids"); } - if (pDict == NULL) { + if (!bFind) { return 0; - } else { - pArray = pDict->GetArray("Kids"); - if (pArray == NULL) { - return 1; - } else { - return pArray->GetCount(); - } } + if (iPos >= iLength) { + break; + } + pArray = pDict->GetArray("Kids"); + } + if (!pDict) { + return 0; } + pArray = pDict->GetArray("Kids"); + return pArray ? pArray->GetCount() : 1; } + CPDF_Dictionary* CPDF_InterForm::GetInternalField(FX_DWORD index, const CFX_WideString& csFieldName) const { - if (m_pFormDict == NULL) { - return NULL; + if (!m_pFormDict) { + return nullptr; } CPDF_Array* pArray = m_pFormDict->GetArray("Fields"); - if (pArray == NULL) { - return 0; + if (!pArray) { + return nullptr; } if (csFieldName.IsEmpty()) { return pArray->GetDict(index); - } else { - int iLength = csFieldName.GetLength(); - int iPos = 0; - CPDF_Dictionary* pDict = NULL; - while (pArray != NULL) { - CFX_WideString csSub; - if (iPos < iLength && csFieldName[iPos] == L'.') { - iPos ++; - } - while (iPos < iLength && csFieldName[iPos] != L'.') { - csSub += csFieldName[iPos ++]; - } - int iCount = pArray->GetCount(); - FX_BOOL bFind = FALSE; - for (int i = 0; i < iCount; i ++) { - pDict = pArray->GetDict(i); - if (pDict == NULL) { - continue; - } - CFX_WideString csT = pDict->GetUnicodeText("T"); - if (csT == csSub) { - bFind = TRUE; - break; - } - } - if (!bFind) { - return NULL; + } + int iLength = csFieldName.GetLength(); + int iPos = 0; + CPDF_Dictionary* pDict = NULL; + while (pArray != NULL) { + CFX_WideString csSub; + if (iPos < iLength && csFieldName[iPos] == L'.') { + iPos ++; + } + while (iPos < iLength && csFieldName[iPos] != L'.') { + csSub += csFieldName[iPos ++]; + } + int iCount = pArray->GetCount(); + FX_BOOL bFind = FALSE; + for (int i = 0; i < iCount; i ++) { + pDict = pArray->GetDict(i); + if (pDict == NULL) { + continue; } - if (iPos >= iLength) { + CFX_WideString csT = pDict->GetUnicodeText("T"); + if (csT == csSub) { + bFind = TRUE; break; } - pArray = pDict->GetArray("Kids"); } - if (pDict == NULL) { + if (!bFind) { return NULL; - } else { - pArray = pDict->GetArray("Kids"); - if (pArray == NULL) { - return pDict; - } else { - return pArray->GetDict(index); - } } + if (iPos >= iLength) { + break; + } + pArray = pDict->GetArray("Kids"); + } + if (!pDict) { + return nullptr; } + pArray = pDict->GetArray("Kids"); + return pArray ? pArray->GetDict(index) : pDict; } FX_BOOL CPDF_InterForm::NeedConstructAP() { -- cgit v1.2.3