1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add colored text (not only colored chat).

Add documentation, move files to a proper place and avoid memory leaks.
Make it work with most kind of texts, and allow backgrounds too.
This commit is contained in:
Ekdohibs 2016-05-31 17:30:11 +02:00
parent 1d40385d4a
commit 14ef2b445a
28 changed files with 689 additions and 318 deletions

View file

@ -519,6 +519,38 @@ std::basic_string<T> unescape_enriched(const std::basic_string<T> &s)
return output;
}
template <typename T>
std::vector<std::basic_string<T> > split(const std::basic_string<T> &s, T delim)
{
std::vector<std::basic_string<T> > tokens;
std::basic_string<T> current;
bool last_was_escape = false;
for (size_t i = 0; i < s.length(); i++) {
T si = s[i];
if (last_was_escape) {
current += '\\';
current += si;
last_was_escape = false;
} else {
if (si == delim) {
tokens.push_back(current);
current = std::basic_string<T>();
last_was_escape = false;
} else if (si == '\\') {
last_was_escape = true;
} else {
current += si;
last_was_escape = false;
}
}
}
//push last element
tokens.push_back(current);
return tokens;
}
/**
* Checks that all characters in \p to_check are a decimal digits.
*