diff options
-rw-r--r-- | src/being.cpp | 3 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 12 | ||||
-rw-r--r-- | src/utils/stringutils.h | 8 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/being.cpp b/src/being.cpp index 34f68581..d15c27b3 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -213,7 +213,8 @@ void Being::setPath(const Path &path) void Being::setSpeech(const std::string &text, int time) { - mSpeech = text; + // Remove colors + mSpeech = removeColors(text); // Trim whitespace trim(mSpeech); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index c9428974..64d928d6 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -105,3 +105,15 @@ std::string &removeBadChars(std::string &str) return str; } + +std::string removeColors(std::string msg) +{ + for (unsigned int f = 0; f < msg.length() - 2 && msg.length() > 2; f++) + { + while (msg.length() > f + 2 && msg.at(f) == '#' && msg.at(f + 1) == '#') + { + msg = msg.erase(f, 3); + } + } + return msg; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 89d3d7e9..ae105c6c 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -92,4 +92,12 @@ std::string strprintf(char const *, ...) */ std::string &removeBadChars(std::string &str); +/** + * Removes colors from a string + * + * @param msg the string to remove the colors from + * @return string without colors + */ +std::string removeColors(std::string msg); + #endif // UTILS_STRINGUTILS_H |