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
|
bool Lexer::isEOS () const
|
||||||
{
|
{
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue