summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-01 15:16:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-01 19:35:49 +0000
commitda129ab38c3fb6ed3de85ffb6f8938eb31130a53 (patch)
tree1ed3980d91ae9258f917124d69f0276260e34b71 /xfa/fxfa
parentde7c9620c37486413e1f7db4567b4b0cea6a857f (diff)
downloadpdfium-da129ab38c3fb6ed3de85ffb6f8938eb31130a53.tar.xz
Replace raw value for constant error value in string operations
Currently Find() and other methods that return a FX_STRSIZE return -1 to indicate error/failure. This means that there is a lot of magic numbers and magic checks floating around. The standard library for similar operations uses a npos constant. This CL implements FX_STRNPOS, and replaces usages of magic number checking. It also does some type cleanup along the way where it was obvious that FX_STRSIZE should be being used. Removing the magic numbers should make eventually changing FX_STRSIZE to be unsigned easier in the future. BUG=pdfium:828 Change-Id: I67e481e44cf2f75a1698afa8fbee4f375a74c490 Reviewed-on: https://pdfium-review.googlesource.com/9651 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/cxfa_ffdocview.cpp2
-rw-r--r--xfa/fxfa/cxfa_pdffontmgr.cpp16
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp3
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp8
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp3
-rw-r--r--xfa/fxfa/parser/cxfa_localevalue.cpp13
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp10
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp27
10 files changed, 46 insertions, 44 deletions
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 8d1ec2338a..ff20188a92 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -279,7 +279,7 @@ int32_t CXFA_FFDocView::ProcessWidgetEvent(CXFA_EventParam* pParam,
wsValidateStr = pValidateNode->GetContent();
}
- if (wsValidateStr.Find(L"preSubmit") == -1)
+ if (wsValidateStr.Find(L"preSubmit") == FX_STRNPOS)
return XFA_EVENTERROR_Success;
}
diff --git a/xfa/fxfa/cxfa_pdffontmgr.cpp b/xfa/fxfa/cxfa_pdffontmgr.cpp
index 77c4433f98..6e7a2ede4b 100644
--- a/xfa/fxfa/cxfa_pdffontmgr.cpp
+++ b/xfa/fxfa/cxfa_pdffontmgr.cpp
@@ -120,9 +120,9 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
bool bStrictMatch) {
CFX_ByteString bsDRName = bsDRFontName;
bsDRName.Remove('-');
- int32_t iPsLen = bsPsName.GetLength();
- int32_t nIndex = bsDRName.Find(bsPsName);
- if (nIndex != -1 && !bStrictMatch)
+ FX_STRSIZE iPsLen = bsPsName.GetLength();
+ FX_STRSIZE nIndex = bsDRName.Find(bsPsName);
+ if (nIndex != FX_STRNPOS && !bStrictMatch)
return true;
if (nIndex != 0)
@@ -130,8 +130,8 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
int32_t iDifferLength = bsDRName.GetLength() - iPsLen;
if (iDifferLength > 1 || (bBold || bItalic)) {
- int32_t iBoldIndex = bsDRName.Find("Bold");
- bool bBoldFont = iBoldIndex > 0;
+ FX_STRSIZE iBoldIndex = bsDRName.Find("Bold");
+ bool bBoldFont = iBoldIndex != FX_STRNPOS;
if (bBold != bBoldFont)
return false;
@@ -140,11 +140,11 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4);
}
bool bItalicFont = true;
- if (bsDRName.Find("Italic") > 0) {
+ if (bsDRName.Find("Italic") != FX_STRNPOS) {
iDifferLength -= 6;
- } else if (bsDRName.Find("It") > 0) {
+ } else if (bsDRName.Find("It") != FX_STRNPOS) {
iDifferLength -= 2;
- } else if (bsDRName.Find("Oblique") > 0) {
+ } else if (bsDRName.Find("Oblique") != FX_STRNPOS) {
iDifferLength -= 7;
} else {
bItalicFont = false;
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
index 84064efb45..9028642b76 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -374,7 +374,8 @@ bool PatternStringType(const CFX_ByteStringC& szPattern,
return true;
}
if (L"date" == wsPattern.Left(4)) {
- patternType = wsPattern.Find(L"time") > 0 ? XFA_VT_DATETIME : XFA_VT_DATE;
+ FX_STRSIZE ret = wsPattern.Find(L"time");
+ patternType = ret != 0 && ret != FX_STRNPOS ? XFA_VT_DATETIME : XFA_VT_DATE;
return true;
}
if (L"time" == wsPattern.Left(4)) {
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index 49a1f5857b..ff9e981e9f 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -225,10 +225,10 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
break;
std::vector<CFX_WideString> wsSelTextArray;
- int32_t iStart = 0;
- int32_t iEnd = wsRawValue.Find(L'\n', iStart);
- iEnd = (iEnd == -1) ? wsRawValue.GetLength() : iEnd;
- while (iEnd >= iStart) {
+ FX_STRSIZE iStart = 0;
+ FX_STRSIZE iEnd = wsRawValue.Find(L'\n', iStart);
+ iEnd = (iEnd == FX_STRNPOS) ? wsRawValue.GetLength() : iEnd;
+ while (iEnd != FX_STRNPOS && iEnd >= iStart) {
wsSelTextArray.push_back(wsRawValue.Mid(iStart, iEnd - iStart));
iStart = iEnd + 1;
if (iStart >= wsRawValue.GetLength())
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 16b999b9e3..f43deaf145 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -306,7 +306,7 @@ XFA_VERSION CXFA_Document::RecognizeXFAVersionNumber(
return XFA_VERSION_UNKNOWN;
}
FX_STRSIZE nDotPos = wsTemplateNS.Find('.', nPrefixLength);
- if (nDotPos == (FX_STRSIZE)-1)
+ if (nDotPos == FX_STRNPOS)
return XFA_VERSION_UNKNOWN;
int8_t iMajor = FXSYS_wtoi(
@@ -368,7 +368,7 @@ void CXFA_Document::DoProtoMerge() {
if (pUseHrefNode->TryCData(XFA_ATTRIBUTE_Usehref, wsUseVal) &&
!wsUseVal.IsEmpty()) {
FX_STRSIZE uSharpPos = wsUseVal.Find('#');
- if (uSharpPos < 0) {
+ if (uSharpPos == FX_STRNPOS) {
wsURI = wsUseVal.AsStringC();
} else {
wsURI = CFX_WideStringC(wsUseVal.c_str(), uSharpPos);
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index 4d6886d7e1..55851bb34a 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -148,9 +148,10 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot,
bool bTargetAllFind = true;
while (iSplitIndex != -1) {
CFX_WideString wsExpr;
- int32_t iSplitNextIndex = 0;
+ FX_STRSIZE iSplitNextIndex = 0;
if (!bTargetAllFind) {
iSplitNextIndex = wsTargetAll.Find(' ', iSplitIndex);
+ ASSERT(iSplitNextIndex != FX_STRNPOS);
wsExpr = wsTargetAll.Mid(iSplitIndex, iSplitNextIndex - iSplitIndex);
} else {
wsExpr = wsTargetAll;
diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp
index 5b5c27f1d4..aa0f74b170 100644
--- a/xfa/fxfa/parser/cxfa_localevalue.cpp
+++ b/xfa/fxfa/parser/cxfa_localevalue.cpp
@@ -49,10 +49,10 @@ bool ValueSplitDateTime(const CFX_WideString& wsDateTime,
if (wsDateTime.IsEmpty())
return false;
- int nSplitIndex = wsDateTime.Find('T');
- if (nSplitIndex < 0)
+ FX_STRSIZE nSplitIndex = wsDateTime.Find('T');
+ if (nSplitIndex == FX_STRNPOS)
nSplitIndex = wsDateTime.Find(' ');
- if (nSplitIndex < 0)
+ if (nSplitIndex == FX_STRNPOS)
return false;
wsDate = wsDateTime.Left(nSplitIndex);
@@ -444,7 +444,7 @@ bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate,
if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2)
return false;
- const bool bSymbol = wsDate.Find(0x2D) != -1;
+ const bool bSymbol = wsDate.Find(0x2D) != FX_STRNPOS;
uint16_t wYear = 0;
uint16_t wMonth = 0;
uint16_t wDay = 0;
@@ -519,7 +519,7 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) {
const uint16_t wCountM = 2;
const uint16_t wCountS = 2;
const uint16_t wCountF = 3;
- const bool bSymbol = wsTime.Find(':') != -1;
+ const bool bSymbol = wsTime.Find(':') != FX_STRNPOS;
uint16_t wHour = 0;
uint16_t wMinute = 0;
uint16_t wSecond = 0;
@@ -558,7 +558,8 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) {
wSecond = pTime[nIndex] - '0' + wSecond * 10;
nIndex++;
}
- if (wsTime.Find('.') > 0) {
+ FX_STRSIZE ret = wsTime.Find('.');
+ if (ret && ret != FX_STRNPOS) {
if (pTime[nIndex] != '.')
return false;
nIndex++;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 261fee1971..8497e60a74 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -4043,10 +4043,10 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
std::vector<CFX_WideString> wsSaveTextArray;
size_t iSize = 0;
if (!wsContent.IsEmpty()) {
- int32_t iStart = 0;
- int32_t iLength = wsContent.GetLength();
- int32_t iEnd = wsContent.Find(L'\n', iStart);
- iEnd = (iEnd == -1) ? iLength : iEnd;
+ FX_STRSIZE iStart = 0;
+ FX_STRSIZE iLength = wsContent.GetLength();
+ FX_STRSIZE iEnd = wsContent.Find(L'\n', iStart);
+ iEnd = (iEnd == FX_STRNPOS) ? iLength : iEnd;
while (iEnd >= iStart) {
wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
iStart = iEnd + 1;
@@ -4054,7 +4054,7 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
break;
}
iEnd = wsContent.Find(L'\n', iStart);
- if (iEnd < 0) {
+ if (iEnd == FX_STRNPOS) {
wsSaveTextArray.push_back(
wsContent.Mid(iStart, iLength - iStart));
}
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 1b5cccf101..39dc858b9e 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -93,7 +93,7 @@ bool GetAttributeLocalName(const CFX_WideStringC& wsAttributeName,
CFX_WideString& wsLocalAttrName) {
CFX_WideString wsAttrName(wsAttributeName);
FX_STRSIZE iFind = wsAttrName.Find(L':', 0);
- if (iFind < 0) {
+ if (iFind == FX_STRNPOS) {
wsLocalAttrName = wsAttrName;
return false;
}
@@ -135,7 +135,7 @@ bool FindAttributeWithNS(CFX_XMLElement* pElement,
for (auto it : pElement->GetAttributes()) {
FX_STRSIZE iFind = it.first.Find(L':', 0);
CFX_WideString wsNSPrefix;
- if (iFind < 0) {
+ if (iFind == FX_STRNPOS) {
if (wsLocalAttributeName != it.first)
continue;
} else {
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 5efc0ea481..34e3aeaf0f 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -42,11 +42,10 @@ bool SplitDateTime(const CFX_WideString& wsDateTime,
if (wsDateTime.IsEmpty())
return false;
- int nSplitIndex = -1;
- nSplitIndex = wsDateTime.Find('T');
- if (nSplitIndex < 0)
+ FX_STRSIZE nSplitIndex = wsDateTime.Find('T');
+ if (nSplitIndex == FX_STRNPOS)
nSplitIndex = wsDateTime.Find(' ');
- if (nSplitIndex < 0)
+ if (nSplitIndex == FX_STRNPOS)
return false;
wsDate = wsDateTime.Left(nSplitIndex);
@@ -848,17 +847,17 @@ std::vector<CFX_WideString> CXFA_WidgetData::GetSelectedItemsValue() {
CFX_WideString wsValue = GetRawValue();
if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {
if (!wsValue.IsEmpty()) {
- int32_t iStart = 0;
- int32_t iLength = wsValue.GetLength();
- int32_t iEnd = wsValue.Find(L'\n', iStart);
- iEnd = (iEnd == -1) ? iLength : iEnd;
+ FX_STRSIZE iStart = 0;
+ FX_STRSIZE iLength = wsValue.GetLength();
+ FX_STRSIZE iEnd = wsValue.Find(L'\n', iStart);
+ iEnd = (iEnd == FX_STRNPOS) ? iLength : iEnd;
while (iEnd >= iStart) {
wsSelTextArray.push_back(wsValue.Mid(iStart, iEnd - iStart));
iStart = iEnd + 1;
if (iStart >= iLength)
break;
iEnd = wsValue.Find(L'\n', iStart);
- if (iEnd < 0)
+ if (iEnd == FX_STRNPOS)
wsSelTextArray.push_back(wsValue.Mid(iStart, iLength - iStart));
}
}
@@ -1318,7 +1317,7 @@ bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float* val) {
if (pUIChild->TryCData(XFA_ATTRIBUTE_WideNarrowRatio, wsWideNarrowRatio)) {
FX_STRSIZE ptPos = wsWideNarrowRatio.Find(':');
float fRatio = 0;
- if (ptPos >= 0) {
+ if (ptPos != FX_STRNPOS) {
fRatio = (float)FXSYS_wtoi(wsWideNarrowRatio.c_str());
} else {
int32_t fA, fB;
@@ -1743,9 +1742,9 @@ void CXFA_WidgetData::NormalizeNumStr(const CFX_WideString& wsValue,
wsOutput = wsValue;
wsOutput.TrimLeft('0');
- int32_t dot_index = wsOutput.Find('.');
+ FX_STRSIZE dot_index = wsOutput.Find('.');
int32_t iFracDigits = 0;
- if (!wsOutput.IsEmpty() && dot_index >= 0 &&
+ if (!wsOutput.IsEmpty() && dot_index != FX_STRNPOS &&
(!GetFracDigits(iFracDigits) || iFracDigits != -1)) {
wsOutput.TrimRight(L"0");
wsOutput.TrimRight(L".");
@@ -1769,8 +1768,8 @@ void CXFA_WidgetData::FormatNumStr(const CFX_WideString& wsValue,
wsSrcNum.Delete(0, 1);
}
int32_t len = wsSrcNum.GetLength();
- int32_t dot_index = wsSrcNum.Find('.');
- if (dot_index == -1)
+ FX_STRSIZE dot_index = wsSrcNum.Find('.');
+ if (dot_index == FX_STRNPOS)
dot_index = len;
int32_t cc = dot_index - 1;