mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Lexer: Added ::wasQuoted to determine original quote state
This commit is contained in:
parent
ba65fa67b1
commit
86ed232348
3 changed files with 30 additions and 14 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
static bool isBoundary (int, int);
|
||||
static bool isPunctuation (int);
|
||||
static void dequote (std::string&);
|
||||
static bool wasQuoted (const std::string&);
|
||||
|
||||
// Helpers.
|
||||
bool isEOS () const;
|
||||
|
|
|
@ -36,7 +36,7 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (795);
|
||||
UnitTest t (799);
|
||||
|
||||
std::vector <std::pair <std::string, Lexer::Type>> tokens;
|
||||
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 (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 (' ', '+'), "' ' --> '+' = isBoundary");
|
||||
|
@ -80,6 +80,12 @@ int main (int argc, char** argv)
|
|||
t.ok (Lexer::isBoundary ('(', '('), "'(' --> '(' = 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.
|
||||
Lexer l0 ("");
|
||||
t.notok (l0.token (token, type), "'' --> no tokens");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue