diff options
author | Lei Zhang <thestig@chromium.org> | 2017-04-24 16:28:07 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-25 00:07:29 +0000 |
commit | ef002c85521278e3082517297cf60372d7751cb1 (patch) | |
tree | be0148d89603262c1bf11f16621a1c43509759db /core/fxcrt | |
parent | 3684a151e76991bc67dd397cba66b0620cc38bae (diff) | |
download | pdfium-ef002c85521278e3082517297cf60372d7751cb1.tar.xz |
Use fx_extension.h utilities in more places.
Change-Id: Iba1aa793567e69acc3cc1acbd5b9a9f531c80b7a
Reviewed-on: https://pdfium-review.googlesource.com/4453
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/cfx_bytestring.cpp | 11 | ||||
-rw-r--r-- | core/fxcrt/cfx_bytestring_unittest.cpp | 13 | ||||
-rw-r--r-- | core/fxcrt/cfx_decimal.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_gcc.cpp | 37 | ||||
-rw-r--r-- | core/fxcrt/fx_extension.h | 2 |
5 files changed, 39 insertions, 28 deletions
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) { |