diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 338f12b5e..28dbb5d6e 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -324,14 +324,14 @@ bool Lexer::isPunctuation (int c) } //////////////////////////////////////////////////////////////////////////////// -void Lexer::dequote (std::string& input) +void Lexer::dequote (std::string& input, const std::string& quotes) { int quote = input[0]; - size_t len = input.length (); - if ((quote == '\'' || quote == '"') && - quote == input[len - 1]) + if (quotes.find (quote) != std::string::npos) { - input = input.substr (1, len - 2); + size_t len = input.length (); + if (input[0] == input[len - 1]) + input = input.substr (1, len - 2); } } @@ -1403,3 +1403,37 @@ bool Lexer::decomposePair ( } //////////////////////////////////////////////////////////////////////////////// +// / / / [] +bool Lexer::decomposeSubstitution ( + const std::string& text, + std::string& from, + std::string& to, + std::string& flags) +{ + std::string parsed_from; + std::string::size_type cursor = 0; + if (readWord (text, "/", cursor, parsed_from) && + parsed_from.length ()) + { + --cursor; + std::string parsed_to; + if (readWord (text, "/", cursor, parsed_to)) + { + std::string parsed_flags = text.substr (cursor); + if (parsed_flags.find ("/") == std::string::npos) + { + dequote (parsed_from, "/"); + dequote (parsed_to, "/"); + + from = parsed_from; + to = parsed_to; + flags = parsed_flags; + return true; + } + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Lexer.h b/src/Lexer.h index 7f96bda00..81e422101 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -74,11 +74,12 @@ public: static bool isPunctuation (int); static bool isAllDigits (const std::string&); static bool isOneWord (const std::string&); - static void dequote (std::string&); + static void dequote (std::string&, const std::string& quotes = "'\""); static bool wasQuoted (const std::string&); static bool readWord (const std::string&, const std::string&, std::string::size_type&, std::string&); static bool readWord (const std::string&, std::string::size_type&, std::string&); static bool decomposePair (const std::string&, std::string&, std::string&, std::string&, std::string&); + static bool decomposeSubstitution (const std::string&, std::string&, std::string&, std::string&); static int hexToInt (int); static int hexToInt (int, int); static int hexToInt (int, int, int, int);