diff options
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/cfx_bytestring.cpp | 16 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring_unittest.cpp | 14 | ||||
-rw-r--r-- | core/fxcrt/cfx_string_c_template.h | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring.cpp | 18 | ||||
-rw-r--r-- | core/fxcrt/cfx_widestring_unittest.cpp | 14 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_util.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_system.h | 4 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmlelement.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/xml/cxml_parser.cpp | 2 |
9 files changed, 40 insertions, 36 deletions
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); |