From e55528e21efdcbdf3342cfe5f838798235346c7e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 8 Jul 2015 11:24:46 -0400 Subject: [PATCH] Lexer: ::readWord now skips leading whiteSpace --- src/Lexer.cpp | 8 +++++--- test/lexer.t.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 60c46f6f2..050c9763b 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -1324,16 +1324,18 @@ bool Lexer::readWord ( { std::string::size_type eos = text.length (); + // Skip initial whitespace. + while (cursor <= eos && + Lexer::isWhitespace(text[cursor])) + ++cursor; + word = ""; int c; while ((c = text[cursor])) { // Unquoted word ends on white space. if (Lexer::isWhitespace (c)) - { - ++cursor; break; - } // Unicode U+XXXX or \uXXXX codepoint. else if (eos - cursor >= 6 && diff --git a/test/lexer.t.cpp b/test/lexer.t.cpp index 47e77db64..0cce6be62 100644 --- a/test/lexer.t.cpp +++ b/test/lexer.t.cpp @@ -37,7 +37,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (1067); + UnitTest t (1069); std::vector > tokens; std::string token; @@ -248,6 +248,11 @@ int main (int argc, char** argv) t.ok (Lexer::readWord (text, cursor, word), "readWord \"one 'two' three\\ four\" --> true"); t.is (word, "three four", " word '" + word + "'"); + text = "one "; + cursor = 0; + t.ok (Lexer::readWord (text, cursor, word), "readWord \"one \" --> true"); + t.is (word, "one", " word '" + word + "'"); + // Test all Lexer types. #define NO {"",Lexer::Type::word} struct