| 1 | /* $XFree86: xc/programs/xterm/wcwidth.character,v 1.3 2001/07/29 22:08:16 tsi Exp $ */cxx . . $ `<file>/lib/konsole_wcwidth.cpp`/ |
| 2 | /* |
| 3 | * This is an implementation of wcwidth() and wcswidth() as defined in |
| 4 | * "The Single UNIX Specification, Version 2, The Open Group, 1997" |
| 5 | * <http://www.UNIX-systems.org/online.html> |
| 6 | * |
| 7 | * Markus Kuhn -- 2001-01-12 -- public domain |
| 8 | */ |
| 9 | |
| 10 | #include <QString> |
| 11 | |
| 12 | #ifdef HAVE_UTF8PROC |
| 13 | #include <utf8proc.h> |
| 14 | #else |
| 15 | #include <cwchar> |
| 16 | #endif |
| 17 | |
| 18 | #include "konsole_wcwidth.h"cxx . . $ `<file>/lib/konsole_wcwidth.h`/ |
| 19 | |
| 20 | int konsole_wcwidthcxx . . $ konsole_wcwidth(9ddfcb434f4b4cce).(wchar_t ucs) |
| 21 | { |
| 22 | #ifdef HAVE_UTF8PROC |
| 23 | utf8proc_category_t cat = utf8proc_category( ucs ); |
| 24 | if (cat == UTF8PROC_CATEGORY_CO) { |
| 25 | // Co: Private use area. libutf8proc makes them zero width, while tmux |
| 26 | // assumes them to be width 1, and glibc's default width is also 1 |
| 27 | return 1; |
| 28 | } |
| 29 | return utf8proc_charwidth( ucs ); |
| 30 | #else |
| 31 | return wcwidth( ucs ); |
| 32 | #endif |
| 33 | } |
| 34 | |
| 35 | // single byte char: +1, multi byte char: +2 |
| 36 | int string_widthcxx . . $ string_width(b67f1dc07021228a).( const stdcxx . . $ std/::wstringcxx . . $ std/wstring# & wstr ) |
| 37 | { |
| 38 | int w = 0; |
| 39 | for ( size_t i = 0; i < wstr.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); ++i ) { |
| 40 | w += konsole_wcwidthcxx . . $ konsole_wcwidth(9ddfcb434f4b4cce).( wstr[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127). i ] ); |
| 41 | } |
| 42 | return w; |
| 43 | } |