summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-04-24 16:16:49 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-25 13:11:17 +0000
commitab1faaa7f81b7dafe03d546341c6a643a58b3678 (patch)
tree76278cedc2e5787b4a5b814cf1150efe3038c435 /xfa/fxfa/fm2js
parentef002c85521278e3082517297cf60372d7751cb1 (diff)
downloadpdfium-ab1faaa7f81b7dafe03d546341c6a643a58b3678.tar.xz
Use fx_extension.h utilities in more places in xfa/
Change-Id: Id58c313aa446ecfa223e5c8edc095586b62a61fa Reviewed-on: https://pdfium-review.googlesource.com/4455 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js')
-rw-r--r--xfa/fxfa/fm2js/xfa_fm2jscontext.cpp48
-rw-r--r--xfa/fxfa/fm2js/xfa_lexer.cpp189
2 files changed, 90 insertions, 147 deletions
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<wchar_t*>(s), const_cast<wchar_t**>(&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();
}