diff options
author | dan sinclair <dsinclair@chromium.org> | 2015-11-10 13:33:04 -0500 |
---|---|---|
committer | dan sinclair <dsinclair@chromium.org> | 2015-11-10 13:33:04 -0500 |
commit | 0569ab0b11b723d9bca4ddd642b0cf8828c4bdd1 (patch) | |
tree | d0f6ba295574785c773536be7b5526680ed60f04 /core/src/fxcrt/fx_basic_gcc.cpp | |
parent | e6e16954f0cdc324849fca9da883be8f131b3834 (diff) | |
download | pdfium-0569ab0b11b723d9bca4ddd642b0cf8828c4bdd1.tar.xz |
Revert x4 "Cleanup some numeric code."
This reverts commit b27902b8995bb3e003daed6b0811ed746763c68d.
Cleanup some numeric code.
This changes the various comparisons of char >= '0' && char <= '9' and
char < '0' || char > '9' to use std::isdigit checks. It also cleans up
a handful of hex to digit conversions to call one common method.
TBR=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1432973003 .
Diffstat (limited to 'core/src/fxcrt/fx_basic_gcc.cpp')
-rw-r--r-- | core/src/fxcrt/fx_basic_gcc.cpp | 48 |
1 files changed, 14 insertions, 34 deletions
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); |