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_gcc.cpp47
-rw-r--r--core/src/fxcrt/fx_basic_wstring.cpp4
-rw-r--r--core/src/fxcrt/fx_extension_unittest.cpp10
-rw-r--r--core/src/fxcrt/fx_xml_parser.cpp5
4 files changed, 24 insertions, 42 deletions
diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp
index 607f095570..e2ec939e7d 100644
--- a/core/src/fxcrt/fx_basic_gcc.cpp
+++ b/core/src/fxcrt/fx_basic_gcc.cpp
@@ -11,42 +11,19 @@
#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_string.h"
-template <class T>
-T FXSYS_StrToInt(const FX_CHAR* str) {
- bool neg = false;
+template <typename IntType, typename CharType>
+IntType FXSYS_StrToInt(const CharType* str) {
if (!str)
return 0;
- if (std::numeric_limits<T>::is_signed && *str == '-') {
- neg = true;
+ bool neg = std::numeric_limits<IntType>::is_signed && *str == '-';
+ if (neg)
str++;
- }
- T num = 0;
- while (*str && std::isdigit(*str)) {
- T val = FXSYS_toDecimalDigit(*str);
- if (num > (std::numeric_limits<T>::max() - val) / 10)
- break;
- num = num * 10 + val;
- str++;
- }
- return neg ? -num : num;
-}
-
-template <class T>
-T FXSYS_StrToInt(const FX_WCHAR* str) {
- bool neg = false;
- if (!str)
- return 0;
-
- if (std::numeric_limits<T>::is_signed && *str == '-') {
- neg = true;
- str++;
- }
- T num = 0;
- while (*str && std::iswdigit(*str)) {
- T val = FXSYS_toDecimalDigitWide(*str);
- if (num > (std::numeric_limits<T>::max() - val) / 10)
+ IntType num = 0;
+ while (*str && FXSYS_isDecimalDigit(*str)) {
+ IntType val = FXSYS_toDecimalDigit(*str);
+ if (num > (std::numeric_limits<IntType>::max() - val) / 10)
break;
num = num * 10 + val;
@@ -93,19 +70,19 @@ 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, FX_CHAR>(str);
}
uint32_t FXSYS_atoui(const FX_CHAR* str) {
return FXSYS_StrToInt<uint32_t>(str);
}
int32_t FXSYS_wtoi(const FX_WCHAR* str) {
- return FXSYS_StrToInt<int32_t>(str);
+ return FXSYS_StrToInt<int32_t, FX_WCHAR>(str);
}
int64_t FXSYS_atoi64(const FX_CHAR* str) {
- return FXSYS_StrToInt<int64_t>(str);
+ return FXSYS_StrToInt<int64_t, FX_CHAR>(str);
}
int64_t FXSYS_wtoi64(const FX_WCHAR* str) {
- return FXSYS_StrToInt<int64_t>(str);
+ return FXSYS_StrToInt<int64_t, 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_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index 396dbc4fff..8df72466e8 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -994,7 +994,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 + FXSYS_toDecimalDigit(str[cc]);
cc++;
}
FX_FLOAT fraction = 0;
@@ -1002,7 +1002,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 * FXSYS_toDecimalDigit(str[cc]);
scale *= 0.1f;
cc++;
}
diff --git a/core/src/fxcrt/fx_extension_unittest.cpp b/core/src/fxcrt/fx_extension_unittest.cpp
index b12dcbe07f..e2ae870f93 100644
--- a/core/src/fxcrt/fx_extension_unittest.cpp
+++ b/core/src/fxcrt/fx_extension_unittest.cpp
@@ -16,9 +16,13 @@ TEST(fxcrt, FXSYS_toHexDigit) {
TEST(fxcrt, FXSYS_toDecimalDigit) {
EXPECT_EQ(7, FXSYS_toDecimalDigit('7'));
EXPECT_EQ(0, FXSYS_toDecimalDigit('a'));
+ EXPECT_EQ(7, FXSYS_toDecimalDigit(L'7'));
+ EXPECT_EQ(0, FXSYS_toDecimalDigit(L'a'));
}
-TEST(fxcrt, FXSYS_toDecimalDigitWide) {
- EXPECT_EQ(7, FXSYS_toDecimalDigitWide(L'7'));
- EXPECT_EQ(0, FXSYS_toDecimalDigitWide(L'a'));
+TEST(fxcrt, FXSYS_isDecimalDigit) {
+ EXPECT_TRUE(FXSYS_isDecimalDigit('7'));
+ EXPECT_TRUE(FXSYS_isDecimalDigit(L'7'));
+ EXPECT_FALSE(FXSYS_isDecimalDigit('a'));
+ EXPECT_FALSE(FXSYS_isDecimalDigit(L'a'));
}
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp
index ab729eebaf..59c3de444e 100644
--- a/core/src/fxcrt/fx_xml_parser.cpp
+++ b/core/src/fxcrt/fx_xml_parser.cpp
@@ -231,7 +231,7 @@ FX_DWORD CXML_Parser::GetCharRef() {
break;
}
if (g_FXCRT_XML_IsDigital(ch))
- code = code * 10 + FXSYS_toDecimalDigit(ch);
+ code = code * 10 + FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch));
break;
case 4:
m_dwIndex++;
@@ -243,7 +243,8 @@ 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) + FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch));
} else if (nHex == FXCRTM_XML_CHARTYPE_HexLowerLetter) {
code = (code << 4) + ch - 87;
} else {