mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
UTF8
- Added UTF8 string width calculation.
This commit is contained in:
parent
8e536fa4a8
commit
551b4dbe90
3 changed files with 22 additions and 1 deletions
14
src/utf8.cpp
14
src/utf8.cpp
|
@ -28,6 +28,7 @@
|
|||
#define L10N // Localization complete.
|
||||
|
||||
#include <string>
|
||||
#include <text.h>
|
||||
#include <utf8.h>
|
||||
#include <i18n.h>
|
||||
|
||||
|
@ -192,6 +193,19 @@ unsigned int utf8_length (const std::string& str)
|
|||
return charLength;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Width of a string in character cells.
|
||||
unsigned int utf8_width (const std::string& str)
|
||||
{
|
||||
unsigned int length = 0;
|
||||
std::string::size_type i = 0;
|
||||
unsigned int c;
|
||||
while ((c = utf8_next_char (str, i)))
|
||||
length += mk_wcwidth (c);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
unsigned int utf8_text_length (const std::string& str)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue