diff options
author | dsinclair <dsinclair@chromium.org> | 2016-06-23 14:00:32 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-23 14:00:32 -0700 |
commit | ce56557ef58facf2519f541d5cad33ea121b4c21 (patch) | |
tree | da8de59a3cd5b7abcd7603eba3ba46e0d503daab /core/fxcrt | |
parent | b97784706ec898ff6b1c36f1564c0c66f9419b17 (diff) | |
download | pdfium-ce56557ef58facf2519f541d5cad33ea121b4c21.tar.xz |
Use some FXSYS methods instead of duplicating
This CL uses the FXSYS_isDecimalDigit in place of a few custom IsDigit methods.
It also creates an iswspace and some fractional math helper methods to share
some code.
Review-Url: https://codereview.chromium.org/2094453004
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/fx_basic_util.cpp | 21 | ||||
-rw-r--r-- | core/fxcrt/include/fx_ext.h | 6 |
2 files changed, 21 insertions, 6 deletions
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index b9cf470d08..12d3aefd1c 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -47,6 +47,18 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { } } +static const FX_FLOAT fraction_scales[] = { + 0.1f, 0.01f, 0.001f, 0.0001f, + 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, + 0.000000001f, 0.0000000001f, 0.00000000001f}; +int FXSYS_FractionalScaleCount() { + return FX_ArraySize(fraction_scales); +} + +FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value) { + return fraction_scales[scale_factor] * value; +} + FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { if (strc.IsEmpty()) return 0.0; @@ -74,17 +86,14 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); cc++; } - static const FX_FLOAT fraction_scales[] = { - 0.1f, 0.01f, 0.001f, 0.0001f, - 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, - 0.000000001f, 0.0000000001f, 0.00000000001f}; int scale = 0; if (cc < len && strc[cc] == '.') { cc++; while (cc < len) { - value += fraction_scales[scale] * FXSYS_toDecimalDigit(strc.CharAt(cc)); + value += + FXSYS_FractionalScale(scale, FXSYS_toDecimalDigit(strc.CharAt(cc))); scale++; - if (scale == FX_ArraySize(fraction_scales)) + if (scale == FXSYS_FractionalScaleCount()) break; cc++; } diff --git a/core/fxcrt/include/fx_ext.h b/core/fxcrt/include/fx_ext.h index d37db67d4a..f7aca68d64 100644 --- a/core/fxcrt/include/fx_ext.h +++ b/core/fxcrt/include/fx_ext.h @@ -53,6 +53,9 @@ inline bool FXSYS_iswdigit(wchar_t wch) { inline bool FXSYS_iswalnum(wchar_t wch) { return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch); } +inline bool FXSYS_iswspace(FX_WCHAR c) { + return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); +} inline int FXSYS_toHexDigit(const FX_CHAR c) { if (!std::isxdigit(c)) @@ -77,6 +80,9 @@ inline int FXSYS_toDecimalDigit(const FX_WCHAR c) { return std::iswdigit(c) ? c - L'0' : 0; } +FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value); +int FXSYS_FractionalScaleCount(); + uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase); uint32_t FX_HashCode_GetW(const CFX_WideStringC& Str, bool bIgnoreCase); |