summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdftext/cpdf_textpage.cpp6
-rw-r--r--core/fxcrt/cfx_bytestring.cpp11
-rw-r--r--core/fxcrt/cfx_bytestring_unittest.cpp13
-rw-r--r--core/fxcrt/cfx_decimal.cpp4
-rw-r--r--core/fxcrt/fx_basic_gcc.cpp37
-rw-r--r--core/fxcrt/fx_extension.h2
6 files changed, 40 insertions, 33 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index a1f056cc37..c64b8e17ae 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -1226,12 +1226,8 @@ bool CPDF_TextPage::IsHyphen(wchar_t curChar) {
if (0x2D == wcTmp || 0xAD == wcTmp) {
if (--nIndex > 0) {
wchar_t preChar = strCurText.GetAt((nIndex));
- if (((preChar >= L'A' && preChar <= L'Z') ||
- (preChar >= L'a' && preChar <= L'z')) &&
- ((curChar >= L'A' && curChar <= L'Z') ||
- (curChar >= L'a' && curChar <= L'z'))) {
+ if (FXSYS_iswalpha(preChar) && FXSYS_iswalpha(curChar))
return true;
- }
}
const PAGECHAR_INFO* preInfo;
if (!m_TempCharList.empty())
diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp
index ab35e5d0c5..5c534507c6 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -13,6 +13,7 @@
#include "core/fxcrt/cfx_string_pool_template.h"
#include "core/fxcrt/fx_basic.h"
+#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/numerics/safe_math.h"
#include "third_party/base/stl_util.h"
@@ -266,14 +267,8 @@ bool CFX_ByteString::EqualNoCase(const CFX_ByteStringC& str) const {
const uint8_t* pThat = str.raw_str();
for (FX_STRSIZE i = 0; i < len; i++) {
if ((*pThis) != (*pThat)) {
- uint8_t bThis = *pThis;
- if (bThis >= 'A' && bThis <= 'Z')
- bThis += 'a' - 'A';
-
- uint8_t bThat = *pThat;
- if (bThat >= 'A' && bThat <= 'Z')
- bThat += 'a' - 'A';
-
+ uint8_t bThis = FXSYS_tolower(*pThis);
+ uint8_t bThat = FXSYS_tolower(*pThat);
if (bThis != bThat)
return false;
}
diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp
index 42627c2299..14d9393371 100644
--- a/core/fxcrt/cfx_bytestring_unittest.cpp
+++ b/core/fxcrt/cfx_bytestring_unittest.cpp
@@ -1239,3 +1239,16 @@ TEST(fxcrt, ByteStringAnyAllNoneOf) {
EXPECT_TRUE(pdfium::ContainsValue(str, 'b'));
EXPECT_FALSE(pdfium::ContainsValue(str, 'z'));
}
+
+TEST(fxcrt, EqualNoCase) {
+ CFX_ByteString str("aaa");
+ EXPECT_TRUE(str.EqualNoCase("aaa"));
+ EXPECT_TRUE(str.EqualNoCase("AAA"));
+ EXPECT_TRUE(str.EqualNoCase("aaA"));
+ EXPECT_TRUE(str.EqualNoCase("Aaa"));
+ EXPECT_FALSE(str.EqualNoCase("aab"));
+ EXPECT_FALSE(str.EqualNoCase("aaaa"));
+ EXPECT_FALSE(str.EqualNoCase("BBBB"));
+ EXPECT_FALSE(str.EqualNoCase("a"));
+ EXPECT_FALSE(str.EqualNoCase(""));
+}
diff --git a/core/fxcrt/cfx_decimal.cpp b/core/fxcrt/cfx_decimal.cpp
index 095978cd43..a463305f6a 100644
--- a/core/fxcrt/cfx_decimal.cpp
+++ b/core/fxcrt/cfx_decimal.cpp
@@ -9,6 +9,8 @@
#include <algorithm>
#include <utility>
+#include "core/fxcrt/fx_extension.h"
+
#define FXMATH_DECIMAL_SCALELIMIT 0x1c
#define FXMATH_DECIMAL_NEGMASK (0x80000000L)
#define FXMATH_DECIMAL_FORCEBOOL(x) (!!(x))
@@ -310,7 +312,7 @@ CFX_Decimal::CFX_Decimal(const CFX_WideStringC& strObj) {
str++;
}
- while (str != strBound && ((*str >= '0' && *str <= '9') || *str == '.') &&
+ while (str != strBound && (std::iswdigit(*str) || *str == '.') &&
scale < FXMATH_DECIMAL_SCALELIMIT) {
if (*str == '.') {
if (!pointmet)
diff --git a/core/fxcrt/fx_basic_gcc.cpp b/core/fxcrt/fx_basic_gcc.cpp
index c42b762daf..ce1f813b5a 100644
--- a/core/fxcrt/fx_basic_gcc.cpp
+++ b/core/fxcrt/fx_basic_gcc.cpp
@@ -183,30 +183,31 @@ wchar_t* FXSYS_wcsupr(wchar_t* str) {
}
return s;
}
+
int FXSYS_stricmp(const char* dst, const char* src) {
- int f, l;
+ int f;
+ int l;
do {
- if (((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z')) {
- f -= ('A' - 'a');
- }
- if (((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z')) {
- l -= ('A' - 'a');
- }
- } while (f && (f == l));
- return (f - l);
+ f = FXSYS_toupper(*dst);
+ l = FXSYS_toupper(*src);
+ ++dst;
+ ++src;
+ } while (f && f == l);
+ return f - l;
}
+
int FXSYS_wcsicmp(const wchar_t* dst, const wchar_t* src) {
- wchar_t f, l;
+ wchar_t f;
+ wchar_t l;
do {
- if (((f = (wchar_t)(*(dst++))) >= 'A') && (f <= 'Z')) {
- f -= ('A' - 'a');
- }
- if (((l = (wchar_t)(*(src++))) >= 'A') && (l <= 'Z')) {
- l -= ('A' - 'a');
- }
- } while (f && (f == l));
- return (f - l);
+ f = FXSYS_toupper(*dst);
+ l = FXSYS_toupper(*src);
+ ++dst;
+ ++src;
+ } while (f && f == l);
+ return f - l;
}
+
char* FXSYS_itoa(int value, char* str, int radix) {
return FXSYS_IntToStr<int32_t, uint32_t, char*>(value, str, radix);
}
diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h
index 00604fb22c..beda105909 100644
--- a/core/fxcrt/fx_extension.h
+++ b/core/fxcrt/fx_extension.h
@@ -38,7 +38,7 @@ inline int32_t FXSYS_toupper(int32_t ch) {
}
inline bool FXSYS_iswalpha(wchar_t wch) {
- return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z');
+ return FXSYS_isupper(wch) || FXSYS_islower(wch);
}
inline bool FXSYS_iswalnum(wchar_t wch) {