summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-04-10 09:34:38 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-04-29 09:48:35 +0000
commit913cda59de309f967a24b10575dc3443f382a8f9 (patch)
treebe00679f3e1dadfdc77e707b827491f2447cbebb /src/utils/stringutils.cpp
parent09218ff19862a8e9595b6ccfba807315897d018d (diff)
downloadmana-913cda59de309f967a24b10575dc3443f382a8f9.tar.gz
mana-913cda59de309f967a24b10575dc3443f382a8f9.tar.bz2
mana-913cda59de309f967a24b10575dc3443f382a8f9.tar.xz
mana-913cda59de309f967a24b10575dc3443f382a8f9.zip
Changed removeColors to work in-place
Can avoid some memory allocations. Also simplified its implementation a little. Also made ChatLogger::getDateString use the full year.
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index ba5f575b..05b6982c 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -111,14 +111,13 @@ std::string &replaceCharacters(std::string &str,
return str;
}
-std::string removeColors(std::string msg)
+std::string &removeColors(std::string &msg)
{
- for (unsigned int f = 0; f < msg.length() - 2 && msg.length() > 2; f++)
+ auto pos = msg.find("##");
+ while (pos != std::string::npos && msg.length() - pos >= 3)
{
- while (msg.length() > f + 2 && msg.at(f) == '#' && msg.at(f + 1) == '#')
- {
- msg = msg.erase(f, 3);
- }
+ msg.erase(pos, 3);
+ pos = msg.find("##", pos);
}
return msg;
}