Lexer: Added ::dequote

This commit is contained in:
Paul Beckingham 2016-01-06 10:43:26 -05:00
parent a2e45b9297
commit 8b159d7225
2 changed files with 20 additions and 0 deletions

View file

@ -329,6 +329,25 @@ bool Lexer::isPunctuation (int c)
! isAlpha (c); ! isAlpha (c);
} }
////////////////////////////////////////////////////////////////////////////////
// Assumes that quotes is a string containing a non-trivial set of quote
// characters.
std::string Lexer::dequote (const std::string& input, const std::string& quotes)
{
if (input.length ())
{
int quote = input[0];
if (quotes.find (quote) != std::string::npos)
{
size_t len = input.length ();
if (quote == input[len - 1])
return input.substr (1, len - 2);
}
}
return input;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Lexer::isEOS () const bool Lexer::isEOS () const
{ {

View file

@ -67,6 +67,7 @@ public:
static std::string trimLeft (const std::string& in, const std::string& t = " "); static std::string trimLeft (const std::string& in, const std::string& t = " ");
static std::string trimRight (const std::string& in, const std::string& t = " "); static std::string trimRight (const std::string& in, const std::string& t = " ");
static std::string trim (const std::string& in, const std::string& t = " "); static std::string trim (const std::string& in, const std::string& t = " ");
static std::string dequote (const std::string&, const std::string& quotes = "'\"");
// Stream Classifiers. // Stream Classifiers.
bool isEOS () const; bool isEOS () const;