summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp9
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp4
-rw-r--r--core/fpdfdoc/cpdf_action.cpp3
-rw-r--r--core/fpdftext/cpdf_linkextract.cpp20
-rw-r--r--core/fpdftext/cpdf_textpagefind.cpp2
-rw-r--r--core/fxcrt/cfx_bytestring.cpp16
-rw-r--r--core/fxcrt/cfx_bytestring_unittest.cpp14
-rw-r--r--core/fxcrt/cfx_string_c_template.h2
-rw-r--r--core/fxcrt/cfx_widestring.cpp18
-rw-r--r--core/fxcrt/cfx_widestring_unittest.cpp14
-rw-r--r--core/fxcrt/fx_basic_util.cpp2
-rw-r--r--core/fxcrt/fx_system.h4
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.cpp4
-rw-r--r--core/fxcrt/xml/cxml_parser.cpp2
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.cpp4
-rw-r--r--core/fxge/apple/fx_mac_imp.cpp4
-rw-r--r--core/fxge/cfx_folderfontinfo.cpp8
-rw-r--r--core/fxge/cfx_font.cpp2
-rw-r--r--core/fxge/cfx_fontmapper.cpp6
-rw-r--r--core/fxge/cfx_renderdevice.cpp2
-rw-r--r--core/fxge/fx_ge_linux.cpp15
-rw-r--r--core/fxge/win32/fx_win32_device.cpp33
23 files changed, 102 insertions, 88 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index 62b10c9149..e9676b1115 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -186,8 +186,10 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessStandardText) {
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 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessText) {
}
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 288f9d57a8..692de0f5eb 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -316,7 +316,7 @@ void CPDF_StreamContentParser::AddNameParam(const CFX_ByteStringC& bsName) {
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 0cd4ca9225..7025b3e7d8 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -89,7 +89,7 @@ int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteString& key) {
}
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_ByteStringC& bstr) {
}
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 2357580548..dae7a7180e 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -96,7 +96,8 @@ CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
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 e0bd4ae49f..d795e71639 100644
--- a/core/fpdftext/cpdf_linkextract.cpp
+++ b/core/fpdftext/cpdf_linkextract.cpp
@@ -22,7 +22,7 @@ namespace {
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 @@ bool CPDF_LinkExtract::CheckWebLink(CFX_WideString* strBeCheck,
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 @@ bool CPDF_LinkExtract::CheckWebLink(CFX_WideString* strBeCheck,
// 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::CheckWebLink(CFX_WideString* strBeCheck,
}
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 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString* str) {
// 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 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString* str) {
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 fe610abcd4..adef9f6c0c 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -164,7 +164,7 @@ bool CPDF_TextPageFind::FindNext() {
}
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 e7e55de8e3..6e01933682 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -562,41 +562,41 @@ CFX_ByteString CFX_ByteString::Left(FX_STRSIZE nCount) const {
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 bcf6f7495e..d7f265e32a 100644
--- a/core/fxcrt/cfx_bytestring_unittest.cpp
+++ b/core/fxcrt/cfx_bytestring_unittest.cpp
@@ -826,22 +826,22 @@ TEST(fxcrt, ByteStringCGetID) {
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 77f34f638e..b87b65991e 100644
--- a/core/fxcrt/cfx_string_c_template.h
+++ b/core/fxcrt/cfx_string_c_template.h
@@ -127,7 +127,7 @@ class CFX_StringCTemplate {
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 d7c1ef23ea..8937783863 100644
--- a/core/fxcrt/cfx_widestring.cpp
+++ b/core/fxcrt/cfx_widestring.cpp
@@ -78,7 +78,7 @@ FX_STRSIZE GuessSizeForVSWPrintf(const wchar_t* pFormat, va_list argList) {
++pStr;
}
if (nWidth < 0 || nWidth > 128 * 1024)
- return -1;
+ return FX_STRNPOS;
int nPrecision = 0;
if (*pStr == '.') {
pStr++;
@@ -92,7 +92,7 @@ FX_STRSIZE GuessSizeForVSWPrintf(const wchar_t* pFormat, va_list argList) {
}
}
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 @@ void CFX_WideString::FormatV(const wchar_t* pFormat, va_list argList) {
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 @@ CFX_WideString CFX_WideString::Left(FX_STRSIZE nCount) const {
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 1d6d110497..a53e9a35e2 100644
--- a/core/fxcrt/cfx_widestring_unittest.cpp
+++ b/core/fxcrt/cfx_widestring_unittest.cpp
@@ -853,22 +853,22 @@ TEST(fxcrt, WideStringCOperatorNE) {
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 aef623ce92..7730866c73 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 5e8aa6c0e6..e9288641b8 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -127,6 +127,10 @@ void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap);
#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 8c2442e765..75bf9ee593 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -43,14 +43,14 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLElement::Clone() {
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 5ac1f82206..35eca527e6 100644
--- a/core/fxcrt/xml/cxml_parser.cpp
+++ b/core/fxcrt/xml/cxml_parser.cpp
@@ -83,7 +83,7 @@ void FX_XML_SplitQualifiedName(const CFX_ByteStringC& bsFullName,
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 23fcd5bbec..3cee6decac 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -194,13 +194,13 @@ bool FPF_SkiaIsCJK(uint8_t uCharset) {
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 78fe16459c..54aac7bfa6 100644
--- a/core/fxge/apple/fx_mac_imp.cpp
+++ b/core/fxge/apple/fx_mac_imp.cpp
@@ -52,7 +52,7 @@ const char JAPAN_GOTHIC[] = "Hiragino Kaku Gothic Pro W6";
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 @@ void* CFX_MacFontInfo::MapFont(int weight,
// 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 12e7dd25fc..f16722c4d6 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -251,11 +251,11 @@ void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path,
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 @@ void* CFX_FolderFontInfo::FindFont(int weight,
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 a8e271dd9a..1fd08f2676 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -447,7 +447,7 @@ bool CFX_Font::IsItalic() const {
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 4c0073ab73..b8ffe047a3 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -172,7 +172,7 @@ const struct CODEPAGE_MAP {
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 @@ CFX_ByteString TT_NormalizeName(const char* family) {
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 279e720d1e..310a16512c 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -337,7 +337,7 @@ bool ShouldDrawDeviceText(const CFX_Font* pFont, uint32_t text_flags) {
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 d9fac3f54c..0552f1c58c 100644
--- a/core/fxge/fx_ge_linux.cpp
+++ b/core/fxge/fx_ge_linux.cpp
@@ -45,17 +45,18 @@ size_t GetJapanesePreference(const char* facearr,
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 4427755cf5..b707a76c08 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -503,7 +503,7 @@ void* CFX_Win32FallbackFontInfo::MapFont(int weight,
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 @@ void CFX_Win32FontInfo::GetGBPreference(CFX_ByteString& face,
}
}
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 @@ void CFX_Win32FontInfo::GetGBPreference(CFX_ByteString& face,
}
}
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::GetGBPreference(CFX_ByteString& face,
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 @@ void CFX_Win32FontInfo::GetJapanesePreference(CFX_ByteString& face,
}
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 @@ void* CFX_Win32FontInfo::MapFont(int weight,
face = "Gulim";
break;
case FX_CHARSET_ChineseTraditional:
- if (face.Find("MSung") >= 0) {
+ if (face.Find("MSung") != FX_STRNPOS) {
face = "MingLiU";
} else {
face = "PMingLiU";