summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_cssvaluelistparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fde/css/cfde_cssvaluelistparser.cpp')
-rw-r--r--xfa/fde/css/cfde_cssvaluelistparser.cpp100
1 files changed, 35 insertions, 65 deletions
diff --git a/xfa/fde/css/cfde_cssvaluelistparser.cpp b/xfa/fde/css/cfde_cssvaluelistparser.cpp
index 3c204b0d2b..42c3296865 100644
--- a/xfa/fde/css/cfde_cssvaluelistparser.cpp
+++ b/xfa/fde/css/cfde_cssvaluelistparser.cpp
@@ -16,50 +16,36 @@ CFDE_CSSValueListParser::CFDE_CSSValueListParser(const FX_WCHAR* psz,
bool CFDE_CSSValueListParser::NextValue(FDE_CSSPrimitiveType& eType,
const FX_WCHAR*& pStart,
int32_t& iLength) {
- while (m_pCur < m_pEnd && (*m_pCur <= ' ' || *m_pCur == m_Separator)) {
+ while (m_pCur < m_pEnd && (*m_pCur <= ' ' || *m_pCur == m_Separator))
++m_pCur;
- }
- if (m_pCur >= m_pEnd) {
+
+ if (m_pCur >= m_pEnd)
return false;
- }
+
eType = FDE_CSSPrimitiveType::Unknown;
pStart = m_pCur;
iLength = 0;
FX_WCHAR wch = *m_pCur;
if (wch == '#') {
- iLength = SkipTo(' ');
- if (iLength == 4 || iLength == 7) {
+ iLength = SkipTo(' ', false, false);
+ if (iLength == 4 || iLength == 7)
eType = FDE_CSSPrimitiveType::RGB;
- }
} else if ((wch >= '0' && wch <= '9') || wch == '.' || wch == '-' ||
wch == '+') {
- while (m_pCur < m_pEnd && (*m_pCur > ' ' && *m_pCur != m_Separator)) {
+ while (m_pCur < m_pEnd && (*m_pCur > ' ' && *m_pCur != m_Separator))
++m_pCur;
- }
+
iLength = m_pCur - pStart;
- if (iLength > 0) {
- eType = FDE_CSSPrimitiveType::Number;
- }
+ eType = FDE_CSSPrimitiveType::Number;
} else if (wch == '\"' || wch == '\'') {
pStart++;
- iLength = SkipTo(wch) - 1;
+ m_pCur++;
+ iLength = SkipTo(wch, false, false);
m_pCur++;
eType = FDE_CSSPrimitiveType::String;
} else if (m_pEnd - m_pCur > 5 && m_pCur[3] == '(') {
- if (FXSYS_wcsnicmp(L"url", m_pCur, 3) == 0) {
- wch = m_pCur[4];
- if (wch == '\"' || wch == '\'') {
- pStart += 5;
- iLength = SkipTo(wch) - 6;
- m_pCur += 2;
- } else {
- pStart += 4;
- iLength = SkipTo(')') - 4;
- m_pCur++;
- }
- eType = FDE_CSSPrimitiveType::String;
- } else if (FXSYS_wcsnicmp(L"rgb", m_pCur, 3) == 0) {
- iLength = SkipTo(')') + 1;
+ if (FXSYS_wcsnicmp(L"rgb", m_pCur, 3) == 0) {
+ iLength = SkipTo(')', false, false) + 1;
m_pCur++;
eType = FDE_CSSPrimitiveType::RGB;
}
@@ -69,48 +55,32 @@ bool CFDE_CSSValueListParser::NextValue(FDE_CSSPrimitiveType& eType,
}
return m_pCur <= m_pEnd && iLength > 0;
}
+
int32_t CFDE_CSSValueListParser::SkipTo(FX_WCHAR wch,
- bool bWSSeparator,
- bool bBrContinue) {
+ bool breakOnSpace,
+ bool matchBrackets) {
const FX_WCHAR* pStart = m_pCur;
- if (!bBrContinue) {
- if (bWSSeparator) {
- while ((++m_pCur < m_pEnd) && (*m_pCur != wch) && (*m_pCur > ' ')) {
- continue;
- }
- } else {
- while (++m_pCur < m_pEnd && *m_pCur != wch) {
- continue;
- }
- }
-
- } else {
- int32_t iBracketCount = 0;
- if (bWSSeparator) {
- while ((m_pCur < m_pEnd) && (*m_pCur != wch) && (*m_pCur > ' ')) {
- if (*m_pCur == '(') {
- iBracketCount++;
- } else if (*m_pCur == ')') {
- iBracketCount--;
- }
- m_pCur++;
- }
- } else {
- while (m_pCur < m_pEnd && *m_pCur != wch) {
- if (*m_pCur == '(') {
- iBracketCount++;
- } else if (*m_pCur == ')') {
- iBracketCount--;
- }
- m_pCur++;
- }
- }
- while (iBracketCount > 0 && m_pCur < m_pEnd) {
- if (*m_pCur == ')') {
- iBracketCount--;
- }
+ int32_t bracketCount = 0;
+ while (m_pCur < m_pEnd && *m_pCur != wch) {
+ if (breakOnSpace && *m_pCur <= ' ')
+ break;
+ if (!matchBrackets) {
m_pCur++;
+ continue;
}
+
+ if (*m_pCur == '(')
+ bracketCount++;
+ else if (*m_pCur == ')')
+ bracketCount--;
+
+ m_pCur++;
+ }
+
+ while (bracketCount > 0 && m_pCur < m_pEnd) {
+ if (*m_pCur == ')')
+ bracketCount--;
+ m_pCur++;
}
return m_pCur - pStart;
}