summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--fpdfsdk/fxedit/fxet_list.cpp9
-rw-r--r--fpdfsdk/fxedit/fxet_list.h1
-rw-r--r--fpdfsdk/javascript/util.cpp13
9 files changed, 47 insertions, 49 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) {
diff --git a/fpdfsdk/fxedit/fxet_list.cpp b/fpdfsdk/fxedit/fxet_list.cpp
index c10b6a205e..c8fef948af 100644
--- a/fpdfsdk/fxedit/fxet_list.cpp
+++ b/fpdfsdk/fxedit/fxet_list.cpp
@@ -10,6 +10,7 @@
#include <utility>
#include "core/fpdfdoc/cpvt_word.h"
+#include "core/fxcrt/fx_extension.h"
#include "fpdfsdk/fxedit/fxet_edit.h"
#include "fpdfsdk/pdfwindow/PWL_ListBox.h"
#include "third_party/base/stl_util.h"
@@ -638,12 +639,6 @@ int32_t CFX_ListCtrl::GetLastSelected() const {
return -1;
}
-wchar_t CFX_ListCtrl::Toupper(wchar_t c) const {
- if ((c >= 'a') && (c <= 'z'))
- c = c - ('a' - 'A');
- return c;
-}
-
int32_t CFX_ListCtrl::FindNext(int32_t nIndex, wchar_t nChar) const {
int32_t nCircleIndex = nIndex;
int32_t sz = pdfium::CollectionSize<int32_t>(m_ListItems);
@@ -653,7 +648,7 @@ int32_t CFX_ListCtrl::FindNext(int32_t nIndex, wchar_t nChar) const {
nCircleIndex = 0;
if (CFX_ListItem* pListItem = m_ListItems[nCircleIndex].get()) {
- if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar))
+ if (FXSYS_toupper(pListItem->GetFirstChar()) == FXSYS_toupper(nChar))
return nCircleIndex;
}
}
diff --git a/fpdfsdk/fxedit/fxet_list.h b/fpdfsdk/fxedit/fxet_list.h
index 50e43c9d2f..cd6e2ddeff 100644
--- a/fpdfsdk/fxedit/fxet_list.h
+++ b/fpdfsdk/fxedit/fxet_list.h
@@ -262,7 +262,6 @@ class CFX_ListCtrl : protected CFX_ListContainer {
CFX_WideString GetItemText(int32_t nIndex) const;
void SetItemSelect(int32_t nItemIndex, bool bSelected);
int32_t GetLastSelected() const;
- wchar_t Toupper(wchar_t c) const;
CPWL_List_Notify* m_pNotify;
bool m_bNotifyFlag;
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index dc34119c38..bc968a59d9 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -321,9 +321,9 @@ bool util::printx(CJS_Runtime* pRuntime,
enum CaseMode { kPreserveCase, kUpperCase, kLowerCase };
static wchar_t TranslateCase(wchar_t input, CaseMode eMode) {
- if (eMode == kLowerCase && input >= 'A' && input <= 'Z')
+ if (eMode == kLowerCase && FXSYS_isupper(input))
return input | 0x20;
- if (eMode == kUpperCase && input >= 'a' && input <= 'z')
+ if (eMode == kUpperCase && FXSYS_islower(input))
return input & ~0x20;
return input;
}
@@ -368,9 +368,7 @@ CFX_WideString util::printx(const CFX_WideString& wsFormat,
} break;
case 'X': {
if (iSourceIdx < wsSource.GetLength()) {
- if ((wsSource[iSourceIdx] >= '0' && wsSource[iSourceIdx] <= '9') ||
- (wsSource[iSourceIdx] >= 'a' && wsSource[iSourceIdx] <= 'z') ||
- (wsSource[iSourceIdx] >= 'A' && wsSource[iSourceIdx] <= 'Z')) {
+ if (FXSYS_iswalnum(wsSource[iSourceIdx])) {
wsResult += TranslateCase(wsSource[iSourceIdx], eCaseMode);
++iFormatIdx;
}
@@ -381,8 +379,7 @@ CFX_WideString util::printx(const CFX_WideString& wsFormat,
} break;
case 'A': {
if (iSourceIdx < wsSource.GetLength()) {
- if ((wsSource[iSourceIdx] >= 'a' && wsSource[iSourceIdx] <= 'z') ||
- (wsSource[iSourceIdx] >= 'A' && wsSource[iSourceIdx] <= 'Z')) {
+ if (FXSYS_iswalpha(wsSource[iSourceIdx])) {
wsResult += TranslateCase(wsSource[iSourceIdx], eCaseMode);
++iFormatIdx;
}
@@ -393,7 +390,7 @@ CFX_WideString util::printx(const CFX_WideString& wsFormat,
} break;
case '9': {
if (iSourceIdx < wsSource.GetLength()) {
- if (wsSource[iSourceIdx] >= '0' && wsSource[iSourceIdx] <= '9') {
+ if (std::iswdigit(wsSource[iSourceIdx])) {
wsResult += wsSource[iSourceIdx];
++iFormatIdx;
}