diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-09-21 13:54:36 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-09-21 13:54:36 +0200 |
commit | e1a461279731877ad66298d9c0576997474453af (patch) | |
tree | deb81f9f0b023a969e3592d15936aecdec3907cc /src | |
parent | de456363882d54f18d6fd8614c6d5431d7402824 (diff) | |
download | weechat-e1a461279731877ad66298d9c0576997474453af.zip |
core: ignore color codes in ${length:xxx} and ${lengthscr:xxx}
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-eval.c | 7 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 24 | ||||
-rw-r--r-- | src/gui/gui-chat.h | 1 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index 15f5bc3b5..498f6a116 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -39,6 +39,7 @@ #include "wee-string.h" #include "wee-utf8.h" #include "../gui/gui-buffer.h" +#include "../gui/gui-chat.h" #include "../gui/gui-color.h" #include "../gui/gui-window.h" #include "../plugins/plugin.h" @@ -297,7 +298,7 @@ end: * 6. a reversed string (format: rev:xxx) * 7. a repeated string (format: repeat:count,string) * 8. length of a string (format: length:xxx) or length of a string on screen - * (format: lengthscr:xxx) + * (format: lengthscr:xxx); color codes are ignored * 9. a regex group captured (format: re:N (0.99) or re:+) * 10. a color (format: color:xxx) * 11. an info (format: info:name,arguments) @@ -487,13 +488,13 @@ eval_replace_vars_cb (void *data, const char *text) */ if (strncmp (text, "length:", 7) == 0) { - length = utf8_strlen (text + 7); + length = gui_chat_strlen (text + 7); snprintf (str_value, sizeof (str_value), "%d", length); return strdup (str_value); } if (strncmp (text, "lengthscr:", 10) == 0) { - length = utf8_strlen_screen (text + 10); + length = gui_chat_strlen_screen (text + 10); snprintf (str_value, sizeof (str_value), "%d", length); return strdup (str_value); } diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 687e17686..fe2f07504 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -167,6 +167,30 @@ gui_chat_char_size_screen (const char *utf_char) } /* + * Returns number of char in a string (special chars like colors/attributes are + * ignored). + */ + +int +gui_chat_strlen (const char *string) +{ + int length; + + length = 0; + while (string && string[0]) + { + string = gui_chat_string_next_char (NULL, NULL, + (unsigned char *)string, 0, 0, 0); + if (string) + { + length++; + string = utf8_next_char (string); + } + } + return length; +} + +/* * Returns number of char needed on screen to display a word (special chars like * colors/attributes are ignored). */ diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index b72e21b83..2f4f9ae03 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -69,6 +69,7 @@ extern int gui_chat_display_tags; extern void gui_chat_init (); extern void gui_chat_prefix_build (); extern int gui_chat_utf_char_valid (const char *utf_char); +extern int gui_chat_strlen (const char *string); extern int gui_chat_strlen_screen (const char *string); extern const char *gui_chat_string_add_offset (const char *string, int offset); extern const char *gui_chat_string_add_offset_screen (const char *string, |