diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-07-27 14:30:07 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-27 18:55:40 +0000 |
commit | 8318658ccc9b1afd4472f136c7172b1568d12ab8 (patch) | |
tree | ec89982512d47dccc0c6482037a2e69c8f460595 | |
parent | 7314af7d04d3fd4f29fff1f0da648944183bd0d0 (diff) | |
download | pdfium-8318658ccc9b1afd4472f136c7172b1568d12ab8.tar.xz |
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 <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmlexer.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
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_FMToken> 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_FMToken> 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_FMToken> 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); - } } } |