From 8b159d722556a895c132b574dac0fa8e61cab971 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 6 Jan 2016 10:43:26 -0500 Subject: [PATCH] Lexer: Added ::dequote --- src/Lexer.cpp | 19 +++++++++++++++++++ src/Lexer.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index d28807cc..1d96e11b 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -329,6 +329,25 @@ bool Lexer::isPunctuation (int 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 { diff --git a/src/Lexer.h b/src/Lexer.h index ea122c2a..2504862e 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -67,6 +67,7 @@ public: 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 trim (const std::string& in, const std::string& t = " "); + static std::string dequote (const std::string&, const std::string& quotes = "'\""); // Stream Classifiers. bool isEOS () const;