From ab1faaa7f81b7dafe03d546341c6a643a58b3678 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 24 Apr 2017 16:16:49 -0700 Subject: Use fx_extension.h utilities in more places in xfa/ Change-Id: Id58c313aa446ecfa223e5c8edc095586b62a61fa Reviewed-on: https://pdfium-review.googlesource.com/4455 Commit-Queue: dsinclair Reviewed-by: dsinclair --- xfa/fde/css/cfde_cssselector.cpp | 14 +-- xfa/fde/css/cfde_csssyntaxparser.cpp | 4 +- xfa/fde/css/cfde_cssvaluelistparser.cpp | 3 +- xfa/fgas/crt/cfgas_formatstring.cpp | 29 +++-- xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 48 ++++---- xfa/fxfa/fm2js/xfa_lexer.cpp | 189 +++++++++++--------------------- xfa/fxfa/parser/cxfa_widgetdata.cpp | 16 +-- 7 files changed, 112 insertions(+), 191 deletions(-) diff --git a/xfa/fde/css/cfde_cssselector.cpp b/xfa/fde/css/cfde_cssselector.cpp index 6842d58738..c1e9f7f22a 100644 --- a/xfa/fde/css/cfde_cssselector.cpp +++ b/xfa/fde/css/cfde_cssselector.cpp @@ -8,24 +8,18 @@ #include +#include "core/fxcrt/fx_extension.h" #include "third_party/base/ptr_util.h" namespace { -bool IsCSSChar(wchar_t wch) { - return (wch >= 'a' && wch <= 'z') || (wch >= 'A' && wch <= 'Z'); -} - int32_t GetCSSNameLen(const wchar_t* psz, const wchar_t* pEnd) { const wchar_t* pStart = psz; while (psz < pEnd) { wchar_t wch = *psz; - if (IsCSSChar(wch) || (wch >= '0' && wch <= '9') || wch == '_' || - wch == '-') { - ++psz; - } else { + if (!FXSYS_iswalnum(wch) && wch != '_' && wch != '-') break; - } + ++psz; } return psz - pStart; } @@ -73,7 +67,7 @@ std::unique_ptr CFDE_CSSSelector::FromString( std::unique_ptr pFirst = nullptr; for (psz = pStart; psz < pEnd;) { wchar_t wch = *psz; - if (IsCSSChar(wch) || wch == '*') { + if (FXSYS_iswalpha(wch) || wch == '*') { int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd); auto p = pdfium::MakeUnique( FDE_CSSSelectorType::Element, psz, iNameLen, true); diff --git a/xfa/fde/css/cfde_csssyntaxparser.cpp b/xfa/fde/css/cfde_csssyntaxparser.cpp index ac1abcc665..bc861bdd6e 100644 --- a/xfa/fde/css/cfde_csssyntaxparser.cpp +++ b/xfa/fde/css/cfde_csssyntaxparser.cpp @@ -9,14 +9,14 @@ #include #include "core/fxcrt/fx_codepage.h" +#include "core/fxcrt/fx_extension.h" #include "xfa/fde/css/cfde_cssdeclaration.h" #include "xfa/fde/css/fde_cssdatatable.h" namespace { bool IsSelectorStart(wchar_t wch) { - return wch == '.' || wch == '#' || wch == '*' || (wch >= 'a' && wch <= 'z') || - (wch >= 'A' && wch <= 'Z'); + return wch == '.' || wch == '#' || wch == '*' || FXSYS_iswalpha(wch); } } // namespace diff --git a/xfa/fde/css/cfde_cssvaluelistparser.cpp b/xfa/fde/css/cfde_cssvaluelistparser.cpp index 36d5edc3c7..84dc20b328 100644 --- a/xfa/fde/css/cfde_cssvaluelistparser.cpp +++ b/xfa/fde/css/cfde_cssvaluelistparser.cpp @@ -30,8 +30,7 @@ bool CFDE_CSSValueListParser::NextValue(FDE_CSSPrimitiveType& eType, iLength = SkipTo(' ', false, false); if (iLength == 4 || iLength == 7) eType = FDE_CSSPrimitiveType::RGB; - } else if ((wch >= '0' && wch <= '9') || wch == '.' || wch == '-' || - wch == '+') { + } else if (std::iswdigit(wch) || wch == '.' || wch == '-' || wch == '+') { while (m_pCur < m_pEnd && (*m_pCur > ' ' && *m_pCur != m_Separator)) ++m_pCur; diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp index d4ac87c7bc..0c2e307b7c 100644 --- a/xfa/fgas/crt/cfgas_formatstring.cpp +++ b/xfa/fgas/crt/cfgas_formatstring.cpp @@ -89,6 +89,16 @@ int32_t ParseTimeZone(const wchar_t* pStr, int32_t iLen, FX_TIMEZONE* tz) { return iStart; } +int32_t ConvertHex(int32_t iKeyValue, wchar_t ch) { + if (std::iswdigit(ch)) + return iKeyValue * 16 + ch - '0'; + if (FXSYS_islower(ch)) + return iKeyValue * 16 + ch - 'a' + 10; + if (FXSYS_isupper(ch)) + return iKeyValue * 16 + ch - 'A' + 10; + return iKeyValue; +} + CFX_WideString GetLiteralText(const wchar_t* pStrPattern, int32_t& iPattern, int32_t iLenPattern) { @@ -104,9 +114,8 @@ CFX_WideString GetLiteralText(const wchar_t* pStrPattern, if ((iPattern + 1 >= iLenPattern) || ((pStrPattern[iPattern + 1] != '\'') && (iQuote % 2 == 0))) { break; - } else { - iQuote++; } + iQuote++; iPattern++; } else if (pStrPattern[iPattern] == '\\' && (iPattern + 1 < iLenPattern) && pStrPattern[iPattern + 1] == 'u') { @@ -115,13 +124,7 @@ CFX_WideString GetLiteralText(const wchar_t* pStrPattern, int32_t i = 0; while (iPattern < iLenPattern && i++ < 4) { wchar_t ch = pStrPattern[iPattern++]; - if ((ch >= '0' && ch <= '9')) { - iKeyValue = iKeyValue * 16 + ch - '0'; - } else if ((ch >= 'a' && ch <= 'f')) { - iKeyValue = iKeyValue * 16 + ch - 'a' + 10; - } else if ((ch >= 'A' && ch <= 'F')) { - iKeyValue = iKeyValue * 16 + ch - 'A' + 10; - } + iKeyValue = ConvertHex(iKeyValue, ch); } if (iKeyValue != 0) { wsOutput += (wchar_t)(iKeyValue & 0x0000FFFF); @@ -158,13 +161,7 @@ CFX_WideString GetLiteralTextReverse(const wchar_t* pStrPattern, int32_t i = 1; for (; i < iLen && i < 5; i++) { wchar_t ch = wsOutput[i]; - if ((ch >= '0' && ch <= '9')) { - iKeyValue = iKeyValue * 16 + ch - '0'; - } else if ((ch >= 'a' && ch <= 'f')) { - iKeyValue = iKeyValue * 16 + ch - 'a' + 10; - } else if ((ch >= 'A' && ch <= 'F')) { - iKeyValue = iKeyValue * 16 + ch - 'A' + 10; - } + iKeyValue = ConvertHex(iKeyValue, ch); } if (iKeyValue != 0) { wsOutput.Delete(0, i); diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index bf44ffbcc4..5c67418218 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -543,6 +543,14 @@ FX_LOCALEDATETIMESUBCATEGORY SubCategoryFromInt(int32_t iStyle) { } } +bool IsPartOfNumber(char ch) { + return std::isdigit(ch) || ch == '-' || ch == '.'; +} + +bool IsPartOfNumberW(wchar_t ch) { + return std::iswdigit(ch) || ch == L'-' || ch == L'.'; +} + } // namespace // static @@ -1674,7 +1682,7 @@ bool CXFA_FM2JSContext::IsIsoDateFormat(const char* pData, char strYear[5]; strYear[4] = '\0'; for (int32_t i = 0; i < 4; ++i) { - if (pData[i] > '9' || pData[i] < '0') + if (!std::isdigit(pData[i])) return false; strYear[i] = pData[i]; @@ -1689,8 +1697,7 @@ bool CXFA_FM2JSContext::IsIsoDateFormat(const char* pData, char strTemp[3]; strTemp[2] = '\0'; int32_t iPosOff = iStyle == 0 ? 4 : 5; - if ((pData[iPosOff] > '9' || pData[iPosOff] < '0') || - (pData[iPosOff + 1] > '9' || pData[iPosOff + 1] < '0')) + if (!std::isdigit(pData[iPosOff]) || !std::isdigit(pData[iPosOff + 1])) return false; strTemp[0] = pData[iPosOff]; @@ -1708,8 +1715,7 @@ bool CXFA_FM2JSContext::IsIsoDateFormat(const char* pData, if (iLength == 7) return true; } - if ((pData[iPosOff] > '9' || pData[iPosOff] < '0') || - (pData[iPosOff + 1] > '9' || pData[iPosOff + 1] < '0')) + if (!std::isdigit(pData[iPosOff]) || !std::isdigit(pData[iPosOff + 1])) return false; strTemp[0] = pData[iPosOff]; @@ -1759,7 +1765,7 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const char* pData, int32_t iZone = 0; int32_t i = 0; while (i < iLength) { - if ((pData[i] > '9' || pData[i] < '0') && pData[i] != ':') { + if (!std::isdigit(pData[i]) && pData[i] != ':') { iZone = i; break; } @@ -1774,11 +1780,11 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const char* pData, if (iIndex >= iZone) break; - if (pData[iIndex] > '9' || pData[iIndex] < '0') + if (!std::isdigit(pData[iIndex])) return false; strTemp[0] = pData[iIndex]; - if (pData[iIndex + 1] > '9' || pData[iIndex + 1] < '0') + if (!std::isdigit(pData[iIndex + 1])) return false; strTemp[1] = pData[iIndex + 1]; @@ -1814,15 +1820,15 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const char* pData, ++iIndex; char strSec[4]; strSec[3] = '\0'; - if (pData[iIndex] > '9' || pData[iIndex] < '0') + if (!std::isdigit(pData[iIndex])) return false; strSec[0] = pData[iIndex]; - if (pData[iIndex + 1] > '9' || pData[iIndex + 1] < '0') + if (!std::isdigit(pData[iIndex + 1])) return false; strSec[1] = pData[iIndex + 1]; - if (pData[iIndex + 2] > '9' || pData[iIndex + 2] < '0') + if (!std::isdigit(pData[iIndex + 2])) return false; strSec[2] = pData[iIndex + 2]; @@ -1847,11 +1853,11 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const char* pData, while (iIndex < iLength) { if (iIndex >= iLength) return false; - if (pData[iIndex] > '9' || pData[iIndex] < '0') + if (!std::isdigit(pData[iIndex])) return false; strTemp[0] = pData[iIndex]; - if (pData[iIndex + 1] > '9' || pData[iIndex + 1] < '0') + if (!std::isdigit(pData[iIndex + 1])) return false; strTemp[1] = pData[iIndex + 1]; @@ -2898,8 +2904,7 @@ void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, break; } eParserStatus = VALUETYPE_HAVEDIGITWHITE; - } else if ((typeChar >= '0' && typeChar <= '9') || typeChar == '-' || - typeChar == '.') { + } else if (IsPartOfNumberW(typeChar)) { if (eParserStatus == VALUETYPE_HAVEDIGITWHITE) { eParserStatus = VALUETYPE_ISIN; break; @@ -2910,8 +2915,7 @@ void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, if ((eParserStatus == VALUETYPE_START || eParserStatus == VALUETYPE_HAVEDIGIT || eParserStatus == VALUETYPE_HAVEDIGITWHITE) && - (nextChar > '9' || nextChar < '0') && nextChar != '.' && - nextChar != '-') { + !IsPartOfNumberW(nextChar)) { eParserStatus = (typeChar == 'c') ? VALUETYPE_ISCM : VALUETYPE_ISPT; break; } @@ -2921,8 +2925,7 @@ void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, if ((eParserStatus == VALUETYPE_START || eParserStatus == VALUETYPE_HAVEDIGIT || eParserStatus == VALUETYPE_HAVEDIGITWHITE) && - (nextChar > '9' || nextChar < '0') && nextChar != '.' && - nextChar != '-') { + !IsPartOfNumberW(nextChar)) { eParserStatus = VALUETYPE_ISMM; if (nextChar == 'p' || ((u + 5 < uLen) && pData[u + 1] == 'i' && pData[u + 2] == 'l' && pData[u + 3] == 'l' && @@ -2983,10 +2986,8 @@ void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, ++u; while (u < unitspanString.GetLength()) { - if ((pData[u] > '9' || pData[u] < '0') && pData[u] != '.' && - pData[u] != '-') { + if (!IsPartOfNumber(pData[u])) break; - } ++u; } @@ -3016,9 +3017,8 @@ void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, ++uVal; while (uVal < unitTempString.GetLength()) { - if ((pChar[uVal] > '9' || pChar[uVal] < '0') && pChar[uVal] != '.') { + if (!std::isdigit(pChar[uVal]) && pChar[uVal] != '.') break; - } ++uVal; } while (IsWhitespace(pChar[uVal])) diff --git a/xfa/fxfa/fm2js/xfa_lexer.cpp b/xfa/fxfa/fm2js/xfa_lexer.cpp index b646743d10..44fa5150dc 100644 --- a/xfa/fxfa/fm2js/xfa_lexer.cpp +++ b/xfa/fxfa/fm2js/xfa_lexer.cpp @@ -20,63 +20,31 @@ struct XFA_FMDChar { return p; } static uint16_t get(const wchar_t* p) { return *p; } - static bool isWhiteSpace(const wchar_t* p) { - return (*p) == 0x09 || (*p) == 0x0b || (*p) == 0x0c || (*p) == 0x20; - } - static bool isLineTerminator(const wchar_t* p) { - return *p == 0x0A || *p == 0x0D; - } - static bool isBinary(const wchar_t* p) { return (*p) >= '0' && (*p) <= '1'; } - static bool isOctal(const wchar_t* p) { return (*p) >= '0' && (*p) <= '7'; } - static bool isDigital(const wchar_t* p) { return (*p) >= '0' && (*p) <= '9'; } - static bool isHex(const wchar_t* p) { - return isDigital(p) || ((*p) >= 'a' && (*p) <= 'f') || - ((*p) >= 'A' && (*p) <= 'F'); - } - static bool isAlpha(const wchar_t* p) { - return ((*p) <= 'z' && (*p) >= 'a') || ((*p) <= 'Z' && (*p) >= 'A'); - } - static bool isAvalid(const wchar_t* p, bool flag = 0); - static bool string2number(const wchar_t* s, + static bool isValid(const wchar_t* p); + static void string2number(const wchar_t* s, double* pValue, const wchar_t*& pEnd); static bool isUnicodeAlpha(uint16_t ch); }; -inline bool XFA_FMDChar::isAvalid(const wchar_t* p, bool flag) { - if (*p == 0) { - return 1; - } - if ((*p <= 0x0A && *p >= 0x09) || *p == 0x0D || - (*p <= 0xd7ff && *p >= 0x20) || (*p <= 0xfffd && *p >= 0xe000)) { - return 1; - } - if (!flag) { - if (*p == 0x0B || *p == 0x0C) { - return 1; - } - } - return 0; +bool XFA_FMDChar::isValid(const wchar_t* p) { + return *p == 0 || (*p >= 0x09 && *p <= 0x0D) || + (*p >= 0x20 && *p <= 0xd7FF) || (*p >= 0xE000 && *p <= 0xFFFD); } -inline bool XFA_FMDChar::string2number(const wchar_t* s, - double* pValue, - const wchar_t*& pEnd) { +void XFA_FMDChar::string2number(const wchar_t* s, + double* pValue, + const wchar_t*& pEnd) { if (s) *pValue = wcstod(const_cast(s), const_cast(&pEnd)); - - return 0; } inline bool XFA_FMDChar::isUnicodeAlpha(uint16_t ch) { - if (ch == 0 || ch == 0x0A || ch == 0x0D || ch == 0x09 || ch == 0x0B || - ch == 0x0C || ch == 0x20 || ch == '.' || ch == ';' || ch == '"' || - ch == '=' || ch == '<' || ch == '>' || ch == ',' || ch == '(' || - ch == ')' || ch == ']' || ch == '[' || ch == '&' || ch == '|' || - ch == '+' || ch == '-' || ch == '*' || ch == '/') { - return false; - } - return true; + return !(ch == 0 || ch == 0x0A || ch == 0x0D || ch == 0x09 || ch == 0x0B || + ch == 0x0C || ch == 0x20 || ch == '.' || ch == ';' || ch == '"' || + ch == '=' || ch == '<' || ch == '>' || ch == ',' || ch == '(' || + ch == ')' || ch == ']' || ch == '[' || ch == '&' || ch == '|' || + ch == '+' || ch == '-' || ch == '*' || ch == '/'); } const XFA_FMKeyword keyWords[] = { @@ -171,14 +139,14 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() { CXFA_FMToken* CXFA_FMLexer::Scan() { uint16_t ch = 0; CXFA_FMToken* p = new CXFA_FMToken(m_uCurrentLine); - if (!XFA_FMDChar::isAvalid(m_ptr)) { + if (!XFA_FMDChar::isValid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); Error(kFMErrUnsupportedChar, ch); return p; } int iRet = 0; while (1) { - if (!XFA_FMDChar::isAvalid(m_ptr)) { + if (!XFA_FMDChar::isValid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); Error(kFMErrUnsupportedChar, ch); return p; @@ -200,14 +168,15 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { const wchar_t* pTemp = 0; Comment(m_ptr, pTemp); m_ptr = pTemp; - } break; + break; + } case '"': { const wchar_t* pTemp = 0; p->m_type = TOKstring; iRet = String(p, m_ptr, pTemp); m_ptr = pTemp; - } return p; + } case '0': case '1': case '2': @@ -222,70 +191,58 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { const wchar_t* pTemp = 0; iRet = Number(p, m_ptr, pTemp); m_ptr = pTemp; - if (iRet) { + if (iRet) Error(kFMErrBadSuffixNumber); - return p; - } - } return p; + } case '=': XFA_FMDChar::inc(m_ptr); - if (XFA_FMDChar::isAvalid(m_ptr)) { + if (XFA_FMDChar::isValid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); if (ch == '=') { p->m_type = TOKeq; XFA_FMDChar::inc(m_ptr); - return p; } else { p->m_type = TOKassign; - return p; } } else { ch = XFA_FMDChar::get(m_ptr); Error(kFMErrUnsupportedChar, ch); - return p; } - break; + return p; case '<': XFA_FMDChar::inc(m_ptr); - if (XFA_FMDChar::isAvalid(m_ptr)) { + if (XFA_FMDChar::isValid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); if (ch == '=') { p->m_type = TOKle; XFA_FMDChar::inc(m_ptr); - return p; } else if (ch == '>') { p->m_type = TOKne; XFA_FMDChar::inc(m_ptr); - return p; } else { p->m_type = TOKlt; - return p; } } else { ch = XFA_FMDChar::get(m_ptr); Error(kFMErrUnsupportedChar, ch); - return p; } - break; + return p; case '>': XFA_FMDChar::inc(m_ptr); - if (XFA_FMDChar::isAvalid(m_ptr)) { + if (XFA_FMDChar::isValid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); if (ch == '=') { p->m_type = TOKge; XFA_FMDChar::inc(m_ptr); - return p; } else { p->m_type = TOKgt; - return p; } } else { ch = XFA_FMDChar::get(m_ptr); Error(kFMErrUnsupportedChar, ch); - return p; } - break; + return p; case ',': p->m_type = TOKcomma; XFA_FMDChar::inc(m_ptr); @@ -326,60 +283,52 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { XFA_FMDChar::inc(m_ptr); p->m_type = TOKmul; return p; - case '/': + case '/': { XFA_FMDChar::inc(m_ptr); - if (XFA_FMDChar::isAvalid(m_ptr)) { - ch = XFA_FMDChar::get(m_ptr); - if (ch == '/') { - const wchar_t* pTemp = 0; - Comment(m_ptr, pTemp); - m_ptr = pTemp; - break; - } else { - p->m_type = TOKdiv; - return p; - } - } else { + if (!XFA_FMDChar::isValid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); Error(kFMErrUnsupportedChar, ch); return p; } + ch = XFA_FMDChar::get(m_ptr); + if (ch != '/') { + p->m_type = TOKdiv; + return p; + } + const wchar_t* pTemp = 0; + Comment(m_ptr, pTemp); + m_ptr = pTemp; break; + } case '.': XFA_FMDChar::inc(m_ptr); - if (XFA_FMDChar::isAvalid(m_ptr)) { + if (XFA_FMDChar::isValid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); if (ch == '.') { p->m_type = TOKdotdot; XFA_FMDChar::inc(m_ptr); - return p; } else if (ch == '*') { p->m_type = TOKdotstar; XFA_FMDChar::inc(m_ptr); - return p; } else if (ch == '#') { p->m_type = TOKdotscream; XFA_FMDChar::inc(m_ptr); - return p; } else if (ch <= '9' && ch >= '0') { p->m_type = TOKnumber; const wchar_t* pTemp = 0; XFA_FMDChar::dec(m_ptr); iRet = Number(p, m_ptr, pTemp); m_ptr = pTemp; - if (iRet) { + if (iRet) Error(kFMErrBadSuffixNumber); - } - return p; } else { p->m_type = TOKdot; - return p; } } else { ch = XFA_FMDChar::get(m_ptr); Error(kFMErrUnsupportedChar, ch); - return p; } + return p; case 0x09: case 0x0B: case 0x0C: @@ -390,12 +339,10 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { const wchar_t* pTemp = 0; iRet = Identifiers(p, m_ptr, pTemp); m_ptr = pTemp; - if (iRet) { - return p; - } - p->m_type = IsKeyword(p->m_wstring); - } + if (!iRet) + p->m_type = IsKeyword(p->m_wstring); return p; + } } } } @@ -404,9 +351,8 @@ uint32_t CXFA_FMLexer::Number(CXFA_FMToken* t, const wchar_t* p, const wchar_t*& pEnd) { double number = 0; - if (XFA_FMDChar::string2number(p, &number, pEnd)) - return 1; - if (pEnd && XFA_FMDChar::isAlpha(pEnd)) + XFA_FMDChar::string2number(p, &number, pEnd); + if (pEnd && FXSYS_iswalpha(*pEnd)) return 1; t->m_wstring = CFX_WideStringC(p, (pEnd - p)); @@ -421,30 +367,31 @@ uint32_t CXFA_FMLexer::String(CXFA_FMToken* t, XFA_FMDChar::inc(p); ch = XFA_FMDChar::get(p); while (ch) { - if (!XFA_FMDChar::isAvalid(p)) { + if (!XFA_FMDChar::isValid(p)) { ch = XFA_FMDChar::get(p); pEnd = p; t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart)); Error(kFMErrUnsupportedChar, ch); return 1; } - if (ch == '"') { + if (ch != '"') { XFA_FMDChar::inc(p); - if (!XFA_FMDChar::isAvalid(p)) { - ch = XFA_FMDChar::get(p); - pEnd = p; - t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart)); - Error(kFMErrUnsupportedChar, ch); - return 1; - } ch = XFA_FMDChar::get(p); - if (ch == '"') { - goto NEXT; - } else { - break; - } + continue; + } + + XFA_FMDChar::inc(p); + if (!XFA_FMDChar::isValid(p)) { + ch = XFA_FMDChar::get(p); + pEnd = p; + t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart)); + Error(kFMErrUnsupportedChar, ch); + return 1; } - NEXT: + ch = XFA_FMDChar::get(p); + if (ch != '"') + break; + XFA_FMDChar::inc(p); ch = XFA_FMDChar::get(p); } @@ -460,7 +407,7 @@ uint32_t CXFA_FMLexer::Identifiers(CXFA_FMToken* t, uint16_t ch = 0; ch = XFA_FMDChar::get(p); XFA_FMDChar::inc(p); - if (!XFA_FMDChar::isAvalid(p)) { + if (!XFA_FMDChar::isValid(p)) { pEnd = p; t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart)); Error(kFMErrUnsupportedChar, ch); @@ -468,20 +415,19 @@ uint32_t CXFA_FMLexer::Identifiers(CXFA_FMToken* t, } ch = XFA_FMDChar::get(p); while (ch) { - if (!XFA_FMDChar::isAvalid(p)) { + if (!XFA_FMDChar::isValid(p)) { pEnd = p; t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart)); Error(kFMErrUnsupportedChar, ch); return 1; } ch = XFA_FMDChar::get(p); - if (XFA_FMDChar::isUnicodeAlpha(ch)) { - XFA_FMDChar::inc(p); - } else { + if (!XFA_FMDChar::isUnicodeAlpha(ch)) { pEnd = p; t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart)); return 0; } + XFA_FMDChar::inc(p); } pEnd = p; t->m_wstring = CFX_WideStringC(pStart, (pEnd - pStart)); @@ -536,8 +482,5 @@ void CXFA_FMLexer::Error(const wchar_t* msg, ...) { } bool CXFA_FMLexer::HasError() const { - if (m_pErrorInfo->message.IsEmpty()) { - return false; - } - return true; + return !m_pErrorInfo->message.IsEmpty(); } diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index 361c48a6bc..f11a668276 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -51,24 +51,12 @@ bool SplitDateTime(const CFX_WideString& wsDateTime, wsDate = wsDateTime.Left(nSplitIndex); if (!wsDate.IsEmpty()) { - int32_t iCount = wsDate.GetLength(); - int32_t i = 0; - for (i = 0; i < iCount; i++) { - if (wsDate[i] >= '0' && wsDate[i] <= '9') - break; - } - if (i == iCount) + if (!std::any_of(wsDate.begin(), wsDate.end(), std::iswdigit)) return false; } wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); if (!wsTime.IsEmpty()) { - int32_t iCount = wsTime.GetLength(); - int32_t i = 0; - for (i = 0; i < iCount; i++) { - if (wsTime[i] >= '0' && wsTime[i] <= '9') - break; - } - if (i == iCount) + if (!std::any_of(wsTime.begin(), wsTime.end(), std::iswdigit)) return false; } return true; -- cgit v1.2.3