summaryrefslogtreecommitdiff
path: root/core/src/fxcodec
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-16 12:28:39 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-16 12:28:39 -0500
commit3f148915d12f54a946a0c0bf526162b79c39d650 (patch)
tree17a95f27c8a6a07356b68ac41b5fbcc0f2358ab9 /core/src/fxcodec
parent76c6d639f46c37ba955569f507201eb3f1b613fc (diff)
downloadpdfium-3f148915d12f54a946a0c0bf526162b79c39d650.tar.xz
Reland "Cleanup some numeric code.""chromium/2567
This reverts commit 0569ab0b11b723d9bca4ddd642b0cf8828c4bdd1. 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/1449873003 .
Diffstat (limited to 'core/src/fxcodec')
-rw-r--r--core/src/fxcodec/codec/fx_codec.cpp49
1 files changed, 27 insertions, 22 deletions
diff --git a/core/src/fxcodec/codec/fx_codec.cpp b/core/src/fxcodec/codec/fx_codec.cpp
index bfa5befce4..51a1f5d55c 100644
--- a/core/src/fxcodec/codec/fx_codec.cpp
+++ b/core/src/fxcodec/codec/fx_codec.cpp
@@ -1,3 +1,4 @@
+
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,6 +10,7 @@
#include <cmath>
#include "codec_int.h"
+#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_safe_types.h"
#include "third_party/base/logging.h"
@@ -147,6 +149,20 @@ FX_BOOL CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf,
FX_DWORD& dest_size) {
return FALSE;
}
+
+#define EXPONENT_DETECT(ptr) \
+ for (;; ptr++) { \
+ if (!std::isdigit(*ptr)) { \
+ if (endptr) \
+ *endptr = (char*)ptr; \
+ break; \
+ } else { \
+ exp_ret *= 10; \
+ exp_ret += FXSYS_toDecimalDigit(*ptr); \
+ continue; \
+ } \
+ }
+
extern "C" double FXstrtod(const char* nptr, char** endptr) {
double ret = 0.0;
const char* ptr = nptr;
@@ -157,20 +173,20 @@ 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');
+ ret += FXSYS_toDecimalDigit(*ptr);
} else {
fra_count++;
fra_ret *= 10;
- fra_ret += (*ptr - '0');
+ fra_ret += FXSYS_toDecimalDigit(*ptr);
}
continue;
}
@@ -188,29 +204,17 @@ 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; \
- } \
- }
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) {
@@ -218,7 +222,6 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) {
}
break;
}
-#undef EXPONENT_DETECT
break;
}
if (ptr != nptr && !e_number) {
@@ -247,6 +250,8 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) {
}
return is_negative ? -ret : ret;
}
+#undef EXPONENT_DETECT
+
FX_BOOL CCodec_BasicModule::A85Encode(const uint8_t* src_buf,
FX_DWORD src_size,
uint8_t*& dest_buf,