diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/stringutils.cpp | 18 | ||||
-rw-r--r-- | src/utils/stringutils.h | 4 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 67a0d831..6727dcdf 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -140,3 +140,21 @@ int compareStrI(const std::string &a, const std::string &b) return 0; } + +bool isWordSeparator(char chr) +{ + return (chr == ' ' || chr == ',' || chr == '.'); +} + +const std::string findSameSubstring(std::string &str1, std::string &str2) +{ + int minLength = str1.length() > str2.length() ? str2.length() : str1.length(); + for (int f = 0; f < minLength; f ++) + { + if (str1.at(f) != str2.at(f)) + { + return str1.substr(0, f); + } + } + return str1.substr(0, minLength); +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 3624268f..4f0138de 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -119,4 +119,8 @@ std::string removeColors(std::string msg); */ int compareStrI(const std::string &a, const std::string &b); +bool isWordSeparator(char chr); + +const std::string findSameSubstring(std::string &str1, std::string &str2); + #endif // UTILS_STRINGUTILS_H |