From 8318658ccc9b1afd4472f136c7172b1568d12ab8 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 27 Jul 2017 14:30:07 -0400 Subject: Refactor whitespace lexing to be explicit Removed 'case 0xf00:' to either be the character being checked or moved to a IsWhitespaceCharacter() check. BUG=pdfium:815 Change-Id: I34727a00f6d54ecf8de2f9e4eb785b3c10b6c521 Reviewed-on: https://pdfium-review.googlesource.com/9310 Reviewed-by: (OOO Jul 28 - Aug 8) dsinclair Reviewed-by: Tom Sepez Commit-Queue: Ryan Harrison --- xfa/fxfa/fm2js/cxfa_fmlexer.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'xfa/fxfa/fm2js') diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp index d217587e66..5e5761702b 100644 --- a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp @@ -30,6 +30,13 @@ bool IsInitialIdentifierCharacter(wchar_t c) { c == 0x0021; // '!' } +bool IsWhitespaceCharacter(wchar_t c) { + return c == 0x0009 || // Horizontal tab + c == 0x000B || // Vertical tab + c == 0x000C || // Form feed + c == 0x0020; // Space +} + const XFA_FMKeyword keyWords[] = { {TOKand, 0x00000026, L"&"}, {TOKlparen, 0x00000028, L"("}, @@ -168,23 +175,21 @@ std::unique_ptr CXFA_FMLexer::NextToken() { } switch (*m_cursor) { - case 0x0A: + case '\n': ++m_current_line; m_token->m_line_num = m_current_line; ++m_cursor; break; - case 0x0D: + case '\r': ++m_cursor; break; - case ';': { + case ';': AdvanceForComment(); break; - } - case '"': { + case '"': m_token->m_type = TOKstring; AdvanceForString(); return std::move(m_token); - } case '0': case '1': case '2': @@ -194,11 +199,10 @@ std::unique_ptr CXFA_FMLexer::NextToken() { case '6': case '7': case '8': - case '9': { + case '9': m_token->m_type = TOKnumber; AdvanceForNumber(); return std::move(m_token); - } case '=': ++m_cursor; if (m_cursor > m_end) { @@ -343,20 +347,17 @@ std::unique_ptr CXFA_FMLexer::NextToken() { m_token->m_type = TOKdot; } return std::move(m_token); - case 0x09: - case 0x0B: - case 0x0C: - case 0x20: - ++m_cursor; - break; - default: { + default: + if (IsWhitespaceCharacter(*m_cursor)) { + ++m_cursor; + break; + } if (!IsInitialIdentifierCharacter(*m_cursor)) { RaiseError(); return nullptr; } AdvanceForIdentifier(); return std::move(m_token); - } } } -- cgit v1.2.3