- Added more UTF8 unit tests for calculating string length, string width,
  formatted string length, formatted string width.
- Implemented UTF8 text width method for symmetry.
This commit is contained in:
Paul Beckingham 2013-03-02 18:14:56 -05:00
parent 551b4dbe90
commit 914447c885
3 changed files with 55 additions and 19 deletions

View file

@ -244,6 +244,32 @@ unsigned int utf8_text_length (const std::string& str)
return charLength;
}
////////////////////////////////////////////////////////////////////////////////
unsigned int utf8_text_width (const std::string& str)
{
bool in_color = false;
unsigned int length = 0;
std::string::size_type i = 0;
unsigned int c;
while ((c = utf8_next_char (str, i)))
{
if (in_color)
{
if (c == 'm')
in_color = false;
}
else if (c == 033)
{
in_color = true;
}
else
length += mk_wcwidth (c);
}
return length;
}
////////////////////////////////////////////////////////////////////////////////
const std::string utf8_substr (
const std::string& input,