diff options
Diffstat (limited to 'src/utils/stringutils.h')
-rw-r--r-- | src/utils/stringutils.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 1fa8e1e6..885ddcb8 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -107,19 +107,28 @@ std::string &replaceCharacters(std::string &str, char replacement = '_'); /** - * Removes colors from a string + * Removes colors from a string. * * @param msg the string to remove the colors from - * @return string without colors + * @return reference to the modified string */ -std::string removeColors(std::string msg); +std::string &removeColors(std::string &msg); /** * Returns whether a string starts with a given prefix. */ -inline bool startsWith(const std::string &str, const char *prefix) +inline bool startsWith(std::string_view str, std::string_view prefix) { - return str.rfind(prefix, 0) == 0; + return str.substr(0, prefix.size()) == prefix; +} + +/** + * Returns whether a string ends with a given suffix. + */ +inline bool endsWith(std::string_view str, std::string_view suffix) +{ + return str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } /** @@ -193,6 +202,8 @@ inline void fromString(const char *str, bool &value) value = getBoolFromString(str); } +void fromString(const char *str, std::vector<int> &value); + template<typename T> struct FromString<T, std::enable_if_t<std::is_enum_v<T>>> { |