diff --git a/src/string.cpp b/src/string.cpp index 5ed6f90daf..644c9d3c18 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -357,6 +357,28 @@ void str_strip_colours(char *str) *dst = '\0'; } +std::string str_strip_all_scc(const char *str) +{ + std::string out; + if (!str) return out; + + WChar c; + size_t len; + + for (len = Utf8Decode(&c, str); c != '\0'; len = Utf8Decode(&c, str)) { + if (c < SCC_CONTROL_START || c > SCC_SPRITE_END) { + /* Copy the characters */ + do { + out.push_back(*str++); + } while (--len != 0); + } else { + /* Just skip (strip) the control codes */ + str += len; + } + } + return out; +} + /** Scans the string for a wchar and replace it with another wchar * @param str The string buffer * @param last The pointer to the last element of the string buffer diff --git a/src/string_func.h b/src/string_func.h index 7d13e56c0f..2420524316 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -48,6 +48,7 @@ void ValidateString(const char *str); const char *str_fix_scc_encoded(char *str, const char *last); void str_strip_colours(char *str); +std::string str_strip_all_scc(const char *str); char *str_replace_wchar(char *str, const char *last, WChar find, WChar replace); bool strtolower(char *str);