summaryrefslogtreecommitdiff
path: root/core/src/fxcrt/fx_basic_util.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-03 14:54:35 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-03 14:54:35 -0500
commite0e922db5fb77df9a5a9cc802096f484ed21da1c (patch)
treed6b3da42c1a28ec150c5cb9fe6b00d8f6af099d5 /core/src/fxcrt/fx_basic_util.cpp
parentc9e76c09b9e7901823ac52a3705da235bd2abe24 (diff)
downloadpdfium-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_util.cpp')
-rw-r--r--core/src/fxcrt/fx_basic_util.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/core/src/fxcrt/fx_basic_util.cpp b/core/src/fxcrt/fx_basic_util.cpp
index 46a0dec1e5..78bdeee693 100644
--- a/core/src/fxcrt/fx_basic_util.cpp
+++ b/core/src/fxcrt/fx_basic_util.cpp
@@ -5,12 +5,17 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../include/fxcrt/fx_basic.h"
+#include "../../include/fxcrt/fx_ext.h"
+
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
#include <sys/types.h>
#include <dirent.h>
#else
#include <direct.h>
#endif
+
+#include <cctype>
+
CFX_PrivateData::~CFX_PrivateData() {
ClearAll();
}
@@ -100,14 +105,11 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
bNegative = TRUE;
cc++;
}
- while (cc < len) {
- if (str[cc] < '0' || str[cc] > '9') {
+ while (cc < len && std::isdigit(str[cc])) {
+ integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]);
+ if (integer < 0)
break;
- }
- integer = integer * 10 + str[cc] - '0';
- if (integer < 0) {
- break;
- }
+
cc++;
}
if (bNegative) {
@@ -144,7 +146,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (str[cc] == '.') {
break;
}
- value = value * 10 + str[cc] - '0';
+ value = value * 10 + FXSYS_toDecimalDigit(str[cc]);
cc++;
}
static const FX_FLOAT fraction_scales[] = {
@@ -155,7 +157,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (cc < len && str[cc] == '.') {
cc++;
while (cc < len) {
- value += fraction_scales[scale] * (str[cc] - '0');
+ value += fraction_scales[scale] * FXSYS_toDecimalDigit(str[cc]);
scale++;
if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) {
break;