Lexer: Added ::wasQuoted to determine original quote state

This commit is contained in:
Paul Beckingham 2015-06-28 12:35:06 -04:00
parent ba65fa67b1
commit 86ed232348
3 changed files with 30 additions and 14 deletions

View file

@ -324,6 +324,15 @@ void Lexer::dequote (std::string& input)
} }
} }
////////////////////////////////////////////////////////////////////////////////
bool Lexer::wasQuoted (const std::string& input)
{
if (input.find_first_of (" \t()") != std::string::npos)
return true;
return false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Lexer::isEOS () const bool Lexer::isEOS () const
{ {

View file

@ -75,6 +75,7 @@ public:
static bool isBoundary (int, int); static bool isBoundary (int, int);
static bool isPunctuation (int); static bool isPunctuation (int);
static void dequote (std::string&); static void dequote (std::string&);
static bool wasQuoted (const std::string&);
// Helpers. // Helpers.
bool isEOS () const; bool isEOS () const;

View file

@ -36,7 +36,7 @@ Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (795); UnitTest t (799);
std::vector <std::pair <std::string, Lexer::Type>> tokens; std::vector <std::pair <std::string, Lexer::Type>> tokens;
std::string token; std::string token;
@ -71,7 +71,7 @@ int main (int argc, char** argv)
t.ok (Lexer::isWhitespace (0x205F), "U+205F isWhitespace"); t.ok (Lexer::isWhitespace (0x205F), "U+205F isWhitespace");
t.ok (Lexer::isWhitespace (0x3000), "U+3000 isWhitespace"); t.ok (Lexer::isWhitespace (0x3000), "U+3000 isWhitespace");
// static bool Lexer::isBoundary(int, int); // static bool Lexer::isBoundary (int, int);
t.ok (Lexer::isBoundary (' ', 'a'), "' ' --> 'a' = isBoundary"); t.ok (Lexer::isBoundary (' ', 'a'), "' ' --> 'a' = isBoundary");
t.ok (Lexer::isBoundary ('a', ' '), "'a' --> ' ' = isBoundary"); t.ok (Lexer::isBoundary ('a', ' '), "'a' --> ' ' = isBoundary");
t.ok (Lexer::isBoundary (' ', '+'), "' ' --> '+' = isBoundary"); t.ok (Lexer::isBoundary (' ', '+'), "' ' --> '+' = isBoundary");
@ -80,6 +80,12 @@ int main (int argc, char** argv)
t.ok (Lexer::isBoundary ('(', '('), "'(' --> '(' = isBoundary"); t.ok (Lexer::isBoundary ('(', '('), "'(' --> '(' = isBoundary");
t.notok (Lexer::isBoundary ('r', 'd'), "'r' --> 'd' = isBoundary"); t.notok (Lexer::isBoundary ('r', 'd'), "'r' --> 'd' = isBoundary");
// static bool Lexer::wasQuoted (const std::string&);
t.notok (Lexer::wasQuoted (""), "'' --> !wasQuoted");
t.notok (Lexer::wasQuoted ("foo"), "'foo' --> !wasQuoted");
t.ok (Lexer::wasQuoted ("a b"), "'a b' --> wasQuoted");
t.ok (Lexer::wasQuoted ("(a)"), "'(a)' --> wasQuoted");
// Should result in no tokens. // Should result in no tokens.
Lexer l0 (""); Lexer l0 ("");
t.notok (l0.token (token, type), "'' --> no tokens"); t.notok (l0.token (token, type), "'' --> no tokens");