diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-12-04 20:03:21 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-12-10 16:05:14 +0100 |
commit | f1cfd6f73f0f5cc16b9b919d64406a35aa81c7cf (patch) | |
tree | 96a6dfbea3772e65aeec1344b2cb4c7061c916ef /src/core/wee-utf8.c | |
parent | d18f68e497c4244404ff8f4f50de82717b178e09 (diff) | |
download | weechat-f1cfd6f73f0f5cc16b9b919d64406a35aa81c7cf.zip |
core: do not display non printable chars, fix function utf8_char_size_screen
Now the function utf8_char_size_screen can return -1 when the char is not
printable.
It has a specific behavior for some chars:
- U+0009: value of option weechat.look.tab_width
- U+0001 to U+001F (except U+0009): 1
- U+00AD (soft hyphen): -1
- U+200B (zero width space): -1
Diffstat (limited to 'src/core/wee-utf8.c')
-rw-r--r-- | src/core/wee-utf8.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index 6f6526319..c976f7441 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -489,18 +489,34 @@ utf8_strnlen (const char *string, int bytes) int utf8_char_size_screen (const char *string) { - int width; + wchar_t codepoint; - if (!string) + if (!string || !string[0]) return 0; if (string[0] == '\t') return CONFIG_INTEGER(config_look_tab_width); - width = wcwidth ((wchar_t)utf8_char_int (string)); + /* + * chars < 32 are displayed with a letter/symbol and reverse video, + * so exactly one column + */ + if (((unsigned char)string[0]) < 32) + return 1; + + codepoint = (wchar_t)utf8_char_int (string); + + /* + * special chars not displayed (because not handled by WeeChat): + * U+00AD: soft hyphen (wcwidth == 1) + * U+200B: zero width space (wcwidth == 0) + */ + if ((codepoint == 0x00AD) || (codepoint == 0x200B)) + { + return -1; + } - /* non printable chars are displayed with a space (so size = 1) */ - return (width >= 0) ? width : 1; + return wcwidth (codepoint); } /* @@ -512,7 +528,7 @@ utf8_char_size_screen (const char *string) int utf8_strlen_screen (const char *string) { - int size_screen; + int size_screen, size_screen_char; const char *ptr_string; if (!string) @@ -525,7 +541,10 @@ utf8_strlen_screen (const char *string) ptr_string = string; while (ptr_string && ptr_string[0]) { - size_screen += utf8_char_size_screen (ptr_string); + size_screen_char = utf8_char_size_screen (ptr_string); + /* count only chars that use at least one column */ + if (size_screen_char > 0) + size_screen += size_screen_char; ptr_string = utf8_next_char (ptr_string); } |