UTF8
- Added UTF8 string width calculation.
This commit is contained in:
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user