From 589f7e0a57675efce9810c15a3e9b7c49bf0bc90 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 29 Oct 2015 14:56:26 -0400 Subject: 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 . --- core/src/fxcodec/codec/fx_codec.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'core/src/fxcodec') 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) { -- cgit v1.2.3