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>
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 62b10c9..e9676b1 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -186,8 +186,10 @@
std::ostringstream buf;
TestProcessText(&generator, &buf, pTextObj.get());
CFX_ByteString textString(buf);
- int firstResourceAt = textString.Find('/') + 1;
- int secondResourceAt = textString.ReverseFind('/') + 1;
+ FX_STRSIZE firstResourceAt = textString.Find('/') + 1;
+ FX_STRSIZE secondResourceAt = textString.ReverseFind('/') + 1;
+ EXPECT_NE(FX_STRNPOS, firstResourceAt);
+ EXPECT_NE(FX_STRNPOS, secondResourceAt);
CFX_ByteString firstString = textString.Left(firstResourceAt);
CFX_ByteString midString =
textString.Mid(firstResourceAt, secondResourceAt - firstResourceAt);
@@ -252,7 +254,8 @@
}
CFX_ByteString textString(buf);
- int firstResourceAt = textString.Find('/') + 1;
+ FX_STRSIZE firstResourceAt = textString.Find('/') + 1;
+ EXPECT_NE(FX_STRNPOS, firstResourceAt);
CFX_ByteString firstString = textString.Left(firstResourceAt);
CFX_ByteString lastString =
textString.Right(textString.GetLength() - firstResourceAt);
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 288f9d5..692de0f 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -316,7 +316,7 @@
m_pDocument->GetByteStringPool(), PDF_NameDecode(bsName));
} else {
param.m_Type = ContentParam::NAME;
- if (bsName.Find('#') == -1) {
+ if (bsName.Find('#') == FX_STRNPOS) {
memcpy(param.m_Name.m_Buffer, bsName.raw_str(), bsName.GetLength());
param.m_Name.m_Len = bsName.GetLength();
} else {
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index 0cd4ca9..7025b3e 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -89,7 +89,7 @@
}
CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
- if (bstr.Find('#') == -1)
+ if (bstr.Find('#') == FX_STRNPOS)
return CFX_ByteString(bstr);
int size = bstr.GetLength();
@@ -110,7 +110,7 @@
}
CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig) {
- if (orig.Find('#') == -1)
+ if (orig.Find('#') == FX_STRNPOS)
return orig;
return PDF_NameDecode(orig.AsStringC());
}
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index 2357580..dae7a71 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -96,7 +96,8 @@
CPDF_Dictionary* pRoot = pDoc->GetRoot();
CPDF_Dictionary* pURI = pRoot->GetDictFor("URI");
if (pURI) {
- if (csURI.Find(":", 0) < 1)
+ FX_STRSIZE ret = csURI.Find(":");
+ if (ret == 0 || ret == FX_STRNPOS)
csURI = pURI->GetStringFor("Base") + csURI;
}
return csURI;
diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp
index e0bd4ae..d795e71 100644
--- a/core/fpdftext/cpdf_linkextract.cpp
+++ b/core/fpdftext/cpdf_linkextract.cpp
@@ -22,7 +22,7 @@
FX_STRSIZE FindWebLinkEnding(const CFX_WideString& str,
FX_STRSIZE start,
FX_STRSIZE end) {
- if (str.Find(L'/', start) != -1) {
+ if (str.Find(L'/', start) != FX_STRNPOS) {
// When there is a path and query after '/', most ASCII chars are allowed.
// We don't sanitize in this case.
return end;
@@ -197,7 +197,7 @@
FX_STRSIZE len = str.GetLength();
// First, try to find the scheme.
FX_STRSIZE start = str.Find(kHttpScheme);
- if (start != -1) {
+ if (start != FX_STRNPOS) {
FX_STRSIZE off = start + kHttpSchemeLen; // move after "http".
if (len > off + 4) { // At least "://<char>" follows.
if (str[off] == L's') // "https" scheme is accepted.
@@ -219,7 +219,7 @@
// When there is no scheme, try to find url starting with "www.".
start = str.Find(kWWWAddrStart);
- if (start != -1 && len > start + kWWWAddrStartLen) {
+ if (start != FX_STRNPOS && len > start + kWWWAddrStartLen) {
FX_STRSIZE end =
TrimExternalBracketsFromWebLink(str, start, str.GetLength() - 1);
end = FindWebLinkEnding(str, start, end);
@@ -234,9 +234,9 @@
}
bool CPDF_LinkExtract::CheckMailLink(CFX_WideString* str) {
- int aPos = str->Find(L'@');
- // Invalid when no '@'.
- if (aPos < 1)
+ FX_STRSIZE aPos = str->Find(L'@');
+ // Invalid when no '@' or when starts/ends with '@'.
+ if (aPos == FX_STRNPOS || aPos == 0 || aPos == str->GetLength() - 1)
return false;
// Check the local part.
@@ -263,15 +263,15 @@
// Check the domain name part.
aPos = str->Find(L'@');
- if (aPos < 1)
+ if (aPos < 1 || aPos == FX_STRNPOS)
return false;
str->TrimRight(L'.');
// At least one '.' in domain name, but not at the beginning.
// TODO(weili): RFC5322 allows domain names to be a local name without '.'.
// Check whether we should remove this check.
- int ePos = str->Find(L'.', aPos + 1);
- if (ePos == -1 || ePos == aPos + 1)
+ FX_STRSIZE ePos = str->Find(L'.', aPos + 1);
+ if (ePos == FX_STRNPOS || ePos == aPos + 1)
return false;
// Validate all other chars in domain name.
@@ -295,7 +295,7 @@
pPos = i;
}
- if (str->Find(L"mailto:") == -1)
+ if (str->Find(L"mailto:") == FX_STRNPOS)
*str = L"mailto:" + *str;
return true;
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index fe610ab..adef9f6 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -164,7 +164,7 @@
}
int endIndex;
nResultPos = m_strText.Find(csWord.c_str(), nStartPos);
- if (nResultPos == -1) {
+ if (nResultPos == FX_STRNPOS) {
m_IsFind = false;
return m_IsFind;
}
diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp
index e7e55de..6e01933 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -562,41 +562,41 @@
FX_STRSIZE CFX_ByteString::Find(char ch, FX_STRSIZE nStart) const {
if (!m_pData)
- return -1;
+ return FX_STRNPOS;
if (nStart < 0 || nStart >= m_pData->m_nDataLength)
- return -1;
+ return FX_STRNPOS;
const char* pStr = static_cast<const char*>(
memchr(m_pData->m_String + nStart, ch, m_pData->m_nDataLength - nStart));
- return pStr ? pStr - m_pData->m_String : -1;
+ return pStr ? pStr - m_pData->m_String : FX_STRNPOS;
}
FX_STRSIZE CFX_ByteString::ReverseFind(char ch) const {
if (!m_pData)
- return -1;
+ return FX_STRNPOS;
FX_STRSIZE nLength = m_pData->m_nDataLength;
while (nLength--) {
if (m_pData->m_String[nLength] == ch)
return nLength;
}
- return -1;
+ return FX_STRNPOS;
}
FX_STRSIZE CFX_ByteString::Find(const CFX_ByteStringC& pSub,
FX_STRSIZE nStart) const {
if (!m_pData)
- return -1;
+ return FX_STRNPOS;
FX_STRSIZE nLength = m_pData->m_nDataLength;
if (nStart > nLength)
- return -1;
+ return FX_STRNPOS;
const char* pStr =
FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart,
pSub.unterminated_c_str(), pSub.GetLength());
- return pStr ? (int)(pStr - m_pData->m_String) : -1;
+ return pStr ? (int)(pStr - m_pData->m_String) : FX_STRNPOS;
}
void CFX_ByteString::MakeLower() {
diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp
index bcf6f74..d7f265e 100644
--- a/core/fxcrt/cfx_bytestring_unittest.cpp
+++ b/core/fxcrt/cfx_bytestring_unittest.cpp
@@ -826,22 +826,22 @@
TEST(fxcrt, ByteStringCFind) {
CFX_ByteStringC null_string;
- EXPECT_EQ(-1, null_string.Find('a'));
- EXPECT_EQ(-1, null_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, null_string.Find('a'));
+ EXPECT_EQ(FX_STRNPOS, null_string.Find(0));
CFX_ByteStringC empty_string("");
- EXPECT_EQ(-1, empty_string.Find('a'));
- EXPECT_EQ(-1, empty_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, empty_string.Find('a'));
+ EXPECT_EQ(FX_STRNPOS, empty_string.Find(0));
CFX_ByteStringC single_string("a");
EXPECT_EQ(0, single_string.Find('a'));
- EXPECT_EQ(-1, single_string.Find('b'));
- EXPECT_EQ(-1, single_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, single_string.Find('b'));
+ EXPECT_EQ(FX_STRNPOS, single_string.Find(0));
CFX_ByteStringC longer_string("abccc");
EXPECT_EQ(0, longer_string.Find('a'));
EXPECT_EQ(2, longer_string.Find('c'));
- EXPECT_EQ(-1, longer_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, longer_string.Find(0));
CFX_ByteStringC hibyte_string(
"ab\x8c"
diff --git a/core/fxcrt/cfx_string_c_template.h b/core/fxcrt/cfx_string_c_template.h
index 77f34f6..b87b659 100644
--- a/core/fxcrt/cfx_string_c_template.h
+++ b/core/fxcrt/cfx_string_c_template.h
@@ -127,7 +127,7 @@
FX_STRSIZE Find(CharType ch) const {
const UnsignedType* found = reinterpret_cast<const UnsignedType*>(FXSYS_chr(
reinterpret_cast<const CharType*>(m_Ptr.Get()), ch, m_Length));
- return found ? found - m_Ptr.Get() : -1;
+ return found ? found - m_Ptr.Get() : FX_STRNPOS;
}
CFX_StringCTemplate Mid(FX_STRSIZE index, FX_STRSIZE count) const {
diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp
index d7c1ef2..8937783 100644
--- a/core/fxcrt/cfx_widestring.cpp
+++ b/core/fxcrt/cfx_widestring.cpp
@@ -78,7 +78,7 @@
++pStr;
}
if (nWidth < 0 || nWidth > 128 * 1024)
- return -1;
+ return FX_STRNPOS;
int nPrecision = 0;
if (*pStr == '.') {
pStr++;
@@ -92,7 +92,7 @@
}
}
if (nPrecision < 0 || nPrecision > 128 * 1024)
- return -1;
+ return FX_STRNPOS;
int nModifier = 0;
if (*pStr == L'I' && *(pStr + 1) == L'6' && *(pStr + 2) == L'4') {
pStr += 3;
@@ -662,7 +662,7 @@
va_end(argListCopy);
if (nMaxLen <= 0) {
nMaxLen = GuessSizeForVSWPrintf(pFormat, argListCopy);
- if (nMaxLen <= 0)
+ if (nMaxLen == FX_STRNPOS)
return;
}
while (nMaxLen < 32 * 1024) {
@@ -724,29 +724,29 @@
FX_STRSIZE CFX_WideString::Find(wchar_t ch, FX_STRSIZE nStart) const {
if (!m_pData)
- return -1;
+ return FX_STRNPOS;
if (nStart < 0 || nStart >= m_pData->m_nDataLength)
- return -1;
+ return FX_STRNPOS;
const wchar_t* pStr =
wmemchr(m_pData->m_String + nStart, ch, m_pData->m_nDataLength - nStart);
- return pStr ? pStr - m_pData->m_String : -1;
+ return pStr ? pStr - m_pData->m_String : FX_STRNPOS;
}
FX_STRSIZE CFX_WideString::Find(const CFX_WideStringC& pSub,
FX_STRSIZE nStart) const {
if (!m_pData)
- return -1;
+ return FX_STRNPOS;
FX_STRSIZE nLength = m_pData->m_nDataLength;
if (nStart > nLength)
- return -1;
+ return FX_STRNPOS;
const wchar_t* pStr =
FX_wcsstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart,
pSub.unterminated_c_str(), pSub.GetLength());
- return pStr ? (int)(pStr - m_pData->m_String) : -1;
+ return pStr ? (int)(pStr - m_pData->m_String) : FX_STRNPOS;
}
void CFX_WideString::MakeLower() {
diff --git a/core/fxcrt/cfx_widestring_unittest.cpp b/core/fxcrt/cfx_widestring_unittest.cpp
index 1d6d110..a53e9a3 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -853,22 +853,22 @@
TEST(fxcrt, WideStringCFind) {
CFX_WideStringC null_string;
- EXPECT_EQ(-1, null_string.Find(L'a'));
- EXPECT_EQ(-1, null_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, null_string.Find(L'a'));
+ EXPECT_EQ(FX_STRNPOS, null_string.Find(0));
CFX_WideStringC empty_string(L"");
- EXPECT_EQ(-1, empty_string.Find(L'a'));
- EXPECT_EQ(-1, empty_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, empty_string.Find(L'a'));
+ EXPECT_EQ(FX_STRNPOS, empty_string.Find(0));
CFX_WideStringC single_string(L"a");
EXPECT_EQ(0, single_string.Find(L'a'));
- EXPECT_EQ(-1, single_string.Find(L'b'));
- EXPECT_EQ(-1, single_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, single_string.Find(L'b'));
+ EXPECT_EQ(FX_STRNPOS, single_string.Find(0));
CFX_WideStringC longer_string(L"abccc");
EXPECT_EQ(0, longer_string.Find(L'a'));
EXPECT_EQ(2, longer_string.Find(L'c'));
- EXPECT_EQ(-1, longer_string.Find(0));
+ EXPECT_EQ(FX_STRNPOS, longer_string.Find(0));
CFX_WideStringC hibyte_string(
L"ab\xff08"
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index aef623c..7730866 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -14,7 +14,7 @@
#include "third_party/base/ptr_util.h"
bool FX_atonum(const CFX_ByteStringC& strc, void* pData) {
- if (strc.Find('.') != -1) {
+ if (strc.Find('.') != FX_STRNPOS) {
float* pFloat = static_cast<float*>(pData);
*pFloat = FX_atof(strc);
return false;
diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h
index 5e8aa6c..e928864 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -127,6 +127,10 @@
#include "third_party/base/numerics/safe_conversions.h"
+// Constant used to indicate failure from find methods and other methods that
+// return FX_STRSIZE.
+constexpr FX_STRSIZE FX_STRNPOS = -1;
+
#define FXSYS_strlen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(strlen(ptr))
#define FXSYS_wcslen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(wcslen(ptr))
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp
index 8c2442e..75bf9ee 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -43,14 +43,14 @@
CFX_WideString CFX_XMLElement::GetLocalTagName() const {
FX_STRSIZE iFind = GetName().Find(L':', 0);
- if (iFind < 0)
+ if (iFind == FX_STRNPOS)
return GetName();
return GetName().Right(GetName().GetLength() - iFind - 1);
}
CFX_WideString CFX_XMLElement::GetNamespacePrefix() const {
FX_STRSIZE iFind = GetName().Find(L':', 0);
- if (iFind < 0)
+ if (iFind == FX_STRNPOS)
return CFX_WideString();
return GetName().Left(iFind);
}
diff --git a/core/fxcrt/xml/cxml_parser.cpp b/core/fxcrt/xml/cxml_parser.cpp
index 5ac1f82..35eca52 100644
--- a/core/fxcrt/xml/cxml_parser.cpp
+++ b/core/fxcrt/xml/cxml_parser.cpp
@@ -83,7 +83,7 @@
return;
FX_STRSIZE iStart = bsFullName.Find(':');
- if (iStart == -1) {
+ if (iStart == FX_STRNPOS) {
bsName = bsFullName;
} else {
bsSpace = bsFullName.Left(iStart);
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index 23fcd5b..3cee6de 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -194,13 +194,13 @@
bool FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) {
CFX_ByteString bsName(bsFacename);
bsName.MakeLower();
- return bsName.Find("symbol") > -1;
+ return bsName.Find("symbol") != FX_STRNPOS;
}
bool FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) {
CFX_ByteString bsName(bsFacename);
bsName.MakeLower();
- return bsName.Find("arabic") > -1;
+ return bsName.Find("arabic") != FX_STRNPOS;
}
const uint32_t g_FPFSkiaFontCharsets[] = {
diff --git a/core/fxge/apple/fx_mac_imp.cpp b/core/fxge/apple/fx_mac_imp.cpp
index 78fe164..54aac7b 100644
--- a/core/fxge/apple/fx_mac_imp.cpp
+++ b/core/fxge/apple/fx_mac_imp.cpp
@@ -52,7 +52,7 @@
const char JAPAN_MINCHO[] = "Hiragino Mincho Pro W6";
void GetJapanesePreference(CFX_ByteString* face, int weight, int pitch_family) {
- if (face->Find("Gothic") >= 0) {
+ if (face->Find("Gothic") != FX_STRNPOS) {
*face = JAPAN_GOTHIC;
return;
}
@@ -82,7 +82,7 @@
// Times New Roman. A more sophisticated approach would be to find all the
// fonts in |m_FontList| with |face| in the name, and examine the fonts to
// see which best matches the requested characteristics.
- if (face.Find("Bold") == -1 && face.Find("Italic") == -1) {
+ if (face.Find("Bold") == FX_STRNPOS && face.Find("Italic") == FX_STRNPOS) {
CFX_ByteString new_face = face;
if (weight > 400)
new_face += " Bold";
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index 12e7dd2..f16722c 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -251,11 +251,11 @@
m_pMapper->AddInstalledFont(facename, FX_CHARSET_ANSI);
pInfo->m_Charsets |= CHARSET_FLAG_ANSI;
pInfo->m_Styles = 0;
- if (style.Find("Bold") > -1)
+ if (style.Find("Bold") != FX_STRNPOS)
pInfo->m_Styles |= FXFONT_BOLD;
- if (style.Find("Italic") > -1 || style.Find("Oblique") > -1)
+ if (style.Find("Italic") != FX_STRNPOS || style.Find("Oblique") != FX_STRNPOS)
pInfo->m_Styles |= FXFONT_ITALIC;
- if (facename.Find("Serif") > -1)
+ if (facename.Find("Serif") != FX_STRNPOS)
pInfo->m_Styles |= FXFONT_SERIF;
m_FontList[facename] = std::move(pInfo);
@@ -289,7 +289,7 @@
continue;
int32_t index = bsName.Find(family);
- if (bMatchName && index < 0)
+ if (bMatchName && index == FX_STRNPOS)
continue;
int32_t iSimilarValue =
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index a8e271d..1fd08f2 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -447,7 +447,7 @@
CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face));
str.MakeLower();
- return str.Find("italic") != -1;
+ return str.Find("italic") != FX_STRNPOS;
}
bool CFX_Font::IsBold() const {
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 4c0073a..b8ffe04 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -172,7 +172,7 @@
int CompareFontFamilyString(const void* key, const void* element) {
CFX_ByteString str_key((const char*)key);
const AltFontFamily* family = reinterpret_cast<const AltFontFamily*>(element);
- if (str_key.Find(family->m_pFontName) != -1)
+ if (str_key.Find(family->m_pFontName) != FX_STRNPOS)
return 0;
return FXSYS_stricmp(reinterpret_cast<const char*>(key), family->m_pFontName);
}
@@ -187,8 +187,8 @@
norm.Remove(' ');
norm.Remove('-');
norm.Remove(',');
- int pos = norm.Find('+');
- if (pos > 0)
+ FX_STRSIZE pos = norm.Find('+');
+ if (pos != 0 && pos != FX_STRNPOS)
norm = norm.Left(pos);
norm.MakeLower();
return norm;
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 279e720..310a165 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -337,7 +337,7 @@
return false;
const CFX_ByteString bsPsName = pFont->GetPsName();
- if (bsPsName.Find("+ZJHL") != -1)
+ if (bsPsName.Find("+ZJHL") != FX_STRNPOS)
return false;
if (bsPsName == "CNAAJI+cmex10")
diff --git a/core/fxge/fx_ge_linux.cpp b/core/fxge/fx_ge_linux.cpp
index d9fac3f..0552f1c 100644
--- a/core/fxge/fx_ge_linux.cpp
+++ b/core/fxge/fx_ge_linux.cpp
@@ -45,17 +45,18 @@
int weight,
int pitch_family) {
CFX_ByteString face = facearr;
- if (face.Find("Gothic") >= 0 ||
- face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
- if (face.Find("PGothic") >= 0 ||
- face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
+ if (face.Find("Gothic") != FX_STRNPOS ||
+ face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") != FX_STRNPOS) {
+ if (face.Find("PGothic") != FX_STRNPOS ||
+ face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") != FX_STRNPOS) {
return 0;
}
return 1;
}
- if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) {
- if (face.Find("PMincho") >= 0 ||
- face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) {
+ if (face.Find("Mincho") != FX_STRNPOS ||
+ face.Find("\x96\xbe\x92\xa9") != FX_STRNPOS) {
+ if (face.Find("PMincho") != FX_STRNPOS ||
+ face.Find("\x82\x6f\x96\xbe\x92\xa9") != FX_STRNPOS) {
return 2;
}
return 3;
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 4427755..b707a76 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -503,7 +503,7 @@
void CFX_Win32FontInfo::GetGBPreference(CFX_ByteString& face,
int weight,
int picth_family) {
- if (face.Find("KaiTi") >= 0 || face.Find("\xbf\xac") >= 0) {
+ if (face.Find("KaiTi") != FX_STRNPOS || face.Find("\xbf\xac") != FX_STRNPOS) {
if (m_KaiTi.IsEmpty()) {
m_KaiTi = FindFont("KaiTi");
if (m_KaiTi.IsEmpty()) {
@@ -511,7 +511,8 @@
}
}
face = m_KaiTi;
- } else if (face.Find("FangSong") >= 0 || face.Find("\xb7\xc2\xcb\xce") >= 0) {
+ } else if (face.Find("FangSong") != FX_STRNPOS ||
+ face.Find("\xb7\xc2\xcb\xce") != FX_STRNPOS) {
if (m_FangSong.IsEmpty()) {
m_FangSong = FindFont("FangSong");
if (m_FangSong.IsEmpty()) {
@@ -519,9 +520,11 @@
}
}
face = m_FangSong;
- } else if (face.Find("SimSun") >= 0 || face.Find("\xcb\xce") >= 0) {
+ } else if (face.Find("SimSun") != FX_STRNPOS ||
+ face.Find("\xcb\xce") != FX_STRNPOS) {
face = "SimSun";
- } else if (face.Find("SimHei") >= 0 || face.Find("\xba\xda") >= 0) {
+ } else if (face.Find("SimHei") != FX_STRNPOS ||
+ face.Find("\xba\xda") != FX_STRNPOS) {
face = "SimHei";
} else if (!(picth_family & FF_ROMAN) && weight > 550) {
face = "SimHei";
@@ -533,15 +536,16 @@
void CFX_Win32FontInfo::GetJapanesePreference(CFX_ByteString& face,
int weight,
int picth_family) {
- if (face.Find("Gothic") >= 0 ||
- face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
- if (face.Find("PGothic") >= 0 ||
- face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
+ if (face.Find("Gothic") != FX_STRNPOS ||
+ face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") != FX_STRNPOS) {
+ if (face.Find("PGothic") != FX_STRNPOS ||
+ face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") != FX_STRNPOS) {
face = "MS PGothic";
- } else if (face.Find("UI Gothic") >= 0) {
+ } else if (face.Find("UI Gothic") != FX_STRNPOS) {
face = "MS UI Gothic";
} else {
- if (face.Find("HGSGothicM") >= 0 || face.Find("HGMaruGothicMPRO") >= 0) {
+ if (face.Find("HGSGothicM") != FX_STRNPOS ||
+ face.Find("HGMaruGothicMPRO") != FX_STRNPOS) {
face = "MS PGothic";
} else {
face = "MS Gothic";
@@ -549,9 +553,10 @@
}
return;
}
- if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) {
- if (face.Find("PMincho") >= 0 ||
- face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) {
+ if (face.Find("Mincho") != FX_STRNPOS ||
+ face.Find("\x96\xbe\x92\xa9") != FX_STRNPOS) {
+ if (face.Find("PMincho") != FX_STRNPOS ||
+ face.Find("\x82\x6f\x96\xbe\x92\xa9") != FX_STRNPOS) {
face = "MS PMincho";
} else {
face = "MS Mincho";
@@ -635,7 +640,7 @@
face = "Gulim";
break;
case FX_CHARSET_ChineseTraditional:
- if (face.Find("MSung") >= 0) {
+ if (face.Find("MSung") != FX_STRNPOS) {
face = "MingLiU";
} else {
face = "PMingLiU";
diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp
index 02bf722..f498917 100644
--- a/fpdfsdk/fpdfedittext.cpp
+++ b/fpdfsdk/fpdfedittext.cpp
@@ -39,7 +39,7 @@
int flags = 0;
if (FXFT_Is_Face_fixedwidth(pFont->GetFace()))
flags |= FXFONT_FIXED_PITCH;
- if (font_name.Find("Serif") > -1)
+ if (font_name.Find("Serif") != FX_STRNPOS)
flags |= FXFONT_SERIF;
if (FXFT_Is_Face_Italic(pFont->GetFace()))
flags |= FXFONT_ITALIC;
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index beab7d8..bf52932 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -80,20 +80,20 @@
int nLength = rangstring.GetLength();
CFX_ByteString cbCompareString("0123456789-,");
for (int i = 0; i < nLength; ++i) {
- if (cbCompareString.Find(rangstring[i]) == -1)
+ if (cbCompareString.Find(rangstring[i]) == FX_STRNPOS)
return false;
}
CFX_ByteString cbMidRange;
- int nStringFrom = 0;
- int nStringTo = 0;
+ FX_STRSIZE nStringFrom = 0;
+ FX_STRSIZE nStringTo = 0;
while (nStringTo < nLength) {
nStringTo = rangstring.Find(',', nStringFrom);
- if (nStringTo == -1)
+ if (nStringTo == FX_STRNPOS)
nStringTo = nLength;
cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom);
- int nMid = cbMidRange.Find('-');
- if (nMid == -1) {
+ FX_STRSIZE nMid = cbMidRange.Find('-');
+ if (nMid == FX_STRNPOS) {
long lPageNum = atol(cbMidRange.c_str());
if (lPageNum <= 0 || lPageNum > nCount)
return false;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 052bed5..7cccd2f 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -809,19 +809,19 @@
void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent,
FPDF_DWORD& flag) {
- if (csSrcContent.Find(L" config ", 0) != -1)
+ if (csSrcContent.Find(L" config ", 0) != FX_STRNPOS)
flag |= FXFA_CONFIG;
- if (csSrcContent.Find(L" template ", 0) != -1)
+ if (csSrcContent.Find(L" template ", 0) != FX_STRNPOS)
flag |= FXFA_TEMPLATE;
- if (csSrcContent.Find(L" localeSet ", 0) != -1)
+ if (csSrcContent.Find(L" localeSet ", 0) != FX_STRNPOS)
flag |= FXFA_LOCALESET;
- if (csSrcContent.Find(L" datasets ", 0) != -1)
+ if (csSrcContent.Find(L" datasets ", 0) != FX_STRNPOS)
flag |= FXFA_DATASETS;
- if (csSrcContent.Find(L" xmpmeta ", 0) != -1)
+ if (csSrcContent.Find(L" xmpmeta ", 0) != FX_STRNPOS)
flag |= FXFA_XMPMETA;
- if (csSrcContent.Find(L" xfdf ", 0) != -1)
+ if (csSrcContent.Find(L" xfdf ", 0) != FX_STRNPOS)
flag |= FXFA_XFDF;
- if (csSrcContent.Find(L" form ", 0) != -1)
+ if (csSrcContent.Find(L" form ", 0) != FX_STRNPOS)
flag |= FXFA_FORM;
if (flag == 0) {
flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
@@ -840,11 +840,11 @@
if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0)
return false;
- int pos = srcURL.Find(L'?', 0);
+ FX_STRSIZE pos = srcURL.Find(L'?', 0);
CFX_WideString tmp;
- if (pos == -1) {
+ if (pos == FX_STRNPOS) {
pos = srcURL.Find(L'@', 0);
- if (pos == -1)
+ if (pos == FX_STRNPOS)
return false;
tmp = srcURL.Right(csURL.GetLength() - 7);
@@ -863,7 +863,7 @@
srcURL.TrimRight();
pos = srcURL.Find(L'&', 0);
- tmp = (pos == -1) ? srcURL : srcURL.Left(pos);
+ tmp = (pos == FX_STRNPOS) ? srcURL : srcURL.Left(pos);
tmp.TrimLeft();
tmp.TrimRight();
if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) {
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 06ed64c..f5d3c68 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -526,7 +526,7 @@
CFX_WideString sFullMonths = fullmonths[m];
sFullMonths.MakeLower();
- if (sFullMonths.Find(sMonth.c_str(), 0) != -1) {
+ if (sFullMonths.Find(sMonth.c_str(), 0) != FX_STRNPOS) {
nMonth = m + 1;
i += 4;
j += nSkip;
@@ -932,7 +932,8 @@
pEvent->SelEnd() - pEvent->SelStart());
}
- bool bHasSign = wstrValue.Find(L'-') != -1 && wstrSelected.Find(L'-') == -1;
+ bool bHasSign = wstrValue.Find(L'-') != FX_STRNPOS &&
+ wstrSelected.Find(L'-') == FX_STRNPOS;
if (bHasSign) {
// can't insert "change" in front to sign postion.
if (pEvent->SelStart() == 0) {
@@ -946,7 +947,7 @@
iSepStyle = 0;
const wchar_t cSep = iSepStyle < 2 ? L'.' : L',';
- bool bHasSep = wstrValue.Find(cSep) != -1;
+ bool bHasSep = wstrValue.Find(cSep) != FX_STRNPOS;
for (FX_STRSIZE i = 0; i < wstrChange.GetLength(); ++i) {
if (wstrChange[i] == cSep) {
if (bHasSep) {
@@ -1111,7 +1112,7 @@
CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime);
double dDate = 0.0f;
- if (strValue.Find(L"GMT") != -1) {
+ if (strValue.Find(L"GMT") != FX_STRNPOS) {
// for GMT format time
// such as "Tue Aug 11 14:24:16 GMT+08002009"
dDate = MakeInterDate(strValue);
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 22cc095..cc0a6e5 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -280,7 +280,7 @@
FXFILL_WINDING);
}
- return m_locTextLoc == BC_TEXT_LOC_NONE || contents.Find(' ') == -1 ||
+ return m_locTextLoc == BC_TEXT_LOC_NONE || contents.Find(' ') == FX_STRNPOS ||
ShowChars(contents, device, matrix, m_barWidth, m_multiple);
}
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index f07cce8..d940247 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -191,7 +191,7 @@
ccf++;
}
*iDotIndex = wsNum.Find('.');
- if (*iDotIndex >= 0)
+ if (*iDotIndex != FX_STRNPOS)
return true;
*iDotIndex = iLenf;
@@ -249,7 +249,7 @@
*cc += iLiteralLen;
ccf++;
continue;
- } else if (wsDateSymbols.Find(strf[ccf]) == -1) {
+ } else if (wsDateSymbols.Find(strf[ccf]) == FX_STRNPOS) {
if (strf[ccf] != str[*cc])
return false;
(*cc)++;
@@ -370,7 +370,7 @@
ccf++;
continue;
}
- if (wsTimeSymbols.Find(strf[ccf]) == -1) {
+ if (wsTimeSymbols.Find(strf[ccf]) == FX_STRNPOS) {
if (strf[ccf] != str[*cc])
return false;
(*cc)++;
@@ -577,7 +577,7 @@
ccf++;
continue;
}
- if (wsDateSymbols.Find(strf[ccf]) == -1) {
+ if (wsDateSymbols.Find(strf[ccf]) == FX_STRNPOS) {
wsResult += strf[ccf++];
continue;
}
@@ -635,7 +635,7 @@
int32_t lenf = wsTimePattern.GetLength();
uint16_t wHour = hour;
bool bPM = false;
- if (wsTimePattern.Find('A') != -1) {
+ if (wsTimePattern.Find('A') != FX_STRNPOS) {
if (wHour >= 12)
bPM = true;
}
@@ -647,7 +647,7 @@
ccf++;
continue;
}
- if (wsTimeSymbols.Find(strf[ccf]) == -1) {
+ if (wsTimeSymbols.Find(strf[ccf]) == FX_STRNPOS) {
wsResult += strf[ccf++];
continue;
}
@@ -874,7 +874,7 @@
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
GetLiteralText(pStr, &ccf, iLenf);
- } else if (!bBraceOpen && wsConstChars.Find(pStr[ccf]) == -1) {
+ } else if (!bBraceOpen && wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (true) {
@@ -932,7 +932,7 @@
int32_t iCurChar = ccf;
GetLiteralText(pStr, &ccf, iLenf);
wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
- } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == -1) {
+ } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
CFX_WideString wsSearchCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
@@ -984,7 +984,7 @@
int32_t iCurChar = ccf;
GetLiteralText(pStr, &ccf, iLenf);
*wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
- } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == -1) {
+ } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
@@ -1031,7 +1031,7 @@
wsSubCategory = pLocale->GetNumPattern(eSubCategory);
*iDotIndex = wsSubCategory.Find('.');
- if (*iDotIndex > 0) {
+ if (*iDotIndex != 0 && *iDotIndex != FX_STRNPOS) {
*iDotIndex += wsPurgePattern->GetLength();
bFindDot = true;
*dwStyle |= FX_NUMSTYLE_DotVorv;
@@ -1570,7 +1570,7 @@
GetLiteralText(pStr, &ccf, iLenf);
wsTempPattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
} else if (!bBraceOpen && iFindCategory != 3 &&
- wsConstChars.Find(pStr[ccf]) == -1) {
+ wsConstChars.Find(pStr[ccf]) == FX_STRNPOS) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
@@ -1951,7 +1951,7 @@
const wchar_t* str = wsSrcNum.c_str();
int len = wsSrcNum.GetLength();
int dot_index = wsSrcNum.Find('.');
- if (dot_index == -1)
+ if (dot_index == FX_STRNPOS)
dot_index = len;
ccf = dot_index_f - 1;
@@ -2282,7 +2282,7 @@
CFX_DateTime dt;
int32_t iT = wsSrcDateTime.Find(L"T");
- if (iT < 0) {
+ if (iT == FX_STRNPOS) {
if (eCategory == FX_DATETIMETYPE_Date &&
FX_DateFromCanonical(wsSrcDateTime, &dt)) {
*wsOutput = FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, true,
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 6f86c7c..813a91d 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -1267,7 +1267,7 @@
int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1,
const CFX_WideString& Name2) {
- if (Name1.Find(Name2.c_str()) != -1)
+ if (Name1.Find(Name2.c_str()) != FX_STRNPOS)
return 1;
return 0;
}
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 8d1ec23..ff20188 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -279,7 +279,7 @@
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 77c4433..6e7a2ed 100644
--- a/xfa/fxfa/cxfa_pdffontmgr.cpp
+++ b/xfa/fxfa/cxfa_pdffontmgr.cpp
@@ -120,9 +120,9 @@
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 @@
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 @@
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 84064efb..9028642 100644
--- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp
@@ -374,7 +374,8 @@
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 49a1f58..ff9e981 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -225,10 +225,10 @@
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 16b999b..f43deaf 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -306,7 +306,7 @@
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 @@
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 4d6886d..55851bb 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -148,9 +148,10 @@
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 5b5c27f..aa0f74b 100644
--- a/xfa/fxfa/parser/cxfa_localevalue.cpp
+++ b/xfa/fxfa/parser/cxfa_localevalue.cpp
@@ -49,10 +49,10 @@
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 @@
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 @@
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 @@
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 261fee1..8497e60 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -4043,10 +4043,10 @@
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 @@
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 1b5cccf..39dc858 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -93,7 +93,7 @@
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 @@
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 5efc0ea..34e3aea 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -42,11 +42,10 @@
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 @@
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 @@
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 @@
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 @@
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;