Added basic inline command parser

This commit is contained in:
Bartek Kryza
2021-07-28 23:10:46 +02:00
parent e7f9674433
commit 4cdd034017
7 changed files with 376 additions and 0 deletions

View File

@@ -126,5 +126,20 @@ bool find_element_alias(
return true;
}
bool replace_all(
std::string &input, std::string pattern, std::string replace_with)
{
bool replaced{false};
auto pos = input.find(pattern);
while (pos < input.size()) {
input.replace(pos, pattern.size(), replace_with);
pos = input.find(pattern, pos + replace_with.size());
replaced = true;
}
return replaced;
}
}
}

View File

@@ -104,5 +104,15 @@ std::string unqualify(const std::string &s);
*/
bool find_element_alias(
const std::string &input, std::tuple<std::string, size_t, size_t> &result);
/**
* @brief Find and replace in string
*
* Replaces all occurences of pattern with replace_with in input string.
*
* @return True if at least on replacement was made
*/
bool replace_all(
std::string &input, std::string pattern, std::string replace_with);
}
}