diff options
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 4 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 5 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 4 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 4 | ||||
-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 | ||||
-rw-r--r-- | tests/unit/core/test-core-eval.cpp | 2 |
8 files changed, 40 insertions, 11 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 91a7e14f3..b602ad1c2 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -2476,7 +2476,7 @@ expanded to last): | `+${length:xxx}+` + (_WeeChat ≥ 2.7_) | - Length of string (number of UTF-8 chars). | + Length of string (number of UTF-8 chars), color codes are ignored. | `+${length:test}+` + `+${length:こんにちは世界}+` | `+4+` + @@ -2484,7 +2484,7 @@ expanded to last): | `+${lengthscr:xxx}+` + (_WeeChat ≥ 2.7_) | - Length of string displayed on screen. | + Length of string displayed on screen, color codes are ignored. | `+${lengthscr:test}+` + `+${lengthscr:こんにちは世界}+` | `+4+` + diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 1ea4042a4..583b49ae9 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -2523,7 +2523,8 @@ première étendue à la dernière) : | `+${length:xxx}+` + (_WeeChat ≥ 2.7_) | - Longueur de la chaîne (nombre de caractères UTF-8). | + Longueur de la chaîne (nombre de caractères UTF-8), les codes couleurs sont + ignorés. | `+${length:test}+` + `+${length:こんにちは世界}+` | `+4+` + @@ -2531,7 +2532,7 @@ première étendue à la dernière) : | `+${lengthscr:xxx}+` + (_WeeChat ≥ 2.7_) | - Longueur de la chaîne affichée à l'écran. | + Longueur de la chaîne affichée à l'écran, les codes couleurs sont ignorés. | `+${lengthscr:test}+` + `+${lengthscr:こんにちは世界}+` | `+4+` + diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 72b139616..e874795d0 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -2584,7 +2584,7 @@ expanded to last): | `+${length:xxx}+` + (_WeeChat ≥ 2.7_) | - Length of string (number of UTF-8 chars). | + Length of string (number of UTF-8 chars), color codes are ignored. | `+${length:test}+` + `+${length:こんにちは世界}+` | `+4+` + @@ -2592,7 +2592,7 @@ expanded to last): | `+${lengthscr:xxx}+` + (_WeeChat ≥ 2.7_) | - Length of string displayed on screen. | + Length of string displayed on screen, color codes are ignored. | `+${lengthscr:test}+` + `+${lengthscr:こんにちは世界}+` | `+4+` + diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index b65b7fc93..1c37b0307 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -2488,7 +2488,7 @@ str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, optio // TRANSLATION MISSING | `+${length:xxx}+` + (_WeeChat ≥ 2.7_) | - Length of string (number of UTF-8 chars). | + Length of string (number of UTF-8 chars), color codes are ignored. | `+${length:test}+` + `+${length:こんにちは世界}+` | `+4+` + @@ -2497,7 +2497,7 @@ str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, optio // TRANSLATION MISSING | `+${lengthscr:xxx}+` + (_WeeChat ≥ 2.7_) | - Length of string displayed on screen. | + Length of string displayed on screen, color codes are ignored. | `+${lengthscr:test}+` + `+${lengthscr:こんにちは世界}+` | `+4+` + 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, diff --git a/tests/unit/core/test-core-eval.cpp b/tests/unit/core/test-core-eval.cpp index d2a4da21e..65b2e6fed 100644 --- a/tests/unit/core/test-core-eval.cpp +++ b/tests/unit/core/test-core-eval.cpp @@ -367,10 +367,12 @@ TEST(CoreEval, EvalExpression) WEE_CHECK_EVAL("0", "${length:}"); WEE_CHECK_EVAL("4", "${length:test}"); WEE_CHECK_EVAL("7", "${length:こんにちは世界}"); + WEE_CHECK_EVAL("7", "${length:${color:green}こんにちは世界}"); WEE_CHECK_EVAL("0", "${lengthscr:}"); WEE_CHECK_EVAL("4", "${lengthscr:test}"); WEE_CHECK_EVAL("14", "${lengthscr:こんにちは世界}"); + WEE_CHECK_EVAL("14", "${lengthscr:${color:green}こんにちは世界}"); /* test color */ WEE_CHECK_EVAL(gui_color_get_custom ("green"), "${color:green}"); |