From d0e4f4ca10626fd1e9d57fa55a0aae0c890a71ac Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 11 Jul 2015 17:09:29 -0400 Subject: [PATCH] Lexer: Implemented ::decomposePattern --- src/Lexer.cpp | 26 ++++++++++++++++++++++++++ src/Lexer.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 28dbb5d6e..27e18255d 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -1437,3 +1437,29 @@ bool Lexer::decomposeSubstitution ( } //////////////////////////////////////////////////////////////////////////////// +// / / [] +bool Lexer::decomposePattern ( + const std::string& text, + std::string& pattern, + std::string& flags) +{ + std::string parsed_pattern; + std::string::size_type cursor = 0; + if (readWord (text, "/", cursor, parsed_pattern) && + parsed_pattern.length ()) + { + std::string parsed_flags = text.substr (cursor); + if (parsed_flags.find ("/") == std::string::npos) + { + dequote (parsed_pattern, "/"); + + pattern = parsed_pattern; + flags = parsed_flags; + return true; + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Lexer.h b/src/Lexer.h index 81e422101..00fec62cb 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -80,6 +80,7 @@ public: 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 bool decomposePattern (const std::string&, std::string&, std::string&); static int hexToInt (int); static int hexToInt (int, int); static int hexToInt (int, int, int, int);