From 10cfea1fdafc8fcf1edd60bc783e9db9ef6229c0 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 16 Nov 2015 13:09:00 -0500 Subject: Merge to XFA: Reland "Cleanup some numeric code."" 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 . (cherry picked from commit 3f148915d12f54a946a0c0bf526162b79c39d650) Review URL: https://codereview.chromium.org/1452673002 . --- fpdfsdk/src/fsdk_baseannot.cpp | 44 +++++++++++++++----------------- fpdfsdk/src/javascript/PublicMethods.cpp | 5 ++-- fpdfsdk/src/javascript/util.cpp | 7 ++--- 3 files changed, 28 insertions(+), 28 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp index 090a50fe62..8b083e3bea 100644 --- a/fpdfsdk/src/fsdk_baseannot.cpp +++ b/fpdfsdk/src/fsdk_baseannot.cpp @@ -4,7 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "../include/fpdfxfa/fpdfxfa_doc.h" +#include "core/include/fxcrt/fx_ext.h" +#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" #include "fpdfsdk/include/fsdk_baseannot.h" #include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/include/fsdk_mgr.h" @@ -217,12 +218,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( int i = 0; int j, k; FX_CHAR ch; - while (i < strLength) { - ch = dtStr[i]; - if (ch >= '0' && ch <= '9') - break; - i++; - } + while (i < strLength && !std::isdigit(dtStr[i])) + ++i; + if (i >= strLength) return *this; @@ -230,9 +228,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 4) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } @@ -244,9 +242,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 2) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } @@ -258,9 +256,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 2) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } @@ -272,9 +270,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 2) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } @@ -286,9 +284,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 2) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } @@ -300,9 +298,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 2) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } @@ -321,9 +319,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 2) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } @@ -338,9 +336,9 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( k = 0; while (i < strLength && j < 2) { ch = dtStr[i]; - k = k * 10 + ch - '0'; + k = k * 10 + FXSYS_toDecimalDigit(ch); j++; - if (ch < '0' || ch > '9') + if (!std::isdigit(ch)) break; i++; } diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp index 454085069e..75327dd631 100644 --- a/fpdfsdk/src/javascript/PublicMethods.cpp +++ b/fpdfsdk/src/javascript/PublicMethods.cpp @@ -14,6 +14,7 @@ #include "JS_Runtime.h" #include "JS_Value.h" #include "color.h" +#include "core/include/fxcrt/fx_ext.h" #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. #include "fpdfsdk/include/javascript/IJavaScript.h" #include "resource.h" @@ -108,7 +109,7 @@ FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) { } FX_BOOL CJS_PublicMethods::IsDigit(char ch) { - return (ch >= '0' && ch <= '9'); + return std::isdigit(ch); } FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) { @@ -388,7 +389,7 @@ int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string, FX_WCHAR c = string.GetAt(i); if (IsDigit((wchar_t)c)) { - nRet = nRet * 10 + (c - '0'); + nRet = nRet * 10 + FXSYS_toDecimalDigitWide(c); nSkip = i - nStart + 1; if (nSkip >= nMaxStep) break; diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp index c021ec9e95..30df53ea72 100644 --- a/fpdfsdk/src/javascript/util.cpp +++ b/fpdfsdk/src/javascript/util.cpp @@ -13,6 +13,7 @@ #include "JS_Runtime.h" #include "JS_Value.h" #include "PublicMethods.h" +#include "core/include/fxcrt/fx_ext.h" #include "fpdfsdk/include/javascript/IJavaScript.h" #include "resource.h" @@ -425,7 +426,7 @@ void util::printx(const std::string& cFormat, break; case 'X': { while (itSource < iSize) { - if ((cSource[itSource] >= '0' && cSource[itSource] <= '9') || + if (std::isdigit(cSource[itSource]) || (cSource[itSource] >= 'a' && cSource[itSource] <= 'z') || (cSource[itSource] >= 'A' && cSource[itSource] <= 'Z')) { cPurpose += cSource[itSource]; @@ -450,7 +451,7 @@ void util::printx(const std::string& cFormat, } break; case '9': { while (itSource < iSize) { - if (cSource[itSource] >= '0' && cSource[itSource] <= '9') { + if (std::isdigit(cSource[itSource])) { cPurpose += cSource[itSource]; itSource++; break; @@ -531,7 +532,7 @@ int64_t FX_atoi64(const char* nptr) { total = 0; while (isdigit(c)) { - total = 10 * total + (c - '0'); /* accumulate digit */ + total = 10 * total + FXSYS_toDecimalDigit(c); /* accumulate digit */ c = (int)(unsigned char)*nptr++; /* get next char */ } -- cgit v1.2.3