diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-11-03 14:54:35 -0500 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-11-03 14:54:35 -0500 |
commit | e0e922db5fb77df9a5a9cc802096f484ed21da1c (patch) | |
tree | d6b3da42c1a28ec150c5cb9fe6b00d8f6af099d5 /core/src/fxcrt/fx_basic_gcc.cpp | |
parent | c9e76c09b9e7901823ac52a3705da235bd2abe24 (diff) | |
download | pdfium-e0e922db5fb77df9a5a9cc802096f484ed21da1c.tar.xz |
Revert "Revert "Cleanup some numeric code.""
This reverts commit 23d576f0b498bd4f37ef2175916223a2e5ea0324.
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.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1405253007 .
Diffstat (limited to 'core/src/fxcrt/fx_basic_gcc.cpp')
-rw-r--r-- | core/src/fxcrt/fx_basic_gcc.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp index 6f17482156..250079913c 100644 --- a/core/src/fxcrt/fx_basic_gcc.cpp +++ b/core/src/fxcrt/fx_basic_gcc.cpp @@ -5,6 +5,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include <limits> +#include <cctype> #include "../../include/fxcrt/fx_ext.h" #include "../../include/fxcrt/fx_string.h" @@ -12,22 +13,19 @@ template <class T, class STR_T> T FXSYS_StrToInt(STR_T str) { FX_BOOL neg = FALSE; - if (str == NULL) { + if (!str) return 0; - } + if (*str == '-') { neg = TRUE; str++; } T num = 0; - while (*str) { - if ((*str) < '0' || (*str) > '9') { + while (*str && std::isdigit(*str)) { + if (num > (std::numeric_limits<T>::max() - 9) / 10) break; - } - if (num > (std::numeric_limits<T>::max() - 9) / 10) { - break; - } - num = num * 10 + (*str) - '0'; + + num = num * 10 + FXSYS_toDecimalDigit(*str); str++; } return neg ? -num : num; |