diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-29 14:56:26 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-29 14:56:26 -0400 |
commit | 589f7e0a57675efce9810c15a3e9b7c49bf0bc90 (patch) | |
tree | 6839707c05c00f227744ffc3788665cb1cb5b7bd /core/src/fxcodec/codec | |
parent | 6ed0028f1cf12ee53e9e7f657b7ba186c77a42f3 (diff) | |
download | pdfium-589f7e0a57675efce9810c15a3e9b7c49bf0bc90.tar.xz |
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=thestig@chromium.org
Review URL: https://codereview.chromium.org/1415933005 .
Diffstat (limited to 'core/src/fxcodec/codec')
-rw-r--r-- | core/src/fxcodec/codec/fx_codec.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/core/src/fxcodec/codec/fx_codec.cpp b/core/src/fxcodec/codec/fx_codec.cpp index 46f479e0b1..eca6505d12 100644 --- a/core/src/fxcodec/codec/fx_codec.cpp +++ b/core/src/fxcodec/codec/fx_codec.cpp @@ -157,13 +157,13 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) { return 0.0; } for (;; ptr++) { - if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' ')) { + if (!e_number && !e_point && (*ptr == '\t' || *ptr == ' ')) continue; - } - if (*ptr >= '0' && *ptr <= '9') { - if (!e_number) { + + if (std::isdigit(*ptr)) { + if (!e_number) e_number = 1; - } + if (!e_point) { ret *= 10; ret += (*ptr - '0'); @@ -188,29 +188,29 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) { } } if (e_number && (*ptr == 'e' || *ptr == 'E')) { -#define EXPONENT_DETECT(ptr) \ - for (;; ptr++) { \ - if (*ptr < '0' || *ptr > '9') { \ - if (endptr) \ - *endptr = (char*)ptr; \ - break; \ - } else { \ - exp_ret *= 10; \ - exp_ret += (*ptr - '0'); \ - continue; \ - } \ +#define EXPONENT_DETECT(ptr) \ + for (;; ptr++) { \ + if (!std::isdigit(*ptr)) { \ + if (endptr) \ + *endptr = (char*)ptr; \ + break; \ + } else { \ + exp_ret *= 10; \ + exp_ret += (*ptr - '0'); \ + continue; \ + } \ } exp_ptr = ptr++; if (*ptr == '+' || *ptr == '-') { exp_sig = (*ptr++ == '+') ? 1 : -1; - if (*ptr < '0' || *ptr > '9') { + if (!std::isdigit(*ptr)) { if (endptr) { *endptr = (char*)exp_ptr; } break; } EXPONENT_DETECT(ptr); - } else if (*ptr >= '0' && *ptr <= '9') { + } else if (std::isdigit(*ptr)) { EXPONENT_DETECT(ptr); } else { if (endptr) { |