void ChatBackend::addMessage(std::wstring name, std::wstring text)
{
+ name = removeChatEscapes(name);
+ text = removeChatEscapes(text);
+
// Note: A message may consist of multiple lines, for example the MOTD.
WStrfnd fnd(text);
while (!fnd.atend())
return true;
}
+std::wstring removeChatEscapes(const std::wstring &s) {
+ std::wstring output;
+ size_t i = 0;
+ while (i < s.length()) {
+ if (s[i] == L'\v') {
+ ++i;
+ if (i == s.length()) continue;
+ if (s[i] == L'(') {
+ ++i;
+ while (i < s.length() && s[i] != L')') {
+ if (s[i] == L'\\') {
+ ++i;
+ }
+ ++i;
+ }
+ ++i;
+ } else {
+ ++i;
+ }
+ continue;
+ }
+ output += s[i];
+ ++i;
+ }
+ return output;
+}
+
void str_replace(std::string &str, char from, char to)
{
std::replace(str.begin(), str.end(), from, to);
}
}
+/**
+ * Remove all chat escape sequences in \p s.
+ *
+ * @param s The string in which to remove escape sequences.
+ * @return \p s, with escape sequences removed.
+ */
+std::wstring removeChatEscapes(const std::wstring &s);
/**
* Replace all occurrences of the character \p from in \p str with \p to.