Lexer: ::readWord now skips leading whiteSpace

This commit is contained in:
Paul Beckingham 2015-07-08 11:24:46 -04:00
parent 6c56f4b695
commit e55528e21e
2 changed files with 11 additions and 4 deletions

View file

@ -1324,16 +1324,18 @@ bool Lexer::readWord (
{ {
std::string::size_type eos = text.length (); std::string::size_type eos = text.length ();
// Skip initial whitespace.
while (cursor <= eos &&
Lexer::isWhitespace(text[cursor]))
++cursor;
word = ""; word = "";
int c; int c;
while ((c = text[cursor])) while ((c = text[cursor]))
{ {
// Unquoted word ends on white space. // Unquoted word ends on white space.
if (Lexer::isWhitespace (c)) if (Lexer::isWhitespace (c))
{
++cursor;
break; break;
}
// Unicode U+XXXX or \uXXXX codepoint. // Unicode U+XXXX or \uXXXX codepoint.
else if (eos - cursor >= 6 && else if (eos - cursor >= 6 &&

View file

@ -37,7 +37,7 @@ Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (1067); UnitTest t (1069);
std::vector <std::pair <std::string, Lexer::Type>> tokens; std::vector <std::pair <std::string, Lexer::Type>> tokens;
std::string token; 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.ok (Lexer::readWord (text, cursor, word), "readWord \"one 'two' three\\ four\" --> true");
t.is (word, "three four", " word '" + word + "'"); 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. // Test all Lexer types.
#define NO {"",Lexer::Type::word} #define NO {"",Lexer::Type::word}
struct struct