From ce56557ef58facf2519f541d5cad33ea121b4c21 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 23 Jun 2016 14:00:32 -0700 Subject: 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 --- xfa/fxfa/parser/cxfa_data.cpp | 13 ++++++------ xfa/fxfa/parser/cxfa_widgetdata.cpp | 2 +- xfa/fxfa/parser/xfa_localevalue.cpp | 41 ++++++++++++++++++++----------------- xfa/fxfa/parser/xfa_utils.h | 8 +------- xfa/fxfa/parser/xfa_utils_imp.cpp | 6 +++--- 5 files changed, 34 insertions(+), 36 deletions(-) (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cxfa_data.cpp b/xfa/fxfa/parser/cxfa_data.cpp index 7a218516b7..0589adf581 100644 --- a/xfa/fxfa/parser/cxfa_data.cpp +++ b/xfa/fxfa/parser/cxfa_data.cpp @@ -6,6 +6,7 @@ #include "xfa/fxfa/parser/cxfa_data.h" +#include "core/fxcrt/include/fx_ext.h" #include "xfa/fxfa/parser/xfa_object.h" // Static. @@ -17,14 +18,14 @@ FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { int cc = 0; const FX_WCHAR* str = wsValue.c_str(); int len = wsValue.GetLength(); - while (XFA_IsSpace(str[cc]) && cc < len) + while (FXSYS_iswspace(str[cc]) && cc < len) cc++; if (cc >= len) return 0xff000000; while (cc < len) { - if (str[cc] == ',' || !XFA_IsDigit(str[cc])) + if (str[cc] == ',' || !FXSYS_isDecimalDigit(str[cc])) break; r = r * 10 + str[cc] - '0'; @@ -32,11 +33,11 @@ FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { } if (cc < len && str[cc] == ',') { cc++; - while (XFA_IsSpace(str[cc]) && cc < len) + while (FXSYS_iswspace(str[cc]) && cc < len) cc++; while (cc < len) { - if (str[cc] == ',' || !XFA_IsDigit(str[cc])) + if (str[cc] == ',' || !FXSYS_isDecimalDigit(str[cc])) break; g = g * 10 + str[cc] - '0'; @@ -44,11 +45,11 @@ FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { } if (cc < len && str[cc] == ',') { cc++; - while (XFA_IsSpace(str[cc]) && cc < len) + while (FXSYS_iswspace(str[cc]) && cc < len) cc++; while (cc < len) { - if (str[cc] == ',' || !XFA_IsDigit(str[cc])) + if (str[cc] == ',' || !FXSYS_isDecimalDigit(str[cc])) break; b = b * 10 + str[cc] - '0'; diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index d241772fe3..1dd78e198f 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -1753,7 +1753,7 @@ CFX_WideString CXFA_WidgetData::NumericLimit(const CFX_WideString& wsValue, } for (; i < iCount; i++) { FX_WCHAR wc = wsValue[i]; - if (XFA_IsDigit(wc)) { + if (FXSYS_isDecimalDigit(wc)) { if (iLead >= 0) { iLead_++; if (iLead_ > iLead) diff --git a/xfa/fxfa/parser/xfa_localevalue.cpp b/xfa/fxfa/parser/xfa_localevalue.cpp index 0aa646d932..c7f78b387e 100644 --- a/xfa/fxfa/parser/xfa_localevalue.cpp +++ b/xfa/fxfa/parser/xfa_localevalue.cpp @@ -6,6 +6,7 @@ #include "xfa/fxfa/parser/xfa_localevalue.h" +#include "core/fxcrt/include/fx_ext.h" #include "xfa/fgas/localization/fgas_localeimp.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" @@ -219,7 +220,7 @@ FX_FLOAT CXFA_LocaleValue::GetNum() const { FX_BOOL bNegative = FALSE, bExpSign = FALSE; const FX_WCHAR* str = m_wsValue.c_str(); int len = m_wsValue.GetLength(); - while (XFA_IsSpace(str[cc]) && cc < len) { + while (FXSYS_iswspace(str[cc]) && cc < len) { cc++; } if (cc >= len) { @@ -233,7 +234,8 @@ FX_FLOAT CXFA_LocaleValue::GetNum() const { } int nIntegralLen = 0; while (cc < len) { - if (str[cc] == '.' || !XFA_IsDigit(str[cc]) || nIntegralLen > 17) { + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || + nIntegralLen > 17) { break; } nIntegral = nIntegral * 10 + str[cc] - '0'; @@ -250,7 +252,7 @@ FX_FLOAT CXFA_LocaleValue::GetNum() const { scale++; cc++; if (scale == sizeof fraction_scales / sizeof(double) || - !XFA_IsDigit(str[cc])) { + !FXSYS_isDecimalDigit(str[cc])) { break; } } @@ -267,7 +269,7 @@ FX_FLOAT CXFA_LocaleValue::GetNum() const { } } while (cc < len) { - if (str[cc] == '.' || !XFA_IsDigit(str[cc])) { + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { break; } nExponent = nExponent * 10 + str[cc] - '0'; @@ -294,7 +296,7 @@ FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { FX_BOOL bNegative = FALSE, bExpSign = FALSE; const FX_WCHAR* str = m_wsValue.c_str(); int len = m_wsValue.GetLength(); - while (XFA_IsSpace(str[cc]) && cc < len) { + while (FXSYS_iswspace(str[cc]) && cc < len) { cc++; } if (cc >= len) { @@ -308,7 +310,8 @@ FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { } int32_t nIntegralLen = 0; while (cc < len) { - if (str[cc] == '.' || !XFA_IsDigit(str[cc]) || nIntegralLen > 17) { + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || + nIntegralLen > 17) { break; } nIntegral = nIntegral * 10 + str[cc] - '0'; @@ -325,7 +328,7 @@ FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { scale++; cc++; if (scale == sizeof fraction_scales / sizeof(FX_DOUBLE) || - !XFA_IsDigit(str[cc])) { + !FXSYS_isDecimalDigit(str[cc])) { break; } } @@ -342,7 +345,7 @@ FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { } } while (cc < len) { - if (str[cc] == '.' || !XFA_IsDigit(str[cc])) { + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { break; } nExponent = nExponent * 10 + str[cc] - '0'; @@ -616,7 +619,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, const FX_WCHAR* pDate = wsDate.c_str(); int nIndex = 0, nStart = 0; while (pDate[nIndex] != '\0' && nIndex < wCountY) { - if (!XFA_IsDigit(pDate[nIndex])) { + if (!FXSYS_isDecimalDigit(pDate[nIndex])) { return FALSE; } wYear = (pDate[nIndex] - '0') + wYear * 10; @@ -630,7 +633,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, } nStart = nIndex; while (pDate[nIndex] != '\0' && nIndex - nStart < wCountM && nIndex < nLen) { - if (!XFA_IsDigit(pDate[nIndex])) { + if (!FXSYS_isDecimalDigit(pDate[nIndex])) { return FALSE; } wMonth = (pDate[nIndex] - '0') + wMonth * 10; @@ -644,7 +647,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, } nStart = nIndex; while (pDate[nIndex] != '\0' && nIndex - nStart < wCountD && nIndex < nLen) { - if (!XFA_IsDigit(pDate[nIndex])) { + if (!FXSYS_isDecimalDigit(pDate[nIndex])) { return FALSE; } wDay = (pDate[nIndex] - '0') + wDay * 10; @@ -703,7 +706,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { int nIndex = 0; int nStart = 0; while (nIndex - nStart < wCountH && pTime[nIndex]) { - if (!XFA_IsDigit(pTime[nIndex])) + if (!FXSYS_isDecimalDigit(pTime[nIndex])) return FALSE; wHour = pTime[nIndex] - '0' + wHour * 10; nIndex++; @@ -715,7 +718,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { } nStart = nIndex; while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) { - if (!XFA_IsDigit(pTime[nIndex])) + if (!FXSYS_isDecimalDigit(pTime[nIndex])) return FALSE; wMinute = pTime[nIndex] - '0' + wMinute * 10; nIndex++; @@ -727,7 +730,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { } nStart = nIndex; while (nIndex - nStart < wCountS && nIndex < nLen && pTime[nIndex]) { - if (!XFA_IsDigit(pTime[nIndex])) + if (!FXSYS_isDecimalDigit(pTime[nIndex])) return FALSE; wSecond = pTime[nIndex] - '0' + wSecond * 10; nIndex++; @@ -738,7 +741,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { nIndex++; nStart = nIndex; while (nIndex - nStart < wCountF && nIndex < nLen && pTime[nIndex]) { - if (!XFA_IsDigit(pTime[nIndex])) + if (!FXSYS_isDecimalDigit(pTime[nIndex])) return FALSE; wFraction = pTime[nIndex] - '0' + wFraction * 10; nIndex++; @@ -753,7 +756,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { nIndex++; nStart = nIndex; while (nIndex - nStart < wCountH && nIndex < nLen && pTime[nIndex]) { - if (!XFA_IsDigit(pTime[nIndex])) + if (!FXSYS_isDecimalDigit(pTime[nIndex])) return FALSE; nOffsetH = pTime[nIndex] - '0' + nOffsetH * 10; nIndex++; @@ -765,7 +768,7 @@ FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { } nStart = nIndex; while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) { - if (!XFA_IsDigit(pTime[nIndex])) + if (!FXSYS_isDecimalDigit(pTime[nIndex])) return FALSE; nOffsetM = pTime[nIndex] - '0' + nOffsetM * 10; nIndex++; @@ -943,7 +946,7 @@ FX_BOOL CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, int32_t nCount = wsNumeric.GetLength(); int32_t nCountFmt = wsFormat.GetLength(); while (n < nCount && (bLimit ? nf < nCountFmt : TRUE) && - XFA_IsDigit(c = pNum[n])) { + FXSYS_isDecimalDigit(c = pNum[n])) { if (bLimit == TRUE) { if ((cf = pFmt[nf]) == L'*') { bLimit = FALSE; @@ -981,7 +984,7 @@ FX_BOOL CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, ++n; bLimit = TRUE; while (n < nCount && (bLimit ? nf < nCountFmt : TRUE) && - XFA_IsDigit(c = pNum[n])) { + FXSYS_isDecimalDigit(c = pNum[n])) { if (bLimit == TRUE) { if ((cf = pFmt[nf]) == L'*') { bLimit = FALSE; diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index 1036d9353f..a9101092a8 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h @@ -18,17 +18,11 @@ class CXFA_LocaleValue; class CXFA_Node; class CXFA_WidgetData; -inline FX_BOOL XFA_IsSpace(FX_WCHAR c) { - return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); -} -inline FX_BOOL XFA_IsDigit(FX_WCHAR c) { - return c >= '0' && c <= '9'; -} - FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( CFDE_XMLElement* pNode, const CFX_WideStringC& wsQualifier, CFX_WideString& wsNamespaceURI); + template class CXFA_NodeIteratorTemplate { public: diff --git a/xfa/fxfa/parser/xfa_utils_imp.cpp b/xfa/fxfa/parser/xfa_utils_imp.cpp index b1fe7b3524..f5da036498 100644 --- a/xfa/fxfa/parser/xfa_utils_imp.cpp +++ b/xfa/fxfa/parser/xfa_utils_imp.cpp @@ -303,7 +303,7 @@ FX_DOUBLE XFA_WideStringToDouble(const CFX_WideString& wsStringVal) { nIntegralLen > 17) { break; } - if (!XFA_IsDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) { return 0; } nIntegral = nIntegral * 10 + str[cc] - '0'; @@ -326,7 +326,7 @@ FX_DOUBLE XFA_WideStringToDouble(const CFX_WideString& wsStringVal) { str[cc] == 'E' || str[cc] == 'e') { break; } - if (!XFA_IsDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) { return 0; } } @@ -343,7 +343,7 @@ FX_DOUBLE XFA_WideStringToDouble(const CFX_WideString& wsStringVal) { } } while (cc < len) { - if (str[cc] == '.' || !XFA_IsDigit(str[cc])) { + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { return 0; } nExponent = nExponent * 10 + str[cc] - '0'; -- cgit v1.2.3