utils: Introduce catv()
This commit is contained in:
24
utils.cpp
24
utils.cpp
@@ -214,3 +214,27 @@ std::string utils::trim(std::string_view view)
|
|||||||
}
|
}
|
||||||
return std::string{view};
|
return std::string{view};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string utils::catv(std::string_view view)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
result.reserve(view.length());
|
||||||
|
for(auto c : view)
|
||||||
|
{
|
||||||
|
if (!isascii(c))
|
||||||
|
{
|
||||||
|
result += "M-";
|
||||||
|
result += toascii(c);
|
||||||
|
}
|
||||||
|
else if(iscntrl(c))
|
||||||
|
{
|
||||||
|
result += '^';
|
||||||
|
result += c == '\177' ? '?': c | 0100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user