summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-03-09 17:46:50 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-09 17:46:50 +0000
commit69da36c5f841e8c6e5ded6c704d9ef58c57d532a (patch)
tree42f50adb5d062f3971f8c6a4f899e737f5462c6c /core
parent3baef5c6daf58cec2df193714b5727802d0bd42e (diff)
downloadpdfium-69da36c5f841e8c6e5ded6c704d9ef58c57d532a.tar.xz
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 <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdftext/cpdf_linkextract.cpp4
-rw-r--r--core/fpdftext/cpdf_textpage.cpp2
-rw-r--r--core/fxcrt/bytestring.cpp4
-rw-r--r--core/fxcrt/css/cfx_cssselector.cpp4
-rw-r--r--core/fxcrt/css/cfx_csssyntaxparser.cpp2
-rw-r--r--core/fxcrt/fx_extension.cpp8
-rw-r--r--core/fxcrt/fx_extension.h18
-rw-r--r--core/fxcrt/fx_system.cpp16
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.cpp4
-rw-r--r--core/fxge/dib/fx_dib_main.cpp6
10 files changed, 34 insertions, 34 deletions
diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp
index c3cf4fc1ef..f8144a171b 100644
--- a/core/fpdftext/cpdf_linkextract.cpp
+++ b/core/fpdftext/cpdf_linkextract.cpp
@@ -246,7 +246,7 @@ bool CPDF_LinkExtract::CheckMailLink(WideString* str) {
size_t pPos = aPos.value(); // Used to track the position of '@' or '.'.
for (size_t i = aPos.value(); i > 0; i--) {
wchar_t ch = (*str)[i - 1];
- if (ch == L'_' || ch == L'-' || FXSYS_iswalnum(ch))
+ if (ch == L'_' || ch == L'-' || FXSYS_iswASCIIalnum(ch))
continue;
if (ch != L'.' || i == pPos || i == 1) {
@@ -282,7 +282,7 @@ bool CPDF_LinkExtract::CheckMailLink(WideString* str) {
pPos = 0; // Used to track the position of '.'.
for (size_t i = aPos.value() + 1; i < nLen; i++) {
wchar_t wch = (*str)[i];
- if (wch == L'-' || FXSYS_iswalnum(wch))
+ if (wch == L'-' || FXSYS_iswASCIIalnum(wch))
continue;
if (wch != L'.' || i == pPos + 1) {
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index e712549ceb..5019eabaf5 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -1210,7 +1210,7 @@ bool CPDF_TextPage::IsHyphen(wchar_t curChar) const {
if ((iter + 1) != curText.rend()) {
iter++;
- if (FXSYS_iswalpha(*iter) && FXSYS_iswalnum(curChar))
+ if (FXSYS_iswASCIIalpha(*iter) && FXSYS_iswASCIIalnum(curChar))
return true;
}
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> CFX_CSSSelector::FromString(
std::unique_ptr<CFX_CSSSelector> 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_CSSSelector>(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<wchar_t>(FXSYS_tolower(*s1++));
- wch2 = static_cast<wchar_t>(FXSYS_tolower(*s2++));
+ wch1 = static_cast<wchar_t>(FXSYS_toASCIIlower(*s1++));
+ wch2 = static_cast<wchar_t>(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);
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index d8b751d9b2..7413a69884 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -97,7 +97,7 @@ uint32_t FPF_GetHashCode_StringA(const char* pStr, int32_t iLength) {
const char* pStrEnd = pStr + iLength;
uint32_t uHashCode = 0;
while (pStr < pStrEnd)
- uHashCode = 31 * uHashCode + FXSYS_tolower(*pStr++);
+ uHashCode = 31 * uHashCode + FXSYS_toASCIIlower(*pStr++);
return uHashCode;
}
@@ -167,7 +167,7 @@ uint32_t FPF_SKIANormalizeFontName(const ByteStringView& bsfamily) {
char ch = pBuffer[i];
if (ch == ' ' || ch == '-' || ch == ',')
continue;
- dwHash = 31 * dwHash + FXSYS_tolower(ch);
+ dwHash = 31 * dwHash + FXSYS_toASCIIlower(ch);
}
return dwHash;
}
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 68e06a6c5d..f0767f3fc7 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -97,7 +97,7 @@ FX_ARGB StringToFXARGB(const WideStringView& wsValue) {
int cc = 0;
const wchar_t* str = wsValue.unterminated_c_str();
int len = wsValue.GetLength();
- while (FXSYS_iswspace(str[cc]) && cc < len)
+ while (FXSYS_iswASCIIspace(str[cc]) && cc < len)
cc++;
if (cc >= len)
@@ -112,7 +112,7 @@ FX_ARGB StringToFXARGB(const WideStringView& wsValue) {
}
if (cc < len && str[cc] == ',') {
cc++;
- while (FXSYS_iswspace(str[cc]) && cc < len)
+ while (FXSYS_iswASCIIspace(str[cc]) && cc < len)
cc++;
while (cc < len) {
@@ -124,7 +124,7 @@ FX_ARGB StringToFXARGB(const WideStringView& wsValue) {
}
if (cc < len && str[cc] == ',') {
cc++;
- while (FXSYS_iswspace(str[cc]) && cc < len)
+ while (FXSYS_iswASCIIspace(str[cc]) && cc < len)
cc++;
while (cc < len) {