Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Unified Diff: core/src/fxcodec/codec/fx_codec.cpp

Issue 1452673002: Merge to XFA: Reland "Cleanup some numeric code."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fxcodec/codec/fx_codec.cpp
diff --git a/core/src/fxcodec/codec/fx_codec.cpp b/core/src/fxcodec/codec/fx_codec.cpp
index 7b6aacea2db6ac4e208b71c210f845da4b047f20..b357f8ac081ec1b5f2f7aee2b1129c5ea1639323 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"
@@ -151,6 +153,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;
@@ -161,20 +177,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;
}
@@ -192,29 +208,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) {
@@ -222,7 +226,6 @@ extern "C" double FXstrtod(const char* nptr, char** endptr) {
}
break;
}
-#undef EXPONENT_DETECT
break;
}
if (ptr != nptr && !e_number) {
@@ -251,6 +254,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,

Powered by Google App Engine
This is Rietveld 408576698