From 36c18c872addaa2d5cc36d1b218f8d2dc22a38be Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 7 Feb 2017 11:47:24 -0500 Subject: Add CFDE_CSSValueListParser tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl adds some unit tests for the CFDE_CSSValueListParser prior to refactoring. Change-Id: I2b32775ea1e70b721f5902cd3d88d68a01166d5e Reviewed-on: https://pdfium-review.googlesource.com/2535 Reviewed-by: Tom Sepez Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- xfa/fde/css/cfde_cssvaluelistparser.cpp | 100 +++++++++++--------------------- 1 file changed, 35 insertions(+), 65 deletions(-) (limited to 'xfa/fde/css/cfde_cssvaluelistparser.cpp') 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; } -- cgit v1.2.3