27 changes: 0 additions & 27 deletions src/util/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,33 +729,6 @@ static bool parseNamedColorString(const std::string &value, video::SColor &color
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);
Expand Down
44 changes: 35 additions & 9 deletions src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,6 @@ inline void str_replace(std::string &str, const std::string &pattern,
}
}

/**
* 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.
*
Expand Down Expand Up @@ -476,7 +468,7 @@ inline std::string wrap_rows(const std::string &from,
* Removes backslashes from an escaped string (FormSpec strings)
*/
template <typename T>
inline std::basic_string<T> unescape_string(std::basic_string<T> &s)
inline std::basic_string<T> unescape_string(const std::basic_string<T> &s)
{
std::basic_string<T> res;

Expand All @@ -492,6 +484,40 @@ inline std::basic_string<T> unescape_string(std::basic_string<T> &s)
return res;
}

/**
* Remove all escape sequences in \p s.
*
* @param s The string in which to remove escape sequences.
* @return \p s, with escape sequences removed.
*/
template <typename T>
std::basic_string<T> unescape_enriched(const std::basic_string<T> &s)
{
std::basic_string<T> output;
size_t i = 0;
while (i < s.length()) {
if (s[i] == '\x1b') {
++i;
if (i == s.length()) continue;
if (s[i] == '(') {
++i;
while (i < s.length() && s[i] != ')') {
if (s[i] == '\\') {
++i;
}
++i;
}
++i;
} else {
++i;
}
continue;
}
output += s[i];
++i;
}
return output;
}

/**
* Checks that all characters in \p to_check are a decimal digits.
Expand Down