mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
UTF8
- 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:
parent
551b4dbe90
commit
914447c885
3 changed files with 55 additions and 19 deletions
26
src/utf8.cpp
26
src/utf8.cpp
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue