summaryrefslogtreecommitdiff
path: root/core/src/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fxcrt')
-rw-r--r--core/src/fxcrt/fx_basic_bstring.cpp9
-rw-r--r--core/src/fxcrt/fx_basic_gcc.cpp48
-rw-r--r--core/src/fxcrt/fx_basic_util.cpp18
-rw-r--r--core/src/fxcrt/fx_basic_wstring.cpp14
-rw-r--r--core/src/fxcrt/fx_extension.cpp14
-rw-r--r--core/src/fxcrt/fx_extension_unittest.cpp24
-rw-r--r--core/src/fxcrt/fx_xml_parser.cpp8
7 files changed, 49 insertions, 86 deletions
diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp
index 574e57a9a6..9d64fbe139 100644
--- a/core/src/fxcrt/fx_basic_bstring.cpp
+++ b/core/src/fxcrt/fx_basic_bstring.cpp
@@ -5,7 +5,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <stddef.h> // For offsetof().
-#include <cctype>
#include "core/include/fxcrt/fx_basic.h"
#include "third_party/base/numerics/safe_math.h"
@@ -494,8 +493,8 @@ void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) {
}
if (nWidth == 0) {
nWidth = FXSYS_atoi(lpsz);
- while (std::isdigit(*lpsz))
- lpsz++;
+ for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++)
+ ;
}
if (nWidth < 0 || nWidth > 128 * 1024) {
lpszFormat = "Bad width";
@@ -510,8 +509,8 @@ void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) {
lpsz++;
} else {
nPrecision = FXSYS_atoi(lpsz);
- while (std::isdigit(*lpsz))
- lpsz++;
+ for (; (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++)
+ ;
}
}
if (nPrecision < 0 || nPrecision > 128 * 1024) {
diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp
index c352ee3f81..f8b0c7ac78 100644
--- a/core/src/fxcrt/fx_basic_gcc.cpp
+++ b/core/src/fxcrt/fx_basic_gcc.cpp
@@ -5,49 +5,29 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <limits>
-#include <cctype>
-#include <cwctype>
#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_string.h"
-template <class T>
-T FXSYS_StrToInt(const FX_CHAR* str) {
+template <class T, class STR_T>
+T FXSYS_StrToInt(STR_T str) {
FX_BOOL neg = FALSE;
- if (!str)
+ if (str == NULL) {
return 0;
-
- if (*str == '-') {
- neg = TRUE;
- str++;
}
- T num = 0;
- while (*str && std::isdigit(*str)) {
- if (num > (std::numeric_limits<T>::max() - 9) / 10)
- break;
-
- num = num * 10 + FXSYS_toDecimalDigit(*str);
- str++;
- }
- return neg ? -num : num;
-}
-
-template <class T>
-T FXSYS_StrToInt(const FX_WCHAR* str) {
- FX_BOOL neg = FALSE;
- if (!str)
- return 0;
-
if (*str == '-') {
neg = TRUE;
str++;
}
T num = 0;
- while (*str && std::iswdigit(*str)) {
- if (num > (std::numeric_limits<T>::max() - 9) / 10)
+ while (*str) {
+ if ((*str) < '0' || (*str) > '9') {
break;
-
- num = num * 10 + FXSYS_toDecimalDigitWide(*str);
+ }
+ if (num > (std::numeric_limits<T>::max() - 9) / 10) {
+ break;
+ }
+ num = num * 10 + (*str) - '0';
str++;
}
return neg ? -num : num;
@@ -91,16 +71,16 @@ STR_T FXSYS_IntToStr(T value, STR_T string, int radix) {
extern "C" {
#endif
int32_t FXSYS_atoi(const FX_CHAR* str) {
- return FXSYS_StrToInt<int32_t>(str);
+ return FXSYS_StrToInt<int32_t, const FX_CHAR*>(str);
}
int32_t FXSYS_wtoi(const FX_WCHAR* str) {
- return FXSYS_StrToInt<int32_t>(str);
+ return FXSYS_StrToInt<int32_t, const FX_WCHAR*>(str);
}
int64_t FXSYS_atoi64(const FX_CHAR* str) {
- return FXSYS_StrToInt<int64_t>(str);
+ return FXSYS_StrToInt<int64_t, const FX_CHAR*>(str);
}
int64_t FXSYS_wtoi64(const FX_WCHAR* str) {
- return FXSYS_StrToInt<int64_t>(str);
+ return FXSYS_StrToInt<int64_t, const FX_WCHAR*>(str);
}
const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix) {
return FXSYS_IntToStr<int64_t, uint64_t, FX_CHAR*>(value, str, radix);
diff --git a/core/src/fxcrt/fx_basic_util.cpp b/core/src/fxcrt/fx_basic_util.cpp
index b4c7064da2..3e9d6169cd 100644
--- a/core/src/fxcrt/fx_basic_util.cpp
+++ b/core/src/fxcrt/fx_basic_util.cpp
@@ -5,9 +5,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "core/include/fxcrt/fx_basic.h"
-#include "core/include/fxcrt/fx_ext.h"
-
-#include <cctype>
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
#include <sys/types.h>
@@ -105,11 +102,14 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
bNegative = TRUE;
cc++;
}
- while (cc < len && std::isdigit(str[cc])) {
- // TODO(dsinclair): This is not the right way to handle overflow.
- integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]);
- if (integer < 0)
+ while (cc < len) {
+ if (str[cc] < '0' || str[cc] > '9') {
break;
+ }
+ integer = integer * 10 + str[cc] - '0';
+ if (integer < 0) {
+ break;
+ }
cc++;
}
if (bNegative) {
@@ -146,7 +146,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (str[cc] == '.') {
break;
}
- value = value * 10 + FXSYS_toDecimalDigit(str[cc]);
+ value = value * 10 + str[cc] - '0';
cc++;
}
static const FX_FLOAT fraction_scales[] = {
@@ -157,7 +157,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (cc < len && str[cc] == '.') {
cc++;
while (cc < len) {
- value += fraction_scales[scale] * FXSYS_toDecimalDigit(str[cc]);
+ value += fraction_scales[scale] * (str[cc] - '0');
scale++;
if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) {
break;
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index 220ffbd57d..131672da2b 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -5,10 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <stddef.h> // For offsetof().
-#include <cctype>
#include "core/include/fxcrt/fx_basic.h"
-#include "core/include/fxcrt/fx_ext.h"
#include "third_party/base/numerics/safe_math.h"
// static
@@ -767,8 +765,8 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) {
}
if (nWidth == 0) {
nWidth = FXSYS_wtoi(lpsz);
- while (std::iswdigit(*lpsz))
- ++lpsz;
+ for (; *lpsz != 0 && (*lpsz) <= '9' && (*lpsz) >= '0'; lpsz++)
+ ;
}
if (nWidth < 0 || nWidth > 128 * 1024) {
lpszFormat = L"Bad width";
@@ -783,8 +781,8 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) {
lpsz++;
} else {
nPrecision = FXSYS_wtoi(lpsz);
- while (std::iswdigit(*lpsz))
- ++lpsz;
+ for (; *lpsz != 0 && (*lpsz) >= '0' && (*lpsz) <= '9'; lpsz++)
+ ;
}
}
if (nPrecision < 0 || nPrecision > 128 * 1024) {
@@ -970,7 +968,7 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) {
if (str[cc] == '.') {
break;
}
- integer = integer * 10 + FXSYS_toDecimalDigitWide(str[cc]);
+ integer = integer * 10 + str[cc] - '0';
cc++;
}
FX_FLOAT fraction = 0;
@@ -978,7 +976,7 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) {
cc++;
FX_FLOAT scale = 0.1f;
while (cc < len) {
- fraction += scale * FXSYS_toDecimalDigitWide(str[cc]);
+ fraction += scale * (str[cc] - '0');
scale *= 0.1f;
cc++;
}
diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp
index 37437ae9ed..7eb86d6364 100644
--- a/core/src/fxcrt/fx_extension.cpp
+++ b/core/src/fxcrt/fx_extension.cpp
@@ -51,7 +51,9 @@ IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer,
IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive) {
return new CFX_MemoryStream(bConsecutive);
}
-
+#ifdef __cplusplus
+extern "C" {
+#endif
FX_FLOAT FXSYS_tan(FX_FLOAT a) {
return (FX_FLOAT)tan(a);
}
@@ -188,7 +190,12 @@ FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr,
}
return dwHashCode;
}
-
+#ifdef __cplusplus
+}
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
void* FX_Random_MT_Start(FX_DWORD dwSeed) {
FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1);
pContext->mt[0] = dwSeed;
@@ -291,3 +298,6 @@ void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount) {
FX_Random_GenerateBase(pBuffer, iCount);
#endif
}
+#ifdef __cplusplus
+}
+#endif
diff --git a/core/src/fxcrt/fx_extension_unittest.cpp b/core/src/fxcrt/fx_extension_unittest.cpp
deleted file mode 100644
index eff8878df0..0000000000
--- a/core/src/fxcrt/fx_extension_unittest.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2015 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-#include "../../include/fxcrt/fx_ext.h"
-
-TEST(fxcrt, FXSYS_toHexDigit) {
- EXPECT_EQ(10, FXSYS_toHexDigit('a'));
- EXPECT_EQ(10, FXSYS_toHexDigit('A'));
- EXPECT_EQ(7, FXSYS_toHexDigit('7'));
- EXPECT_EQ(0, FXSYS_toHexDigit('i'));
-}
-
-TEST(fxcrt, FXSYS_toDecimalDigit) {
- EXPECT_EQ(7, FXSYS_toDecimalDigit('7'));
- EXPECT_EQ(0, FXSYS_toDecimalDigit('a'));
-}
-
-TEST(fxcrt, FXSYS_toDecimalDigitWide) {
- EXPECT_EQ(7, FXSYS_toDecimalDigitWide(L'7'));
- EXPECT_EQ(0, FXSYS_toDecimalDigitWide(L'a'));
-}
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp
index 2d3ff6631e..429bc38289 100644
--- a/core/src/fxcrt/fx_xml_parser.cpp
+++ b/core/src/fxcrt/fx_xml_parser.cpp
@@ -6,7 +6,6 @@
#include "xml_int.h"
-#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_xml.h"
CXML_Parser::~CXML_Parser() {
@@ -229,8 +228,9 @@ FX_DWORD CXML_Parser::GetCharRef() {
iState = 10;
break;
}
- if (g_FXCRT_XML_IsDigital(ch))
- code = code * 10 + FXSYS_toDecimalDigit(ch);
+ if (g_FXCRT_XML_IsDigital(ch)) {
+ code = code * 10 + ch - '0';
+ }
break;
case 4:
m_dwIndex++;
@@ -242,7 +242,7 @@ FX_DWORD CXML_Parser::GetCharRef() {
g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_HexChar;
if (nHex) {
if (nHex == FXCRTM_XML_CHARTYPE_HexDigital) {
- code = (code << 4) + FXSYS_toDecimalDigit(ch);
+ code = (code << 4) + ch - '0';
} else if (nHex == FXCRTM_XML_CHARTYPE_HexLowerLetter) {
code = (code << 4) + ch - 87;
} else {