From da2a5b10fe1ceb6a7228b0630b0ca5bb0a5febf4 Mon Sep 17 00:00:00 2001 From: Albert S Date: Mon, 5 Nov 2018 22:36:18 +0100 Subject: [PATCH] Parser::extractCommand: parse with string_view instead of regex to avoid inconsistent behavior in libcs --- parser.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/parser.cpp b/parser.cpp index a3e9849..bf99445 100644 --- a/parser.cpp +++ b/parser.cpp @@ -65,15 +65,19 @@ std::vector Parser::extractCategories(std::string content) const std::string Parser::extractCommand(std::string cmdname, std::string content) const { - std::string regstr = "(\\s|\\S)*\\[cmd\\:" + cmdname + "\\](.*?)\\[/cmd\\:" + cmdname + "\\](\\s|\\S)*"; - std::regex reg{regstr}; - std::smatch match; - if(std::regex_match(content, match, reg)) - { + std::string cmd = "[cmd:" + cmdname + "]"; + std::string cmdend = "[/cmd:" + cmdname + "]"; - if(match.size() > 1) + std::string_view view = content; + size_t pos = 0; + if((pos = view.find(cmd)) != std::string::npos) + { + view.remove_prefix(pos); + view.remove_prefix(cmd.size()); + if((pos = view.find(cmdend)) != std::string::npos) { - return match.str(2); + auto result = view.substr(0, pos); + return std::string{result}; } } return "";