Added helper function to strip colors from strings.
This commit is contained in:
@@ -140,6 +140,32 @@ namespace utils::string
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
std::string strip(std::string_view sv, bool strip_default_color)
|
||||
{
|
||||
std::string in(sv);
|
||||
|
||||
for (std::size_t i = 0; i + 1 < in.size();)
|
||||
{
|
||||
if (in[i] == '^' && static_cast<std::size_t>(in[i + 1] - '0') < 0xC)
|
||||
{
|
||||
if (in[i + 1] != '7' || strip_default_color)
|
||||
{
|
||||
in.erase(in.begin() + i, in.begin() + i + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::string convert(const std::wstring& wstr)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
Reference in New Issue
Block a user