Lexer:: Added polymorphic ::readWord for quoteѕ and unquoted strings

This commit is contained in:
Paul Beckingham 2015-07-06 16:37:03 -04:00
parent abaf326855
commit 7a6d546a0d
3 changed files with 80 additions and 15 deletions

View file

@ -214,33 +214,34 @@ int main (int argc, char** argv)
// static bool readWord (const std::string&, const std::string&, std::string::size_type&, std::string&);
std::string::size_type cursor = 0;
std::string word;
t.ok (Lexer::readWord ("input", "'\"", cursor, word), "readWord 'input' --> true");
t.is (word, "input", " word '" + word + "'");
t.is ((int)cursor, 5, " cursor");
cursor = 0;
t.ok (Lexer::readWord ("'one two'", "'\"", cursor, word), "readWord ''one two'' --> true");
t.is (word, "one two", " word '" + word + "'");
t.is ((int)cursor, 9, " cursor");
// static bool readWord (const std::string&, std::string::size_type&, std::string&);
cursor = 0;
t.ok (Lexer::readWord ("one\\ two", "'\"", cursor, word), "readWord 'one\\ two' --> true");
t.ok (Lexer::readWord ("input", cursor, word), "readWord 'input' --> true");
t.is (word, "input", " word '" + word + "'");
t.is ((int)cursor, 5, " cursor");
cursor = 0;
t.ok (Lexer::readWord ("one\\ two", cursor, word), "readWord 'one\\ two' --> true");
t.is (word, "one two", " word '" + word + "'");
t.is ((int)cursor, 8, " cursor");
cursor = 0;
t.ok (Lexer::readWord ("\\u20A43", "'\"", cursor, word), "readWord '\\u20A43' --> true");
t.ok (Lexer::readWord ("\\u20A43", cursor, word), "readWord '\\u20A43' --> true");
t.is (word, "₤3", " word '" + word + "'");
t.is ((int)cursor, 7, " cursor");
cursor = 0;
t.ok (Lexer::readWord ("U+20AC4", "'\"", cursor, word), "readWord '\\u20AC4' --> true");
t.ok (Lexer::readWord ("U+20AC4", cursor, word), "readWord '\\u20AC4' --> true");
t.is (word, "€4", " word '" + word + "'");
t.is ((int)cursor, 7, " cursor");
std::string text = "one 'two' three\\ four";
cursor = 0;
while (Lexer::readWord (text, "'\"", cursor, word))
while (Lexer::readWord (text, cursor, word))
{
t.diag ("'" + word + "'");
while (Lexer::isWhitespace(text[cursor]))