- Added UTF8 string width calculation.
This commit is contained in:
Paul Beckingham 2013-03-02 17:15:28 -05:00
parent 8e536fa4a8
commit 551b4dbe90
3 changed files with 22 additions and 1 deletions

View file

@ -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)
{