mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-24 08:56:43 +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)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@ std::string utf8_character (unsigned int);
|
|||
int utf8_sequence (unsigned int);
|
||||
unsigned int utf8_length (const std::string&);
|
||||
unsigned int utf8_text_length (const std::string&);
|
||||
unsigned int utf8_width (const std::string& str);
|
||||
const std::string utf8_substr (const std::string&, unsigned int, unsigned int length = 0);
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue