Support UTF-8 in vitastor-cli table output

This commit is contained in:
Vitaliy Filippov
2023-07-25 01:48:57 +00:00
parent 1fe6b0c0e2
commit f52f58b9e9
3 changed files with 24 additions and 4 deletions
+16
View File
@@ -308,3 +308,19 @@ std::string str_repeat(const std::string & str, int times)
r += str;
return r;
}
size_t utf8_length(const std::string & s)
{
size_t len = 0;
for (size_t i = 0; i < s.size(); i++)
len += (s[i] & 0xC0) != 0x80;
return len;
}
size_t utf8_length(const char *s)
{
size_t len = 0;
for (; *s; s++)
len += (*s & 0xC0) != 0x80;
return len;
}