Parser::extractCommand: parse with string_view instead of regex to avoid inconsistent behavior in libcs
This commit is contained in:
parent
0bd12d1684
commit
9abfa1f2b7
19
parser.cpp
19
parser.cpp
@ -66,16 +66,19 @@ std::vector<std::string> Parser::extractCategories(std::string content) const
|
|||||||
|
|
||||||
std::string Parser::extractCommand(std::string cmdname, 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::string cmd = "[cmd:" + cmdname + "]";
|
||||||
std::regex reg { regstr };
|
std::string cmdend = "[/cmd:" + cmdname + "]";
|
||||||
std::smatch match;
|
|
||||||
if(std::regex_match(content, match, reg))
|
|
||||||
{
|
|
||||||
|
|
||||||
if(match.size() > 1)
|
std::string_view view = content;
|
||||||
|
size_t pos = 0;
|
||||||
|
if((pos = view.find(cmd)) != std::string::npos)
|
||||||
{
|
{
|
||||||
return match.str(2);
|
view.remove_prefix(pos);
|
||||||
|
view.remove_prefix(cmd.size());
|
||||||
|
if((pos = view.find(cmdend)) != std::string::npos)
|
||||||
|
{
|
||||||
|
auto result = view.substr(0, pos);
|
||||||
|
return std::string { result };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
Loading…
Reference in New Issue
Block a user