diff --git a/src/CLI.cpp b/src/CLI.cpp index 5177a0e7c..eb59cbd44 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1638,7 +1639,7 @@ void CLI::desugarFilterPlainArgs () reconstructed.push_back (op); std::string pattern = a->attribute ("raw"); - Lexer::dequote (pattern); + Lexer2::dequote (pattern); A rhs ("argPattern", "'" + pattern + "'"); rhs.tag ("LITERAL"); rhs.tag ("FILTER"); diff --git a/src/Lexer2.cpp b/src/Lexer2.cpp index b4c5a392b..142f96008 100644 --- a/src/Lexer2.cpp +++ b/src/Lexer2.cpp @@ -237,6 +237,18 @@ bool Lexer2::isPunctuation (int c) ispunct (c); } +//////////////////////////////////////////////////////////////////////////////// +void Lexer2::dequote (std::string& input) +{ + int quote = input[0]; + size_t len = input.length (); + if ((quote == '\'' || quote == '"') && + quote == input[len - 1]) + { + input = input.substr (1, len - 2); + } +} + //////////////////////////////////////////////////////////////////////////////// bool Lexer2::isEOS () const { diff --git a/src/Lexer2.h b/src/Lexer2.h index cc12c6daf..0a9363116 100644 --- a/src/Lexer2.h +++ b/src/Lexer2.h @@ -62,6 +62,7 @@ public: static bool isTripleCharOperator (int, int, int, int); static bool isBoundary (int, int); static bool isPunctuation (int); + static void dequote (std::string&); // Helpers. bool isEOS () const; diff --git a/src/Variant.cpp b/src/Variant.cpp index d26aafe87..f12519ad1 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -196,10 +196,10 @@ bool Variant::operator&& (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); left.cast (type_boolean); right.cast (type_boolean); @@ -214,10 +214,10 @@ bool Variant::operator|| (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); left.cast (type_boolean); right.cast (type_boolean); @@ -232,10 +232,10 @@ bool Variant::operator_xor (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); left.cast (type_boolean); right.cast (type_boolean); @@ -251,10 +251,10 @@ bool Variant::operator< (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (left._type) { @@ -396,10 +396,10 @@ bool Variant::operator<= (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (left._type) { @@ -542,10 +542,10 @@ bool Variant::operator> (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (left._type) { @@ -686,10 +686,10 @@ bool Variant::operator>= (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (left._type) { @@ -832,10 +832,10 @@ bool Variant::operator== (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (left._type) { @@ -962,16 +962,16 @@ bool Variant::operator_match (const Variant& other, const Task& task) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); left.cast (type_string); right.cast (type_string); std::string pattern = right._string; - Lexer::dequote (pattern); + Lexer2::dequote (pattern); if (searchUsingRegex) { @@ -1032,10 +1032,10 @@ bool Variant::operator_partial (const Variant& other) const Variant right (other); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (left._type) { @@ -1220,7 +1220,7 @@ bool Variant::operator_hastag (const Variant& other, const Task& task) const { Variant right (other); right.cast (type_string); - Lexer::dequote (right._string); + Lexer2::dequote (right._string); return task.hasTag (right._string); } @@ -1236,7 +1236,7 @@ bool Variant::operator! () const Variant left (*this); if (left._type == type_string) - Lexer::dequote (left._string); + Lexer2::dequote (left._string); left.cast (type_boolean); return ! left._bool; @@ -1401,7 +1401,7 @@ Variant& Variant::operator+= (const Variant& other) Variant right (other); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (_type) { @@ -1513,7 +1513,7 @@ Variant& Variant::operator*= (const Variant& other) Variant right (other); if (right._type == type_string) - Lexer::dequote (right._string); + Lexer2::dequote (right._string); switch (_type) { @@ -1970,7 +1970,7 @@ Variant::operator std::string () const void Variant::sqrt () { if (_type == type_string) - Lexer::dequote (_string); + Lexer2::dequote (_string); cast (type_real); if (_real < 0.0) @@ -2046,7 +2046,7 @@ void Variant::cast (const enum type new_type) break; case type_string: - Lexer::dequote (_string); + Lexer2::dequote (_string); switch (new_type) { case type_unknown: break;