From 69da36c5f841e8c6e5ded6c704d9ef58c57d532a Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 9 Mar 2018 17:46:50 +0000 Subject: Explicitly mark helper methods that only operate on ASCII ranges A number of our character helper methods take in wide character types, but only do tests/operations on the ASCII range of characters. As a very quick first pass I am renaming all of the foot-gun methods to explictly call out this behaviour, while I do a bigger cleanup/refactor. BUG=pdfium:1035 Change-Id: Ia035dfa1cb6812fa6d45155c4565475032c4c165 Reviewed-on: https://pdfium-review.googlesource.com/28330 Commit-Queue: Ryan Harrison Commit-Queue: dsinclair Reviewed-by: Henrique Nakashima Reviewed-by: dsinclair --- core/fxcrt/bytestring.cpp | 4 ++-- core/fxcrt/css/cfx_cssselector.cpp | 4 ++-- core/fxcrt/css/cfx_csssyntaxparser.cpp | 2 +- core/fxcrt/fx_extension.cpp | 8 ++++---- core/fxcrt/fx_extension.h | 18 +++++++++--------- core/fxcrt/fx_system.cpp | 16 ++++++++-------- 6 files changed, 26 insertions(+), 26 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp index 2ab1379974..2a57602692 100644 --- a/core/fxcrt/bytestring.cpp +++ b/core/fxcrt/bytestring.cpp @@ -344,8 +344,8 @@ bool ByteString::EqualNoCase(const ByteStringView& str) const { const uint8_t* pThat = str.raw_str(); for (size_t i = 0; i < len; i++) { if ((*pThis) != (*pThat)) { - uint8_t bThis = FXSYS_tolower(*pThis); - uint8_t bThat = FXSYS_tolower(*pThat); + uint8_t bThis = FXSYS_toASCIIlower(*pThis); + uint8_t bThat = FXSYS_toASCIIlower(*pThat); if (bThis != bThat) return false; } diff --git a/core/fxcrt/css/cfx_cssselector.cpp b/core/fxcrt/css/cfx_cssselector.cpp index 3993dcae5c..76cb846890 100644 --- a/core/fxcrt/css/cfx_cssselector.cpp +++ b/core/fxcrt/css/cfx_cssselector.cpp @@ -17,7 +17,7 @@ int32_t GetCSSNameLen(const wchar_t* psz, const wchar_t* pEnd) { const wchar_t* pStart = psz; while (psz < pEnd) { wchar_t wch = *psz; - if (!FXSYS_iswalnum(wch) && wch != '_' && wch != '-') + if (!FXSYS_iswASCIIalnum(wch) && wch != '_' && wch != '-') break; ++psz; } @@ -67,7 +67,7 @@ std::unique_ptr CFX_CSSSelector::FromString( std::unique_ptr pFirst = nullptr; for (psz = pStart; psz < pEnd;) { wchar_t wch = *psz; - if (FXSYS_iswalpha(wch) || wch == '*') { + if (FXSYS_iswASCIIalpha(wch) || wch == '*') { int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd); auto p = pdfium::MakeUnique(CFX_CSSSelectorType::Element, psz, iNameLen, true); diff --git a/core/fxcrt/css/cfx_csssyntaxparser.cpp b/core/fxcrt/css/cfx_csssyntaxparser.cpp index 30352a5a20..fea951f1ec 100644 --- a/core/fxcrt/css/cfx_csssyntaxparser.cpp +++ b/core/fxcrt/css/cfx_csssyntaxparser.cpp @@ -18,7 +18,7 @@ namespace { bool IsSelectorStart(wchar_t wch) { - return wch == '.' || wch == '#' || wch == '*' || FXSYS_iswalpha(wch); + return wch == '.' || wch == '#' || wch == '*' || FXSYS_iswASCIIalpha(wch); } } // namespace diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 371f1b5211..7bfcec6d42 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -68,8 +68,8 @@ int32_t FXSYS_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t count) { ASSERT(s1 && s2 && count > 0); wchar_t wch1 = 0, wch2 = 0; while (count-- > 0) { - wch1 = static_cast(FXSYS_tolower(*s1++)); - wch2 = static_cast(FXSYS_tolower(*s2++)); + wch1 = static_cast(FXSYS_toASCIIlower(*s1++)); + wch2 = static_cast(FXSYS_toASCIIlower(*s2++)); if (wch1 != wch2) break; } @@ -80,7 +80,7 @@ uint32_t FX_HashCode_GetA(const ByteStringView& str, bool bIgnoreCase) { uint32_t dwHashCode = 0; if (bIgnoreCase) { for (const auto& c : str) - dwHashCode = 31 * dwHashCode + FXSYS_tolower(c); + dwHashCode = 31 * dwHashCode + FXSYS_toASCIIlower(c); } else { for (const auto& c : str) dwHashCode = 31 * dwHashCode + c; @@ -92,7 +92,7 @@ uint32_t FX_HashCode_GetW(const WideStringView& str, bool bIgnoreCase) { uint32_t dwHashCode = 0; if (bIgnoreCase) { for (const auto& c : str) - dwHashCode = 1313 * dwHashCode + FXSYS_tolower(c); + dwHashCode = 1313 * dwHashCode + FXSYS_toASCIIlower(c); } else { for (const auto& c : str) dwHashCode = 1313 * dwHashCode + c; diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h index e02d58d0df..491d4b29b7 100644 --- a/core/fxcrt/fx_extension.h +++ b/core/fxcrt/fx_extension.h @@ -25,31 +25,31 @@ float FXSYS_wcstof(const wchar_t* pwsStr, wchar_t* FXSYS_wcsncpy(wchar_t* dstStr, const wchar_t* srcStr, size_t count); int32_t FXSYS_wcsnicmp(const wchar_t* s1, const wchar_t* s2, size_t count); -inline bool FXSYS_islower(int32_t ch) { +inline bool FXSYS_isASCIIlower(int32_t ch) { return ch >= 'a' && ch <= 'z'; } -inline bool FXSYS_isupper(int32_t ch) { +inline bool FXSYS_isASCIIupper(int32_t ch) { return ch >= 'A' && ch <= 'Z'; } -inline int32_t FXSYS_tolower(int32_t ch) { +inline int32_t FXSYS_toASCIIlower(int32_t ch) { return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); } -inline int32_t FXSYS_toupper(int32_t ch) { +inline int32_t FXSYS_toASCIIupper(int32_t ch) { return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); } -inline bool FXSYS_iswalpha(wchar_t wch) { - return FXSYS_isupper(wch) || FXSYS_islower(wch); +inline bool FXSYS_iswASCIIalpha(wchar_t wch) { + return FXSYS_isASCIIupper(wch) || FXSYS_isASCIIlower(wch); } -inline bool FXSYS_iswalnum(wchar_t wch) { - return FXSYS_iswalpha(wch) || std::iswdigit(wch); +inline bool FXSYS_iswASCIIalnum(wchar_t wch) { + return FXSYS_iswASCIIalpha(wch) || std::iswdigit(wch); } -inline bool FXSYS_iswspace(wchar_t c) { +inline bool FXSYS_iswASCIIspace(wchar_t c) { return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); } diff --git a/core/fxcrt/fx_system.cpp b/core/fxcrt/fx_system.cpp index a5ceec5be1..532e83b949 100644 --- a/core/fxcrt/fx_system.cpp +++ b/core/fxcrt/fx_system.cpp @@ -118,7 +118,7 @@ char* FXSYS_strlwr(char* str) { } char* s = str; while (*str) { - *str = FXSYS_tolower(*str); + *str = FXSYS_toASCIIlower(*str); str++; } return s; @@ -129,7 +129,7 @@ char* FXSYS_strupr(char* str) { } char* s = str; while (*str) { - *str = FXSYS_toupper(*str); + *str = FXSYS_toASCIIupper(*str); str++; } return s; @@ -140,7 +140,7 @@ wchar_t* FXSYS_wcslwr(wchar_t* str) { } wchar_t* s = str; while (*str) { - *str = FXSYS_tolower(*str); + *str = FXSYS_toASCIIlower(*str); str++; } return s; @@ -151,7 +151,7 @@ wchar_t* FXSYS_wcsupr(wchar_t* str) { } wchar_t* s = str; while (*str) { - *str = FXSYS_toupper(*str); + *str = FXSYS_toASCIIupper(*str); str++; } return s; @@ -161,8 +161,8 @@ int FXSYS_stricmp(const char* dst, const char* src) { int f; int l; do { - f = FXSYS_toupper(*dst); - l = FXSYS_toupper(*src); + f = FXSYS_toASCIIupper(*dst); + l = FXSYS_toASCIIupper(*src); ++dst; ++src; } while (f && f == l); @@ -173,8 +173,8 @@ int FXSYS_wcsicmp(const wchar_t* dst, const wchar_t* src) { wchar_t f; wchar_t l; do { - f = FXSYS_toupper(*dst); - l = FXSYS_toupper(*src); + f = FXSYS_toASCIIupper(*dst); + l = FXSYS_toASCIIupper(*src); ++dst; ++src; } while (f && f == l); -- cgit v1.2.3