summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-23 10:39:35 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-23 15:11:19 +0000
commit12db7515f17228798d1aa38fce0fee3e7d2d36b6 (patch)
treee291daf9e6a88ba0248670b9f1ba3a555f052538 /xfa
parent3bb0a34cc75abe49a59c6390353957bbb5c5ab38 (diff)
downloadpdfium-12db7515f17228798d1aa38fce0fee3e7d2d36b6.tar.xz
Convert string Find methods to return an Optional
The Find and ReverseFind methods for WideString, WideStringC, ByteString, and ByteStringC have been converted from returning a raw FX_STRSIZE, to returning Optional<FX_STRSIZE>, so that success/failure can be indicated without using FX_STRNPOS. This allows for removing FX_STRNPOS and by association makes the conversion of FX_STRSIZE to size_t easier, since it forces checking the return value of Find to be explictly done as well as taking the error value out of the range of FX_STRSIZE. New Contains methods have been added for cases where the success or failure is all the call site to Find cared about, and the actual position was ignored. BUG=pdfium:828 Change-Id: Id827e508c8660affa68cc08a13d96121369364b7 Reviewed-on: https://pdfium-review.googlesource.com/11350 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fgas/crt/cfgas_formatstring.cpp56
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp2
-rw-r--r--xfa/fwl/cfwl_combolist.cpp4
-rw-r--r--xfa/fxfa/cxfa_ffdocview.cpp2
-rw-r--r--xfa/fxfa/cxfa_pdffontmgr.cpp25
-rw-r--r--xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp39
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp12
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp33
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp10
-rw-r--r--xfa/fxfa/parser/cxfa_localevalue.cpp18
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp13
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp14
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp43
13 files changed, 141 insertions, 130 deletions
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index b20fa082c3..9da8bb9583 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -190,12 +190,9 @@ bool GetNumericDotIndex(const CFX_WideString& wsNum,
}
ccf++;
}
- *iDotIndex = wsNum.Find('.');
- if (*iDotIndex != FX_STRNPOS)
- return true;
-
- *iDotIndex = iLenf;
- return false;
+ auto result = wsNum.Find('.');
+ *iDotIndex = result.value_or(iLenf);
+ return result.has_value();
}
bool ExtractCountDigits(const wchar_t* str,
@@ -249,7 +246,7 @@ bool ParseLocaleDate(const CFX_WideString& wsDate,
*cc += iLiteralLen;
ccf++;
continue;
- } else if (wsDateSymbols.Find(strf[ccf]) == FX_STRNPOS) {
+ } else if (!wsDateSymbols.Contains(strf[ccf])) {
if (strf[ccf] != str[*cc])
return false;
(*cc)++;
@@ -370,7 +367,7 @@ bool ParseLocaleTime(const CFX_WideString& wsTime,
ccf++;
continue;
}
- if (wsTimeSymbols.Find(strf[ccf]) == FX_STRNPOS) {
+ if (!wsTimeSymbols.Contains(strf[ccf])) {
if (strf[ccf] != str[*cc])
return false;
(*cc)++;
@@ -577,7 +574,7 @@ CFX_WideString DateFormat(const CFX_WideString& wsDatePattern,
ccf++;
continue;
}
- if (wsDateSymbols.Find(strf[ccf]) == FX_STRNPOS) {
+ if (!wsDateSymbols.Contains(strf[ccf])) {
wsResult += strf[ccf++];
continue;
}
@@ -635,7 +632,7 @@ CFX_WideString TimeFormat(const CFX_WideString& wsTimePattern,
int32_t lenf = wsTimePattern.GetLength();
uint16_t wHour = hour;
bool bPM = false;
- if (wsTimePattern.Find('A') != FX_STRNPOS) {
+ if (wsTimePattern.Contains('A')) {
if (wHour >= 12)
bPM = true;
}
@@ -647,7 +644,7 @@ CFX_WideString TimeFormat(const CFX_WideString& wsTimePattern,
ccf++;
continue;
}
- if (wsTimeSymbols.Find(strf[ccf]) == FX_STRNPOS) {
+ if (!wsTimeSymbols.Contains(strf[ccf])) {
wsResult += strf[ccf++];
continue;
}
@@ -874,7 +871,7 @@ FX_LOCALECATEGORY CFGAS_FormatString::GetCategory(
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
GetLiteralText(pStr, &ccf, iLenf);
- } else if (!bBraceOpen && wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
+ } else if (!bBraceOpen && !wsConstChars.Contains(pStr[ccf])) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (true) {
@@ -932,7 +929,7 @@ CFX_WideString CFGAS_FormatString::GetTextFormat(
int32_t iCurChar = ccf;
GetLiteralText(pStr, &ccf, iLenf);
wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
- } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
+ } else if (!bBrackOpen && !wsConstChars.Contains(pStr[ccf])) {
CFX_WideString wsSearchCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
@@ -984,7 +981,7 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat(
int32_t iCurChar = ccf;
GetLiteralText(pStr, &ccf, iLenf);
*wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
- } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
+ } else if (!bBrackOpen && !wsConstChars.Contains(pStr[ccf])) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
@@ -1030,8 +1027,8 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat(
ASSERT(pLocale);
wsSubCategory = pLocale->GetNumPattern(eSubCategory);
- *iDotIndex = wsSubCategory.Find('.');
- if (*iDotIndex != 0 && *iDotIndex != FX_STRNPOS) {
+ auto result = wsSubCategory.Find('.');
+ if (result.has_value() && result.value() != 0) {
*iDotIndex += wsPurgePattern->GetLength();
bFindDot = true;
*dwStyle |= FX_NUMSTYLE_DotVorv;
@@ -1177,9 +1174,8 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
// If we're looking for a '.', 'V' or 'v' and the input string does not
// have a dot index for one of those, then we disable parsing the decimal.
if (!GetNumericDotIndex(wsSrcNum, wsDotSymbol, &dot_index) &&
- (dwFormatStyle & FX_NUMSTYLE_DotVorv)) {
+ (dwFormatStyle & FX_NUMSTYLE_DotVorv))
bReverseParse = true;
- }
// This parse is broken into two parts based on the '.' in the number
// (or 'V' or 'v'). |dot_index_f| is the location of the dot in the format and
@@ -1570,7 +1566,7 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat(
GetLiteralText(pStr, &ccf, iLenf);
wsTempPattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
} else if (!bBraceOpen && iFindCategory != 3 &&
- wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
+ !wsConstChars.Contains(pStr[ccf])) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
@@ -1950,12 +1946,12 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
bool bAddNeg = false;
const wchar_t* str = wsSrcNum.c_str();
int len = wsSrcNum.GetLength();
- int dot_index = wsSrcNum.Find('.');
- if (dot_index == FX_STRNPOS)
+ auto dot_index = wsSrcNum.Find('.');
+ if (!dot_index.has_value())
dot_index = len;
ccf = dot_index_f - 1;
- cc = dot_index - 1;
+ cc = dot_index.value() - 1;
while (ccf >= 0) {
switch (strf[ccf]) {
case '9':
@@ -2089,7 +2085,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
}
if (cc >= 0) {
- int nPos = dot_index % 3;
+ int nPos = dot_index.value() % 3;
wsOutput->clear();
for (int32_t i = 0; i < dot_index; i++) {
if (i % 3 == nPos && i != 0)
@@ -2098,7 +2094,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
}
if (dot_index < len) {
*wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal);
- *wsOutput += wsSrcNum.Right(len - dot_index - 1);
+ *wsOutput += wsSrcNum.Right(len - dot_index.value() - 1);
}
if (bNeg) {
*wsOutput =
@@ -2126,7 +2122,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
}
ccf = dot_index_f + 1;
- cc = dot_index + 1;
+ cc = dot_index.value() + 1;
while (ccf < lenf) {
switch (strf[ccf]) {
case '\'':
@@ -2281,8 +2277,8 @@ bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime,
return false;
CFX_DateTime dt;
- int32_t iT = wsSrcDateTime.Find(L"T");
- if (iT == FX_STRNPOS) {
+ auto iT = wsSrcDateTime.Find(L"T");
+ if (!iT.has_value()) {
if (eCategory == FX_DATETIMETYPE_Date &&
FX_DateFromCanonical(wsSrcDateTime, &dt)) {
*wsOutput = FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, true,
@@ -2296,9 +2292,9 @@ bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime,
return true;
}
} else {
- CFX_WideString wsSrcDate(wsSrcDateTime.c_str(), iT);
- CFX_WideStringC wsSrcTime(wsSrcDateTime.c_str() + iT + 1,
- wsSrcDateTime.GetLength() - iT - 1);
+ CFX_WideString wsSrcDate(wsSrcDateTime.c_str(), iT.value());
+ CFX_WideStringC wsSrcTime(wsSrcDateTime.c_str() + iT.value() + 1,
+ wsSrcDateTime.GetLength() - iT.value() - 1);
if (wsSrcDate.IsEmpty() || wsSrcTime.IsEmpty())
return false;
if (FX_DateFromCanonical(wsSrcDate, &dt) &&
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 813a91dc63..36cf10581a 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -1267,7 +1267,7 @@ void CFGAS_FontMgr::GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) {
int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1,
const CFX_WideString& Name2) {
- if (Name1.Find(Name2.c_str()) != FX_STRNPOS)
+ if (Name1.Contains(Name2.c_str()))
return 1;
return 0;
}
diff --git a/xfa/fwl/cfwl_combolist.cpp b/xfa/fwl/cfwl_combolist.cpp
index 5b700a90de..f334f027e7 100644
--- a/xfa/fwl/cfwl_combolist.cpp
+++ b/xfa/fwl/cfwl_combolist.cpp
@@ -33,8 +33,8 @@ int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) {
for (int32_t i = 0; i < iCount; i++) {
CFWL_ListItem* hItem = GetItem(this, i);
CFX_WideString wsText = hItem ? hItem->GetText() : L"";
- FX_STRSIZE pos = wsText.Find(wsMatch.c_str());
- if (!pos)
+ auto pos = wsText.Find(wsMatch.c_str());
+ if (pos.has_value() && pos.value() == 0)
return i;
}
return -1;
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index ff20188a92..95faeb3606 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") == FX_STRNPOS)
+ if (!wsValidateStr.Contains(L"preSubmit"))
return XFA_EVENTERROR_Success;
}
diff --git a/xfa/fxfa/cxfa_pdffontmgr.cpp b/xfa/fxfa/cxfa_pdffontmgr.cpp
index af94ee8c82..5872078fdf 100644
--- a/xfa/fxfa/cxfa_pdffontmgr.cpp
+++ b/xfa/fxfa/cxfa_pdffontmgr.cpp
@@ -121,30 +121,29 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
CFX_ByteString bsDRName = bsDRFontName;
bsDRName.Remove('-');
FX_STRSIZE iPsLen = bsPsName.GetLength();
- FX_STRSIZE nIndex = bsDRName.Find(bsPsName);
- if (nIndex != FX_STRNPOS && !bStrictMatch)
+ auto nIndex = bsDRName.Find(bsPsName);
+ if (nIndex.has_value() && !bStrictMatch)
return true;
- if (nIndex != 0)
+ if (!nIndex.has_value() || nIndex.value() != 0)
return false;
int32_t iDifferLength = bsDRName.GetLength() - iPsLen;
if (iDifferLength > 1 || (bBold || bItalic)) {
- FX_STRSIZE iBoldIndex = bsDRName.Find("Bold");
- bool bBoldFont = iBoldIndex != FX_STRNPOS;
- if (bBold != bBoldFont)
+ auto iBoldIndex = bsDRName.Find("Bold");
+ if (bBold != iBoldIndex.has_value())
return false;
- if (bBoldFont) {
- iDifferLength =
- std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4);
+ if (iBoldIndex.has_value()) {
+ iDifferLength = std::min(iDifferLength - 4,
+ bsDRName.GetLength() - iBoldIndex.value() - 4);
}
bool bItalicFont = true;
- if (bsDRName.Find("Italic") != FX_STRNPOS) {
+ if (bsDRName.Contains("Italic")) {
iDifferLength -= 6;
- } else if (bsDRName.Find("It") != FX_STRNPOS) {
+ } else if (bsDRName.Contains("It")) {
iDifferLength -= 2;
- } else if (bsDRName.Find("Oblique") != FX_STRNPOS) {
+ } else if (bsDRName.Contains("Oblique")) {
iDifferLength -= 7;
} else {
bItalicFont = false;
@@ -158,7 +157,7 @@ bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
bsDRTailer == "Regular" || bsDRTailer == "Reg") {
return true;
}
- if (bBoldFont || bItalicFont)
+ if (iBoldIndex.has_value() || bItalicFont)
return false;
bool bMatch = false;
diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
index 5912d26a99..a028538198 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -374,8 +374,9 @@ bool PatternStringType(const CFX_ByteStringC& szPattern,
return true;
}
if (L"date" == wsPattern.Left(4)) {
- FX_STRSIZE ret = wsPattern.Find(L"time");
- patternType = ret != 0 && ret != FX_STRNPOS ? XFA_VT_DATETIME : XFA_VT_DATE;
+ auto pos = wsPattern.Find(L"time");
+ patternType =
+ pos.has_value() && pos.value() != 0 ? XFA_VT_DATETIME : XFA_VT_DATE;
return true;
}
if (L"time" == wsPattern.Left(4)) {
@@ -1139,12 +1140,12 @@ void CXFA_FM2JSContext::IsoTime2Num(CFXJSE_Value* pThis,
CXFA_Document* pDoc = pContext->GetDocument();
CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
CFX_ByteString szArgString = ValueToUTF8String(argOne.get());
- FX_STRSIZE pos = szArgString.Find('T', 0);
- szArgString = szArgString.Right(szArgString.GetLength() - (pos + 1));
- if (szArgString.IsEmpty()) {
+ auto pos = szArgString.Find('T', 0);
+ if (!pos.has_value() || pos.value() == szArgString.GetLength() - 1) {
args.GetReturnValue()->SetInteger(0);
return;
}
+ szArgString = szArgString.Right(szArgString.GetLength() - (pos.value() + 1));
CXFA_LocaleValue timeValue(
XFA_VT_TIME, CFX_WideString::FromUTF8(szArgString.AsStringC()), pMgr);
@@ -3077,8 +3078,8 @@ void CXFA_FM2JSContext::At(CFXJSE_Value* pThis,
}
CFX_ByteString stringOne = ValueToUTF8String(argOne.get());
- FX_STRSIZE iPosition = stringOne.Find(stringTwo.AsStringC());
- args.GetReturnValue()->SetInteger(iPosition + 1);
+ auto pos = stringOne.Find(stringTwo.AsStringC());
+ args.GetReturnValue()->SetInteger(pos.has_value() ? pos.value() + 1 : 0);
}
// static
@@ -3689,13 +3690,18 @@ void CXFA_FM2JSContext::Format(CFXJSE_Value* pThis,
if (!PatternStringType(szPattern.AsStringC(), patternType)) {
switch (patternType) {
case XFA_VT_DATETIME: {
- FX_STRSIZE iTChar = wsPattern.Find(L'T');
+ auto iTChar = wsPattern.Find(L'T');
+ if (!iTChar.has_value()) {
+ args.GetReturnValue()->SetString("");
+ return;
+ }
CFX_WideString wsDatePattern(L"date{");
- wsDatePattern += wsPattern.Left(iTChar) + L"} ";
+ wsDatePattern += wsPattern.Left(iTChar.value()) + L"} ";
CFX_WideString wsTimePattern(L"time{");
wsTimePattern +=
- wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) + L"}";
+ wsPattern.Right(wsPattern.GetLength() - (iTChar.value() + 1)) +
+ L"}";
wsPattern = wsDatePattern + wsTimePattern;
} break;
case XFA_VT_DATE: {
@@ -3878,11 +3884,16 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis,
switch (patternType) {
case XFA_VT_DATETIME: {
- FX_STRSIZE iTChar = wsPattern.Find(L'T');
- CFX_WideString wsDatePattern(L"date{" + wsPattern.Left(iTChar) + L"} ");
+ auto iTChar = wsPattern.Find(L'T');
+ if (!iTChar.has_value()) {
+ args.GetReturnValue()->SetString("");
+ return;
+ }
+ CFX_WideString wsDatePattern(L"date{" + wsPattern.Left(iTChar.value()) +
+ L"} ");
CFX_WideString wsTimePattern(
- L"time{" + wsPattern.Right(wsPattern.GetLength() - (iTChar + 1)) +
- L"}");
+ L"time{" +
+ wsPattern.Right(wsPattern.GetLength() - (iTChar.value() + 1)) + L"}");
wsPattern = wsDatePattern + wsTimePattern;
CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
pMgr);
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index b502bbdfa7..05586e12dd 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -226,14 +226,14 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
std::vector<CFX_WideString> wsSelTextArray;
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;
+ auto iEnd = wsRawValue.Find(L'\n', iStart);
+ iEnd = !iEnd.has_value() ? wsRawValue.GetLength() : iEnd;
+ while (iEnd.has_value() && iEnd >= iStart) {
+ wsSelTextArray.push_back(
+ wsRawValue.Mid(iStart, iEnd.value() - iStart));
+ iStart = iEnd.value() + 1;
if (iStart >= wsRawValue.GetLength())
break;
-
iEnd = wsRawValue.Find(L'\n', iStart);
}
CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index f43deaf145..85d2758467 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -305,15 +305,17 @@ XFA_VERSION CXFA_Document::RecognizeXFAVersionNumber(
wsTemplateURIPrefix) {
return XFA_VERSION_UNKNOWN;
}
- FX_STRSIZE nDotPos = wsTemplateNS.Find('.', nPrefixLength);
- if (nDotPos == FX_STRNPOS)
+ auto nDotPos = wsTemplateNS.Find('.', nPrefixLength);
+ if (!nDotPos.has_value())
return XFA_VERSION_UNKNOWN;
int8_t iMajor = FXSYS_wtoi(
- wsTemplateNS.Mid(nPrefixLength, nDotPos - nPrefixLength).c_str());
- int8_t iMinor = FXSYS_wtoi(
- wsTemplateNS.Mid(nDotPos + 1, wsTemplateNS.GetLength() - nDotPos - 2)
- .c_str());
+ wsTemplateNS.Mid(nPrefixLength, nDotPos.value() - nPrefixLength).c_str());
+ int8_t iMinor =
+ FXSYS_wtoi(wsTemplateNS
+ .Mid(nDotPos.value() + 1,
+ wsTemplateNS.GetLength() - nDotPos.value() - 2)
+ .c_str());
XFA_VERSION eVersion = (XFA_VERSION)((int32_t)iMajor * 100 + iMinor);
if (eVersion < XFA_VERSION_MIN || eVersion > XFA_VERSION_MAX)
return XFA_VERSION_UNKNOWN;
@@ -367,20 +369,21 @@ void CXFA_Document::DoProtoMerge() {
CFX_WideStringC wsURI, wsID, wsSOM;
if (pUseHrefNode->TryCData(XFA_ATTRIBUTE_Usehref, wsUseVal) &&
!wsUseVal.IsEmpty()) {
- FX_STRSIZE uSharpPos = wsUseVal.Find('#');
- if (uSharpPos == FX_STRNPOS) {
+ auto uSharpPos = wsUseVal.Find('#');
+ if (!uSharpPos.has_value()) {
wsURI = wsUseVal.AsStringC();
} else {
- wsURI = CFX_WideStringC(wsUseVal.c_str(), uSharpPos);
+ wsURI = CFX_WideStringC(wsUseVal.c_str(), uSharpPos.value());
FX_STRSIZE uLen = wsUseVal.GetLength();
- if (uLen >= uSharpPos + 5 &&
- CFX_WideStringC(wsUseVal.c_str() + uSharpPos, 5) == L"#som(" &&
+ if (uLen >= uSharpPos.value() + 5 &&
+ CFX_WideStringC(wsUseVal.c_str() + uSharpPos.value(), 5) ==
+ L"#som(" &&
wsUseVal[uLen - 1] == ')') {
- wsSOM = CFX_WideStringC(wsUseVal.c_str() + uSharpPos + 5,
- uLen - 1 - uSharpPos - 5);
+ wsSOM = CFX_WideStringC(wsUseVal.c_str() + uSharpPos.value() + 5,
+ uLen - 1 - uSharpPos.value() - 5);
} else {
- wsID = CFX_WideStringC(wsUseVal.c_str() + uSharpPos + 1,
- uLen - uSharpPos - 1);
+ wsID = CFX_WideStringC(wsUseVal.c_str() + uSharpPos.value() + 1,
+ uLen - uSharpPos.value() - 1);
}
}
} else if (pUseHrefNode->TryCData(XFA_ATTRIBUTE_Use, wsUseVal) &&
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index e643bc502f..b02efbb45d 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -148,11 +148,13 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot,
bool bTargetAllFind = true;
while (iSplitIndex != -1) {
CFX_WideString wsExpr;
- FX_STRSIZE iSplitNextIndex = 0;
+ pdfium::Optional<FX_STRSIZE> iSplitNextIndex = 0;
if (!bTargetAllFind) {
iSplitNextIndex = wsTargetAll.Find(' ', iSplitIndex);
- ASSERT(iSplitNextIndex != FX_STRNPOS);
- wsExpr = wsTargetAll.Mid(iSplitIndex, iSplitNextIndex - iSplitIndex);
+ if (!iSplitNextIndex.has_value())
+ return nullptr;
+ wsExpr =
+ wsTargetAll.Mid(iSplitIndex, iSplitNextIndex.value() - iSplitIndex);
} else {
wsExpr = wsTargetAll;
}
@@ -180,7 +182,7 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot,
if (iCount > 0 && rs.objects.front()->IsNode())
return rs.objects.front()->AsNode();
}
- iSplitIndex = iSplitNextIndex;
+ iSplitIndex = iSplitNextIndex.value();
}
return nullptr;
}
diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp
index aa0f74b170..dd56e6d7a1 100644
--- a/xfa/fxfa/parser/cxfa_localevalue.cpp
+++ b/xfa/fxfa/parser/cxfa_localevalue.cpp
@@ -49,14 +49,14 @@ bool ValueSplitDateTime(const CFX_WideString& wsDateTime,
if (wsDateTime.IsEmpty())
return false;
- FX_STRSIZE nSplitIndex = wsDateTime.Find('T');
- if (nSplitIndex == FX_STRNPOS)
+ auto nSplitIndex = wsDateTime.Find('T');
+ if (!nSplitIndex.has_value())
nSplitIndex = wsDateTime.Find(' ');
- if (nSplitIndex == FX_STRNPOS)
+ if (!nSplitIndex.has_value())
return false;
- wsDate = wsDateTime.Left(nSplitIndex);
- wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1);
+ wsDate = wsDateTime.Left(nSplitIndex.value());
+ wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex.value() - 1);
return true;
}
@@ -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) != FX_STRNPOS;
+ const bool bSymbol = wsDate.Contains(0x2D);
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(':') != FX_STRNPOS;
+ const bool bSymbol = wsTime.Contains(':');
uint16_t wHour = 0;
uint16_t wMinute = 0;
uint16_t wSecond = 0;
@@ -558,8 +558,8 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) {
wSecond = pTime[nIndex] - '0' + wSecond * 10;
nIndex++;
}
- FX_STRSIZE ret = wsTime.Find('.');
- if (ret && ret != FX_STRNPOS) {
+ auto pos = wsTime.Find('.');
+ if (pos.has_value() && pos.value() != 0) {
if (pTime[nIndex] != '.')
return false;
nIndex++;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 2b4bdd22c0..eea7fb2489 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -4045,16 +4045,17 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
if (!wsContent.IsEmpty()) {
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;
+ auto iEnd = wsContent.Find(L'\n', iStart);
+ iEnd = !iEnd.has_value() ? iLength : iEnd;
+ while (iEnd.value() >= iStart) {
+ wsSaveTextArray.push_back(
+ wsContent.Mid(iStart, iEnd.value() - iStart));
+ iStart = iEnd.value() + 1;
if (iStart >= iLength) {
break;
}
iEnd = wsContent.Find(L'\n', iStart);
- if (iEnd == FX_STRNPOS) {
+ if (!iEnd.has_value()) {
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 39dc858b9e..ee2a2444fc 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -92,12 +92,12 @@ bool MatchNodeName(CFX_XMLNode* pNode,
bool GetAttributeLocalName(const CFX_WideStringC& wsAttributeName,
CFX_WideString& wsLocalAttrName) {
CFX_WideString wsAttrName(wsAttributeName);
- FX_STRSIZE iFind = wsAttrName.Find(L':', 0);
- if (iFind == FX_STRNPOS) {
+ auto pos = wsAttrName.Find(L':', 0);
+ if (!pos.has_value()) {
wsLocalAttrName = wsAttrName;
return false;
}
- wsLocalAttrName = wsAttrName.Right(wsAttrName.GetLength() - iFind - 1);
+ wsLocalAttrName = wsAttrName.Right(wsAttrName.GetLength() - pos.value() - 1);
return true;
}
@@ -133,17 +133,17 @@ bool FindAttributeWithNS(CFX_XMLElement* pElement,
CFX_WideString wsAttrNS;
for (auto it : pElement->GetAttributes()) {
- FX_STRSIZE iFind = it.first.Find(L':', 0);
+ auto pos = it.first.Find(L':', 0);
CFX_WideString wsNSPrefix;
- if (iFind == FX_STRNPOS) {
+ if (!pos.has_value()) {
if (wsLocalAttributeName != it.first)
continue;
} else {
if (wsLocalAttributeName !=
- it.first.Right(it.first.GetLength() - iFind - 1)) {
+ it.first.Right(it.first.GetLength() - pos.value() - 1)) {
continue;
}
- wsNSPrefix = it.first.Left(iFind);
+ wsNSPrefix = it.first.Left(pos.value());
}
if (!XFA_FDEExtension_ResolveNamespaceQualifier(
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 5b9f62c93f..2da8820b67 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -42,18 +42,18 @@ bool SplitDateTime(const CFX_WideString& wsDateTime,
if (wsDateTime.IsEmpty())
return false;
- FX_STRSIZE nSplitIndex = wsDateTime.Find('T');
- if (nSplitIndex == FX_STRNPOS)
+ auto nSplitIndex = wsDateTime.Find('T');
+ if (!nSplitIndex.has_value())
nSplitIndex = wsDateTime.Find(' ');
- if (nSplitIndex == FX_STRNPOS)
+ if (!nSplitIndex.has_value())
return false;
- wsDate = wsDateTime.Left(nSplitIndex);
+ wsDate = wsDateTime.Left(nSplitIndex.value());
if (!wsDate.IsEmpty()) {
if (!std::any_of(wsDate.begin(), wsDate.end(), std::iswdigit))
return false;
}
- wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1);
+ wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex.value() - 1);
if (!wsTime.IsEmpty()) {
if (!std::any_of(wsTime.begin(), wsTime.end(), std::iswdigit))
return false;
@@ -849,15 +849,15 @@ std::vector<CFX_WideString> CXFA_WidgetData::GetSelectedItemsValue() {
if (!wsValue.IsEmpty()) {
FX_STRSIZE iStart = 0;
FX_STRSIZE iLength = wsValue.GetLength();
- FX_STRSIZE iEnd = wsValue.Find(L'\n', iStart);
- iEnd = (iEnd == FX_STRNPOS) ? iLength : iEnd;
+ auto iEnd = wsValue.Find(L'\n', iStart);
+ iEnd = (!iEnd.has_value()) ? iLength : iEnd;
while (iEnd >= iStart) {
- wsSelTextArray.push_back(wsValue.Mid(iStart, iEnd - iStart));
- iStart = iEnd + 1;
+ wsSelTextArray.push_back(wsValue.Mid(iStart, iEnd.value() - iStart));
+ iStart = iEnd.value() + 1;
if (iStart >= iLength)
break;
iEnd = wsValue.Find(L'\n', iStart);
- if (iEnd == FX_STRNPOS)
+ if (!iEnd.has_value())
wsSelTextArray.push_back(wsValue.Mid(iStart, iLength - iStart));
}
}
@@ -1315,15 +1315,16 @@ bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float* val) {
CXFA_Node* pUIChild = GetUIChild();
CFX_WideString wsWideNarrowRatio;
if (pUIChild->TryCData(XFA_ATTRIBUTE_WideNarrowRatio, wsWideNarrowRatio)) {
- FX_STRSIZE ptPos = wsWideNarrowRatio.Find(':');
+ auto ptPos = wsWideNarrowRatio.Find(':');
float fRatio = 0;
- if (ptPos != FX_STRNPOS) {
+ if (!ptPos.has_value()) {
fRatio = (float)FXSYS_wtoi(wsWideNarrowRatio.c_str());
} else {
int32_t fA, fB;
- fA = FXSYS_wtoi(wsWideNarrowRatio.Left(ptPos).c_str());
+ fA = FXSYS_wtoi(wsWideNarrowRatio.Left(ptPos.value()).c_str());
fB = FXSYS_wtoi(
- wsWideNarrowRatio.Right(wsWideNarrowRatio.GetLength() - (ptPos + 1))
+ wsWideNarrowRatio
+ .Right(wsWideNarrowRatio.GetLength() - (ptPos.value() + 1))
.c_str());
if (fB)
fRatio = (float)fA / fB;
@@ -1742,9 +1743,8 @@ void CXFA_WidgetData::NormalizeNumStr(const CFX_WideString& wsValue,
wsOutput = wsValue;
wsOutput.TrimLeft('0');
- FX_STRSIZE dot_index = wsOutput.Find('.');
int32_t iFracDigits = 0;
- if (!wsOutput.IsEmpty() && dot_index != FX_STRNPOS &&
+ if (!wsOutput.IsEmpty() && wsOutput.Contains('.') &&
(!GetFracDigits(iFracDigits) || iFracDigits != -1)) {
wsOutput.TrimRight(L"0");
wsOutput.TrimRight(L".");
@@ -1768,13 +1768,12 @@ void CXFA_WidgetData::FormatNumStr(const CFX_WideString& wsValue,
wsSrcNum.Delete(0, 1);
}
int32_t len = wsSrcNum.GetLength();
- FX_STRSIZE dot_index = wsSrcNum.Find('.');
- if (dot_index == FX_STRNPOS)
- dot_index = len;
+ auto dot_index = wsSrcNum.Find('.');
+ dot_index = !dot_index.has_value() ? len : dot_index;
- int32_t cc = dot_index - 1;
+ int32_t cc = dot_index.value() - 1;
if (cc >= 0) {
- int nPos = dot_index % 3;
+ int nPos = dot_index.value() % 3;
wsOutput.clear();
for (int32_t i = 0; i < dot_index; i++) {
if (i % 3 == nPos && i != 0)
@@ -1784,7 +1783,7 @@ void CXFA_WidgetData::FormatNumStr(const CFX_WideString& wsValue,
}
if (dot_index < len) {
wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal);
- wsOutput += wsSrcNum.Right(len - dot_index - 1);
+ wsOutput += wsSrcNum.Right(len - dot_index.value() - 1);
}
if (bNeg) {
wsOutput =