From e247ec47b75d45d16298e4e11ba68745b9ebe3eb Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 20 Apr 2017 21:41:36 -0700 Subject: Replace FXSYS_iswdigit with std::iswdigit. Replace other one-off implementations as well. Change-Id: I2878f3fae479c12b7de5234ee3a26477d602d14d Reviewed-on: https://pdfium-review.googlesource.com/4398 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- core/fpdftext/cpdf_textpagefind.cpp | 9 ++------- core/fxcrt/cfx_widestring.cpp | 1 + core/fxcrt/fx_extension.cpp | 16 ++++++++-------- core/fxcrt/fx_extension.h | 6 +----- core/fxcrt/xml/cfx_xmlsyntaxparser.cpp | 12 ++++++------ 5 files changed, 18 insertions(+), 26 deletions(-) (limited to 'core') diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp index 7eaac35194..a4f4a6e828 100644 --- a/core/fpdftext/cpdf_textpagefind.cpp +++ b/core/fpdftext/cpdf_textpagefind.cpp @@ -348,15 +348,10 @@ bool CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText, return false; } if (char_count > 0) { - if (csPageText.GetAt(startPos) >= L'0' && - csPageText.GetAt(startPos) <= L'9' && char_left >= L'0' && - char_left <= L'9') { + if (std::iswdigit(char_left) && std::iswdigit(csPageText.GetAt(startPos))) return false; - } - if (csPageText.GetAt(endPos) >= L'0' && csPageText.GetAt(endPos) <= L'9' && - char_right >= L'0' && char_right <= L'9') { + if (std::iswdigit(char_right) && std::iswdigit(csPageText.GetAt(endPos))) return false; - } } return true; } diff --git a/core/fxcrt/cfx_widestring.cpp b/core/fxcrt/cfx_widestring.cpp index 2b98ce59a4..8cd4de6edd 100644 --- a/core/fxcrt/cfx_widestring.cpp +++ b/core/fxcrt/cfx_widestring.cpp @@ -10,6 +10,7 @@ #include #include +#include #include "core/fxcrt/cfx_string_pool_template.h" #include "core/fxcrt/fx_basic.h" diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 47bd937ff8..209584b68d 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -6,6 +6,8 @@ #include "core/fxcrt/fx_extension.h" +#include + #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #include #else @@ -67,11 +69,10 @@ float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) { float fValue = 0.0f; while (iUsedLen < iLength) { wchar_t wch = pwsStr[iUsedLen]; - if (wch >= L'0' && wch <= L'9') - fValue = fValue * 10.0f + (wch - L'0'); - else + if (!std::iswdigit(wch)) break; + fValue = fValue * 10.0f + (wch - L'0'); iUsedLen++; } @@ -79,12 +80,11 @@ float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) { float fPrecise = 0.1f; while (++iUsedLen < iLength) { wchar_t wch = pwsStr[iUsedLen]; - if (wch >= L'0' && wch <= L'9') { - fValue += (wch - L'0') * fPrecise; - fPrecise *= 0.1f; - } else { + if (!std::iswdigit(wch)) break; - } + + fValue += (wch - L'0') * fPrecise; + fPrecise *= 0.1f; } } if (pUsedLen) diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h index e9d16786a9..00604fb22c 100644 --- a/core/fxcrt/fx_extension.h +++ b/core/fxcrt/fx_extension.h @@ -41,12 +41,8 @@ inline bool FXSYS_iswalpha(wchar_t wch) { return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z'); } -inline bool FXSYS_iswdigit(wchar_t wch) { - return wch >= L'0' && wch <= L'9'; -} - inline bool FXSYS_iswalnum(wchar_t wch) { - return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch); + return FXSYS_iswalpha(wch) || std::iswdigit(wch); } inline bool FXSYS_iswspace(wchar_t c) { diff --git a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp index ac3f1b5c5d..e3d690f5ab 100644 --- a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp +++ b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp @@ -7,6 +7,7 @@ #include "core/fxcrt/xml/cfx_xmlsyntaxparser.h" #include +#include #include #include "core/fxcrt/fx_extension.h" @@ -633,20 +634,19 @@ void CFX_XMLSyntaxParser::ParseTextChar(wchar_t character) { if (iLen > 1 && csEntity[1] == L'x') { for (int32_t i = 2; i < iLen; i++) { w = csEntity[i]; - if (w >= L'0' && w <= L'9') { + if (std::iswdigit(w)) ch = (ch << 4) + w - L'0'; - } else if (w >= L'A' && w <= L'F') { + else if (w >= L'A' && w <= L'F') ch = (ch << 4) + w - 55; - } else if (w >= L'a' && w <= L'f') { + else if (w >= L'a' && w <= L'f') ch = (ch << 4) + w - 87; - } else { + else break; - } } } else { for (int32_t i = 1; i < iLen; i++) { w = csEntity[i]; - if (w < L'0' || w > L'9') + if (!std::iswdigit(w)) break; ch = ch * 10 + w - L'0'; } -- cgit v1.2.3