From cfd221014c1e5337ec14503430c98ca620024f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 23 Aug 2020 23:27:57 +0200 Subject: [PATCH] api: add argument "bytes" in function string_dyn_concat --- ChangeLog.adoc | 1 + doc/en/weechat_plugin_api.en.adoc | 9 ++-- doc/fr/weechat_plugin_api.fr.adoc | 9 ++-- doc/it/weechat_plugin_api.it.adoc | 10 ++-- doc/ja/weechat_plugin_api.ja.adoc | 11 +++-- src/core/wee-eval.c | 4 +- src/core/wee-string.c | 14 ++++-- src/core/wee-string.h | 2 +- src/gui/gui-bar-item.c | 31 +++++++----- src/gui/gui-chat.c | 4 +- src/gui/gui-color.c | 68 +++++++++++++------------- src/plugins/buflist/buflist-bar-item.c | 14 ++++-- src/plugins/buflist/buflist-config.c | 11 +++-- src/plugins/fset/fset-bar-item.c | 67 ++++++++++++++++--------- src/plugins/guile/weechat-guile.c | 16 +++--- src/plugins/irc/irc-color.c | 51 ++++++++++--------- src/plugins/irc/irc-protocol.c | 18 ++++--- src/plugins/irc/irc-server.c | 24 +++++---- src/plugins/lua/weechat-lua.c | 10 ++-- src/plugins/perl/weechat-perl.c | 11 ++--- src/plugins/python/weechat-python.c | 8 +-- src/plugins/ruby/weechat-ruby.c | 17 +++---- src/plugins/script/script-action.c | 27 +++++----- src/plugins/spell/spell-bar-item.c | 17 ++++--- src/plugins/weechat-plugin.h | 8 +-- tests/unit/core/test-core-string.cpp | 51 ++++++++++++++++--- 26 files changed, 308 insertions(+), 205 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 89e392c5c..55b423398 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -20,6 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] New features:: + * api: add argument "bytes" in function string_dyn_concat * api: add function string_color_code_size (issue #1547) * fset: add option fset.look.auto_refresh (issue #1553) * irc: add pointer to irc_nick in focus of bar item "buffer_nicklist" (issue #1535, issue #1538) diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 172e9a936..f19c29f95 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -2819,7 +2819,7 @@ This function is not available in scripting API. ==== string_dyn_concat -_WeeChat ≥ 1.8._ +_WeeChat ≥ 1.8, updated in 3.0._ Concatenate a string to a dynamic string. @@ -2830,13 +2830,16 @@ Prototype: [source,C] ---- -int weechat_string_dyn_concat (char **string, const char *add); +int weechat_string_dyn_concat (char **string, const char *add, int bytes); ---- Arguments: * _string_: pointer to dynamic string * _add_: the string to add +* _bytes_: max number of bytes in _add_ to concatenate, must be lower or equal + to length of _add_ (-1 = automatic: concatenate whole string _add_) + _(WeeChat ≥ 3.0)_ Return value: @@ -2849,7 +2852,7 @@ C example: char **string = weechat_string_dyn_alloc (256); if (weechat_string_dyn_copy (string, "test")) { - if (weechat_string_dyn_concat (string, "abc")) + if (weechat_string_dyn_concat (string, "abc", -1)) { /* ... */ } diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index df275701e..ed6bf238d 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -2864,7 +2864,7 @@ Cette fonction n'est pas disponible dans l'API script. ==== string_dyn_concat -_WeeChat ≥ 1.8._ +_WeeChat ≥ 1.8, mis à jour en 3.0._ Concaténer une chaîne dans une chaîne dynamique. @@ -2875,13 +2875,16 @@ Prototype : [source,C] ---- -int weechat_string_dyn_concat (char **string, const char *add); +int weechat_string_dyn_concat (char **string, const char *add, int bytes); ---- Paramètres : * _string_ : pointeur vers la chaîne dynamique * _add_ : la chaîne à ajouter +* _bytes_ : nombre maximum d'octets de _add_ à concaténer, doit être inférieur + ou égal à la longueur de _add_ (-1 = automatique : concaténer la totalité de + la chaîne _add_) _(WeeChat ≥ 3.0)_ Valeur de retour : @@ -2894,7 +2897,7 @@ Exemple en C : char **string = weechat_string_dyn_alloc (256); if (weechat_string_dyn_copy (string, "test")) { - if (weechat_string_dyn_concat (string, "abc")) + if (weechat_string_dyn_concat (string, "abc", -1)) { /* ... */ } diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 62b85ec7c..a7588feca 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -2938,7 +2938,8 @@ Questa funzione non è disponibile nelle API per lo scripting. ==== string_dyn_concat -_WeeChat ≥ 1.8._ +// TRANSLATION MISSING +_WeeChat ≥ 1.8, updated in 3.0._ // TRANSLATION MISSING Concatenate a string to a dynamic string. @@ -2951,7 +2952,7 @@ Prototipo: [source,C] ---- -int weechat_string_dyn_concat (char **string, const char *add); +int weechat_string_dyn_concat (char **string, const char *add, int bytes); ---- Argomenti: @@ -2959,6 +2960,9 @@ Argomenti: // TRANSLATION MISSING * _string_: pointer to dynamic string * _add_: the string to add +* _bytes_: max number of bytes in _add_ to concatenate, must be lower or equal + to length of _add_ (-1 = automatic: concatenate whole string _add_) + _(WeeChat ≥ 3.0)_ Valore restituito: @@ -2972,7 +2976,7 @@ Esempio in C: char **string = weechat_string_dyn_alloc (256); if (weechat_string_dyn_copy (string, "test")) { - if (weechat_string_dyn_concat (string, "abc")) + if (weechat_string_dyn_concat (string, "abc", -1)) { /* ... */ } diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index fdd40dea5..0ce3866f4 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -2848,7 +2848,8 @@ else ==== string_dyn_concat -_WeeChat バージョン 1.8 以上で利用可_ +// TRANSLATION MISSING +_WeeChat バージョン 1.8 以上で利用可, updated in 3.0_ 動的文字列に文字列を連結します。 @@ -2859,13 +2860,17 @@ _WeeChat バージョン 1.8 以上で利用可_ [source,C] ---- -int weechat_string_dyn_concat (char **string, const char *add); +int weechat_string_dyn_concat (char **string, const char *add, int bytes); ---- 引数: * _string_: 動的文字列へのポインタ * _add_: 連結する文字列 +// TRANSLATION MISSING +* _bytes_: max number of bytes in _add_ to concatenate, must be lower or equal + to length of _add_ (-1 = automatic: concatenate whole string _add_) + _(WeeChat ≥ 3.0)_ 戻り値: @@ -2878,7 +2883,7 @@ C 言語での使用例: char **string = weechat_string_dyn_alloc (256); if (weechat_string_dyn_copy (string, "test")) { - if (weechat_string_dyn_concat (string, "abc")) + if (weechat_string_dyn_concat (string, "abc", -1)) { /* ... */ } diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index 4d64c641f..c36192f09 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -80,8 +80,8 @@ eval_debug_message (struct t_eval_context *eval_context, char *message, ...) return; if (*(eval_context->debug)[0]) - string_dyn_concat (eval_context->debug, "\n"); - string_dyn_concat (eval_context->debug, vbuffer); + string_dyn_concat (eval_context->debug, "\n", -1); + string_dyn_concat (eval_context->debug, vbuffer, -1); free (vbuffer); } diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 4c41239c3..9dbc2ce50 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -3978,6 +3978,10 @@ string_dyn_copy (char **string, const char *new_string) /* * Concatenates a string to a dynamic string and adjusts its size accordingly. * + * The parameter "bytes" is the max number of bytes to concatenate + * (a terminating null byte '\0' is automatically added); value -1 means + * automatic: whole string "add" is concatenated. + * * The string pointer (*string) is updated with the new allocated string * if the string had to be extended, or the same pointer if there was enough * size to concatenate the new string. @@ -3988,7 +3992,7 @@ string_dyn_copy (char **string, const char *new_string) */ int -string_dyn_concat (char **string, const char *add) +string_dyn_concat (char **string, const char *add, int bytes) { struct t_string_dyn *ptr_string_dyn; char *string_realloc; @@ -3997,12 +4001,15 @@ string_dyn_concat (char **string, const char *add) if (!string || !*string) return 0; - if (!add || !add[0]) + if (!add || !add[0] || (bytes == 0)) return 1; ptr_string_dyn = (struct t_string_dyn *)string; length_add = strlen (add); + if ((bytes >= 0) && (bytes < (int)length_add)) + length_add = bytes; + new_size = ptr_string_dyn->size + length_add; if (new_size > ptr_string_dyn->size_alloc) @@ -4027,8 +4034,9 @@ string_dyn_concat (char **string, const char *add) /* concatenate "add" after "string" */ memmove (ptr_string_dyn->string + ptr_string_dyn->size - 1, add, - length_add + 1); + length_add); ptr_string_dyn->size = new_size; + ptr_string_dyn->string[new_size - 1] = '\0'; return 1; } diff --git a/src/core/wee-string.h b/src/core/wee-string.h index a34dbd041..c54513535 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -134,7 +134,7 @@ extern const char *string_shared_get (const char *string); extern void string_shared_free (const char *string); extern char **string_dyn_alloc (int size_alloc); extern int string_dyn_copy (char **string, const char *new_string); -extern int string_dyn_concat (char **string, const char *add); +extern int string_dyn_concat (char **string, const char *add, int bytes); extern char *string_dyn_free (char **string, int free_string); extern void string_end (); diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 1390cee2a..09de97d02 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -1769,7 +1769,7 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data, && ptr_group->visible)) { if (*nicklist[0]) - string_dyn_concat (nicklist, "\n"); + string_dyn_concat (nicklist, "\n", -1); if (ptr_nick) { @@ -1777,7 +1777,7 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data, { for (i = 0; i < ptr_nick->group->level; i++) { - string_dyn_concat (nicklist, " "); + string_dyn_concat (nicklist, " ", -1); } } if (ptr_nick->prefix_color) @@ -1793,18 +1793,20 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data, nicklist, gui_color_get_custom ( gui_color_get_name ( - CONFIG_COLOR(ptr_option)))); + CONFIG_COLOR(ptr_option))), + -1); } } else { string_dyn_concat (nicklist, gui_color_get_custom ( - ptr_nick->prefix_color)); + ptr_nick->prefix_color), + -1); } } if (ptr_nick->prefix) - string_dyn_concat (nicklist, ptr_nick->prefix); + string_dyn_concat (nicklist, ptr_nick->prefix, -1); if (ptr_nick->color) { if (strchr (ptr_nick->color, '.')) @@ -1818,23 +1820,25 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data, nicklist, gui_color_get_custom ( gui_color_get_name ( - CONFIG_COLOR(ptr_option)))); + CONFIG_COLOR(ptr_option))), + -1); } } else { string_dyn_concat (nicklist, gui_color_get_custom ( - ptr_nick->color)); + ptr_nick->color), + -1); } } - string_dyn_concat (nicklist, ptr_nick->name); + string_dyn_concat (nicklist, ptr_nick->name, -1); } else { for (i = 0; i < ptr_group->level - 1; i++) { - string_dyn_concat (nicklist, " "); + string_dyn_concat (nicklist, " ", -1); } if (ptr_group->color) { @@ -1849,19 +1853,22 @@ gui_bar_item_buffer_nicklist_cb (const void *pointer, void *data, nicklist, gui_color_get_custom ( gui_color_get_name ( - CONFIG_COLOR(ptr_option)))); + CONFIG_COLOR(ptr_option))), + -1); } } else { string_dyn_concat (nicklist, gui_color_get_custom ( - ptr_group->color)); + ptr_group->color), + -1); } } string_dyn_concat (nicklist, gui_nicklist_get_group_start ( - ptr_group->name)); + ptr_group->name), + -1); } } gui_nicklist_get_next_item (buffer, &ptr_group, &ptr_nick); diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index f70e9bb50..36a7b9013 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -906,9 +906,9 @@ gui_chat_add_line_waiting_buffer (const char *message) } if (*gui_chat_lines_waiting_buffer[0]) - string_dyn_concat (gui_chat_lines_waiting_buffer, "\n"); + string_dyn_concat (gui_chat_lines_waiting_buffer, "\n", -1); - string_dyn_concat (gui_chat_lines_waiting_buffer, message); + string_dyn_concat (gui_chat_lines_waiting_buffer, message, -1); } /* diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index c487eb68b..bc43ac44e 100644 --- a/src/gui/gui-color.c +++ b/src/gui/gui-color.c @@ -1192,16 +1192,16 @@ gui_color_add_ansi_flag (char **output, int flag) switch (flag) { case GUI_COLOR_EXTENDED_BOLD_FLAG: - string_dyn_concat (output, "\x1B[1m"); + string_dyn_concat (output, "\x1B[1m", -1); break; case GUI_COLOR_EXTENDED_REVERSE_FLAG: - string_dyn_concat (output, "\x1B[7m"); + string_dyn_concat (output, "\x1B[7m", -1); break; case GUI_COLOR_EXTENDED_ITALIC_FLAG: - string_dyn_concat (output, "\x1B[3m"); + string_dyn_concat (output, "\x1B[3m", -1); break; case GUI_COLOR_EXTENDED_UNDERLINE_FLAG: - string_dyn_concat (output, "\x1B[4m"); + string_dyn_concat (output, "\x1B[4m", -1); break; case GUI_COLOR_EXTENDED_KEEPATTR_FLAG: /* nothing to do here (really? not sure) */ @@ -1284,7 +1284,7 @@ gui_color_encode_ansi (const char *string) snprintf (str_concat, sizeof (str_concat), "\x1B[38;5;%dm", color); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } ptr_string += 5; } @@ -1311,7 +1311,7 @@ gui_color_encode_ansi (const char *string) "\x1B[%dm", (ansi_color < 8) ? ansi_color + 30 : ansi_color - 8 + 90); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } } ptr_string += 2; @@ -1335,7 +1335,7 @@ gui_color_encode_ansi (const char *string) snprintf (str_concat, sizeof (str_concat), "\x1B[48;5;%dm", color); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } ptr_string += 5; } @@ -1357,7 +1357,7 @@ gui_color_encode_ansi (const char *string) "\x1B[%dm", (ansi_color < 8) ? ansi_color + 40 : ansi_color - 8 + 100); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } } ptr_string += 2; @@ -1386,7 +1386,7 @@ gui_color_encode_ansi (const char *string) snprintf (str_concat, sizeof (str_concat), "\x1B[38;5;%dm", color); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } ptr_string += 5; } @@ -1413,7 +1413,7 @@ gui_color_encode_ansi (const char *string) "\x1B[%dm", (ansi_color < 8) ? ansi_color + 30 : ansi_color - 8 + 90); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } } ptr_string += 2; @@ -1443,7 +1443,7 @@ gui_color_encode_ansi (const char *string) snprintf (str_concat, sizeof (str_concat), "\x1B[48;5;%dm", color); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } ptr_string += 5; } @@ -1466,7 +1466,7 @@ gui_color_encode_ansi (const char *string) "\x1B[%dm", (ansi_color < 8) ? ansi_color + 40 : ansi_color - 8 + 100); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } } ptr_string += 2; @@ -1489,7 +1489,7 @@ gui_color_encode_ansi (const char *string) snprintf (str_concat, sizeof (str_concat), "\x1B[38;5;%dm", color); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } ptr_string += 5; } @@ -1515,7 +1515,7 @@ gui_color_encode_ansi (const char *string) break; case GUI_COLOR_RESET_CHAR: ptr_string++; - string_dyn_concat (out, "\x1B[39m\x1B[49m"); + string_dyn_concat (out, "\x1B[39m\x1B[49m", -1); break; default: if (isdigit (ptr_string[0]) && isdigit (ptr_string[1])) @@ -1532,40 +1532,40 @@ gui_color_encode_ansi (const char *string) bg = gui_color[color]->background; attrs = gui_color_get_extended_flags ( gui_color[color]->attributes); - string_dyn_concat (out, "\x1B[0m"); + string_dyn_concat (out, "\x1B[0m", -1); if (attrs & GUI_COLOR_EXTENDED_BOLD_FLAG) - string_dyn_concat (out, "\x1B[1m"); + string_dyn_concat (out, "\x1B[1m", -1); if (attrs & GUI_COLOR_EXTENDED_REVERSE_FLAG) - string_dyn_concat (out, "\x1B[7m"); + string_dyn_concat (out, "\x1B[7m", -1); if (attrs & GUI_COLOR_EXTENDED_ITALIC_FLAG) - string_dyn_concat (out, "\x1B[3m"); + string_dyn_concat (out, "\x1B[3m", -1); if (attrs & GUI_COLOR_EXTENDED_UNDERLINE_FLAG) - string_dyn_concat (out, "\x1B[4m"); + string_dyn_concat (out, "\x1B[4m", -1); if ((fg > 0) && (fg & GUI_COLOR_EXTENDED_FLAG)) fg &= GUI_COLOR_EXTENDED_MASK; if ((bg > 0) && (bg & GUI_COLOR_EXTENDED_FLAG)) bg &= GUI_COLOR_EXTENDED_MASK; if (fg < 0) { - string_dyn_concat (out, "\x1B[39m"); + string_dyn_concat (out, "\x1B[39m", -1); } else { snprintf (str_concat, sizeof (str_concat), "\x1B[38;5;%dm", fg); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } if (bg < 0) { - string_dyn_concat (out, "\x1B[49m"); + string_dyn_concat (out, "\x1B[49m", -1); } else { snprintf (str_concat, sizeof (str_concat), "\x1B[48;5;%dm", bg); - string_dyn_concat (out, str_concat); + string_dyn_concat (out, str_concat, -1); } } ptr_string += 2; @@ -1580,16 +1580,16 @@ gui_color_encode_ansi (const char *string) switch (ptr_string[0]) { case GUI_COLOR_ATTR_BOLD_CHAR: - string_dyn_concat (out, "\x1B[1m"); + string_dyn_concat (out, "\x1B[1m", -1); break; case GUI_COLOR_ATTR_REVERSE_CHAR: - string_dyn_concat (out, "\x1B[7m"); + string_dyn_concat (out, "\x1B[7m", -1); break; case GUI_COLOR_ATTR_ITALIC_CHAR: - string_dyn_concat (out, "\x1B[3m"); + string_dyn_concat (out, "\x1B[3m", -1); break; case GUI_COLOR_ATTR_UNDERLINE_CHAR: - string_dyn_concat (out, "\x1B[4m"); + string_dyn_concat (out, "\x1B[4m", -1); break; } ptr_string++; @@ -1602,32 +1602,30 @@ gui_color_encode_ansi (const char *string) switch (ptr_string[0]) { case GUI_COLOR_ATTR_BOLD_CHAR: - string_dyn_concat (out, "\x1B[21m"); + string_dyn_concat (out, "\x1B[21m", -1); break; case GUI_COLOR_ATTR_REVERSE_CHAR: - string_dyn_concat (out, "\x1B[27m"); + string_dyn_concat (out, "\x1B[27m", -1); break; case GUI_COLOR_ATTR_ITALIC_CHAR: - string_dyn_concat (out, "\x1B[23m"); + string_dyn_concat (out, "\x1B[23m", -1); break; case GUI_COLOR_ATTR_UNDERLINE_CHAR: - string_dyn_concat (out, "\x1B[24m"); + string_dyn_concat (out, "\x1B[24m", -1); break; } ptr_string++; } break; case GUI_COLOR_RESET_CHAR: - string_dyn_concat (out, "\x1B[0m"); + string_dyn_concat (out, "\x1B[0m", -1); ptr_string++; break; default: length = utf8_char_size ((char *)ptr_string); if (length == 0) length = 1; - memcpy (str_concat, ptr_string, length); - str_concat[length] = '\0'; - string_dyn_concat (out, str_concat); + string_dyn_concat (out, (const char *)ptr_string, length); ptr_string += length; break; } diff --git a/src/plugins/buflist/buflist-bar-item.c b/src/plugins/buflist/buflist-bar-item.c index e82fc18bc..01efdda8a 100644 --- a/src/plugins/buflist/buflist-bar-item.c +++ b/src/plugins/buflist/buflist-bar-item.c @@ -542,15 +542,19 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, weechat_string_dyn_concat ( hotlist, weechat_config_string ( - buflist_config_format_hotlist_separator)); + buflist_config_format_hotlist_separator), + -1); } weechat_string_dyn_concat ( hotlist, weechat_config_string ( - buflist_config_format_hotlist_level[j])); + buflist_config_format_hotlist_level[j]), + -1); snprintf (str_hotlist_count, sizeof (str_hotlist_count), "%d", count); - weechat_string_dyn_concat (hotlist, str_hotlist_count); + weechat_string_dyn_concat (hotlist, + str_hotlist_count, + -1); } } str_hotlist = *hotlist; @@ -606,7 +610,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, if (weechat_config_boolean (buflist_config_look_add_newline) && *buflist[0]) { - if (!weechat_string_dyn_concat (buflist, "\n")) + if (!weechat_string_dyn_concat (buflist, "\n", -1)) goto error; } @@ -618,7 +622,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, NULL); /* concatenate string */ - rc = weechat_string_dyn_concat (buflist, line); + rc = weechat_string_dyn_concat (buflist, line, -1); free (line); if (!rc) goto error; diff --git a/src/plugins/buflist/buflist-config.c b/src/plugins/buflist/buflist-config.c index 111cf996a..5c60f2f44 100644 --- a/src/plugins/buflist/buflist-config.c +++ b/src/plugins/buflist/buflist-config.c @@ -151,18 +151,19 @@ buflist_config_hook_signals_refresh () ptr_signals_refresh = weechat_config_string ( buflist_config_look_signals_refresh); - weechat_string_dyn_concat (all_signals, BUFLIST_CONFIG_SIGNALS_REFRESH); + weechat_string_dyn_concat (all_signals, BUFLIST_CONFIG_SIGNALS_REFRESH, -1); if (ptr_signals_refresh && ptr_signals_refresh[0]) { - weechat_string_dyn_concat (all_signals, ","); - weechat_string_dyn_concat (all_signals, ptr_signals_refresh); + weechat_string_dyn_concat (all_signals, ",", -1); + weechat_string_dyn_concat (all_signals, ptr_signals_refresh, -1); } if (weechat_config_boolean (buflist_config_look_nick_prefix)) { - weechat_string_dyn_concat (all_signals, ","); + weechat_string_dyn_concat (all_signals, ",", -1); weechat_string_dyn_concat ( all_signals, - BUFLIST_CONFIG_SIGNALS_REFRESH_NICK_PREFIX); + BUFLIST_CONFIG_SIGNALS_REFRESH_NICK_PREFIX, + -1); } signals = weechat_string_split (*all_signals, ",", NULL, diff --git a/src/plugins/fset/fset-bar-item.c b/src/plugins/fset/fset-bar-item.c index bef62d773..60d04c1a1 100644 --- a/src/plugins/fset/fset-bar-item.c +++ b/src/plugins/fset/fset-bar-item.c @@ -81,8 +81,8 @@ fset_bar_item_fset_cb (const void *pointer, void *data, if (!default_and_values) return NULL; - weechat_string_dyn_concat (default_and_values, weechat_color ("bar_fg")); - weechat_string_dyn_concat (default_and_values, _("default: ")); + weechat_string_dyn_concat (default_and_values, weechat_color ("bar_fg"), -1); + weechat_string_dyn_concat (default_and_values, _("default: "), -1); if (ptr_fset_option->default_value) { if (ptr_fset_option->type == FSET_OPTION_TYPE_STRING) @@ -90,29 +90,37 @@ fset_bar_item_fset_cb (const void *pointer, void *data, weechat_string_dyn_concat (default_and_values, weechat_color ( weechat_config_string ( - fset_config_color_help_quotes))); - weechat_string_dyn_concat (default_and_values, "\""); + fset_config_color_help_quotes)), + -1); + weechat_string_dyn_concat (default_and_values, "\"", -1); } weechat_string_dyn_concat ( default_and_values, - weechat_color (weechat_config_string (fset_config_color_help_default_value))); + weechat_color (weechat_config_string (fset_config_color_help_default_value)), + -1); weechat_string_dyn_concat (default_and_values, - ptr_fset_option->default_value); + ptr_fset_option->default_value, + -1); if (ptr_fset_option->type == FSET_OPTION_TYPE_STRING) { weechat_string_dyn_concat (default_and_values, weechat_color ( weechat_config_string ( - fset_config_color_help_quotes))); - weechat_string_dyn_concat (default_and_values, "\""); + fset_config_color_help_quotes)), + -1); + weechat_string_dyn_concat (default_and_values, "\"", -1); } } else { weechat_string_dyn_concat ( default_and_values, - weechat_color (weechat_config_string (fset_config_color_help_default_value))); - weechat_string_dyn_concat (default_and_values, FSET_OPTION_VALUE_NULL); + weechat_color (weechat_config_string (fset_config_color_help_default_value)), + -1); + weechat_string_dyn_concat ( + default_and_values, + FSET_OPTION_VALUE_NULL, + -1); } if ((ptr_fset_option->string_values && ptr_fset_option->string_values[0]) @@ -131,10 +139,11 @@ fset_bar_item_fset_cb (const void *pointer, void *data, || (ptr_fset_option->type == FSET_OPTION_TYPE_INTEGER)) { weechat_string_dyn_concat (default_and_values, - weechat_color ("bar_fg")); - weechat_string_dyn_concat (default_and_values, ", "); - weechat_string_dyn_concat (default_and_values, _("values:")); - weechat_string_dyn_concat (default_and_values, " "); + weechat_color ("bar_fg"), + -1); + weechat_string_dyn_concat (default_and_values, ", ", -1); + weechat_string_dyn_concat (default_and_values, _("values:"), -1); + weechat_string_dyn_concat (default_and_values, " ", -1); if (ptr_string_values) { for (i = 0; ptr_string_values[i]; i++) @@ -142,16 +151,21 @@ fset_bar_item_fset_cb (const void *pointer, void *data, if (i > 0) { weechat_string_dyn_concat (default_and_values, - weechat_color ("bar_fg")); - weechat_string_dyn_concat (default_and_values, ", "); + weechat_color ("bar_fg"), + -1); + weechat_string_dyn_concat (default_and_values, + ", ", + -1); } weechat_string_dyn_concat ( default_and_values, weechat_color ( weechat_config_string ( - fset_config_color_help_values))); + fset_config_color_help_values)), + -1); weechat_string_dyn_concat (default_and_values, - ptr_string_values[i]); + ptr_string_values[i], + -1); } } else @@ -160,19 +174,24 @@ fset_bar_item_fset_cb (const void *pointer, void *data, default_and_values, weechat_color ( weechat_config_string ( - fset_config_color_help_values))); + fset_config_color_help_values)), + -1); weechat_string_dyn_concat (default_and_values, - ptr_fset_option->min); + ptr_fset_option->min, + -1); weechat_string_dyn_concat (default_and_values, - weechat_color ("bar_fg")); - weechat_string_dyn_concat (default_and_values, " ... "); + weechat_color ("bar_fg"), + -1); + weechat_string_dyn_concat (default_and_values, " ... ", -1); weechat_string_dyn_concat ( default_and_values, weechat_color ( weechat_config_string ( - fset_config_color_help_values))); + fset_config_color_help_values)), + -1); weechat_string_dyn_concat (default_and_values, - ptr_fset_option->max); + ptr_fset_option->max, + -1); } } } diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c index 4b6406e48..e1a6484c7 100644 --- a/src/plugins/guile/weechat-guile.c +++ b/src/plugins/guile/weechat-guile.c @@ -1180,13 +1180,13 @@ weechat_guile_port_write (SCM port, SCM src, size_t start, size_t count) ptr_data = data2; while ((ptr_newline = strchr (ptr_data, '\n')) != NULL) { - ptr_newline[0] = '\0'; - weechat_string_dyn_concat (guile_buffer_output, ptr_data); + weechat_string_dyn_concat (guile_buffer_output, + ptr_data, + ptr_newline - ptr_data); weechat_guile_output_flush (); - ptr_newline[0] = '\n'; ptr_data = ++ptr_newline; } - weechat_string_dyn_concat (guile_buffer_output, ptr_data); + weechat_string_dyn_concat (guile_buffer_output, ptr_data, -1); free (data2); @@ -1212,13 +1212,13 @@ weechat_guile_port_write (SCM port, const void *data, size_t size) ptr_data = data2; while ((ptr_newline = strchr (ptr_data, '\n')) != NULL) { - ptr_newline[0] = '\0'; - weechat_string_dyn_concat (guile_buffer_output, ptr_data); + weechat_string_dyn_concat (guile_buffer_output, + ptr_data, + ptr_newline - ptr_data); weechat_guile_output_flush (); - ptr_newline[0] = '\n'; ptr_data = ++ptr_newline; } - weechat_string_dyn_concat (guile_buffer_output, ptr_data); + weechat_string_dyn_concat (guile_buffer_output, ptr_data, -1); free (data2); } diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c index 4ec0c9e30..3919c0466 100644 --- a/src/plugins/irc/irc-color.c +++ b/src/plugins/irc/irc-color.c @@ -266,7 +266,7 @@ irc_color_decode (const char *string, int keep_colors) } /* add "str_to_add" (if not empty) to "out" */ if (str_to_add[0]) - weechat_string_dyn_concat (out, str_to_add); + weechat_string_dyn_concat (out, str_to_add, -1); } result = *out; @@ -287,7 +287,7 @@ irc_color_decode (const char *string, int keep_colors) char * irc_color_encode (const char *string, int keep_colors) { - char **out, *result, str_to_add[2], utf_char[16]; + char **out, *result; unsigned char *ptr_string; int length; @@ -306,29 +306,30 @@ irc_color_encode (const char *string, int keep_colors) { case 0x02: /* ^B */ if (keep_colors) - weechat_string_dyn_concat (out, IRC_COLOR_BOLD_STR); + weechat_string_dyn_concat (out, IRC_COLOR_BOLD_STR, -1); ptr_string++; break; case 0x03: /* ^C */ if (keep_colors) - weechat_string_dyn_concat (out, IRC_COLOR_COLOR_STR); + weechat_string_dyn_concat (out, IRC_COLOR_COLOR_STR, -1); ptr_string++; if (isdigit (ptr_string[0])) { if (keep_colors) { - str_to_add[0] = ptr_string[0]; - str_to_add[1] = '\0'; - weechat_string_dyn_concat (out, str_to_add); + weechat_string_dyn_concat (out, + (const char *)ptr_string, + 1); } ptr_string++; if (isdigit (ptr_string[0])) { if (keep_colors) { - str_to_add[0] = ptr_string[0]; - str_to_add[1] = '\0'; - weechat_string_dyn_concat (out, str_to_add); + weechat_string_dyn_concat ( + out, + (const char *)ptr_string, + 1); } ptr_string++; } @@ -336,24 +337,26 @@ irc_color_encode (const char *string, int keep_colors) if (ptr_string[0] == ',') { if (keep_colors) - weechat_string_dyn_concat (out, ","); + weechat_string_dyn_concat (out, ",", -1); ptr_string++; if (isdigit (ptr_string[0])) { if (keep_colors) { - str_to_add[0] = ptr_string[0]; - str_to_add[1] = '\0'; - weechat_string_dyn_concat (out, str_to_add); + weechat_string_dyn_concat ( + out, + (const char *)ptr_string, + 1); } ptr_string++; if (isdigit (ptr_string[0])) { if (keep_colors) { - str_to_add[0] = ptr_string[0]; - str_to_add[1] = '\0'; - weechat_string_dyn_concat (out, str_to_add); + weechat_string_dyn_concat ( + out, + (const char *)ptr_string, + 1); } ptr_string++; } @@ -362,31 +365,31 @@ irc_color_encode (const char *string, int keep_colors) break; case 0x0F: /* ^O */ if (keep_colors) - weechat_string_dyn_concat (out, IRC_COLOR_RESET_STR); + weechat_string_dyn_concat (out, IRC_COLOR_RESET_STR, -1); ptr_string++; break; case 0x16: /* ^V */ if (keep_colors) - weechat_string_dyn_concat (out, IRC_COLOR_REVERSE_STR); + weechat_string_dyn_concat (out, IRC_COLOR_REVERSE_STR, -1); ptr_string++; break; case 0x1D: /* ^] */ if (keep_colors) - weechat_string_dyn_concat (out, IRC_COLOR_ITALIC_STR); + weechat_string_dyn_concat (out, IRC_COLOR_ITALIC_STR, -1); ptr_string++; break; case 0x1F: /* ^_ */ if (keep_colors) - weechat_string_dyn_concat (out, IRC_COLOR_UNDERLINE_STR); + weechat_string_dyn_concat (out, IRC_COLOR_UNDERLINE_STR, -1); ptr_string++; break; default: length = weechat_utf8_char_size ((char *)ptr_string); if (length == 0) length = 1; - memcpy (utf_char, ptr_string, length); - utf_char[length] = '\0'; - weechat_string_dyn_concat (out, utf_char); + weechat_string_dyn_concat (out, + (const char *)ptr_string, + length); ptr_string += length; } } diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index d20860898..dc3fad004 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -515,12 +515,12 @@ irc_protocol_cap_print_cb (void *data, str_caps = (char **)data; if (*str_caps[0]) - weechat_string_dyn_concat (str_caps, " "); - weechat_string_dyn_concat (str_caps, key); + weechat_string_dyn_concat (str_caps, " ", -1); + weechat_string_dyn_concat (str_caps, key, -1); if (value) { - weechat_string_dyn_concat (str_caps, "="); - weechat_string_dyn_concat (str_caps, value); + weechat_string_dyn_concat (str_caps, "=", -1); + weechat_string_dyn_concat (str_caps, value, -1); } } @@ -837,9 +837,10 @@ IRC_PROTOCOL_CALLBACK(cap) if (caps_supported[i][0] == '-') { if (*str_caps_disabled[0]) - weechat_string_dyn_concat (str_caps_disabled, " "); + weechat_string_dyn_concat (str_caps_disabled, " ", -1); weechat_string_dyn_concat (str_caps_disabled, - caps_supported[i] + 1); + caps_supported[i] + 1, + -1); weechat_hashtable_remove (server->cap_list, caps_supported[i] + 1); @@ -847,9 +848,10 @@ IRC_PROTOCOL_CALLBACK(cap) else { if (*str_caps_enabled[0]) - weechat_string_dyn_concat (str_caps_enabled, " "); + weechat_string_dyn_concat (str_caps_enabled, " ", -1); weechat_string_dyn_concat (str_caps_enabled, - caps_supported[i]); + caps_supported[i], + -1); weechat_hashtable_set (server->cap_list, caps_supported[i], NULL); diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index e98749518..4e0dbe6c4 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -5352,18 +5352,22 @@ irc_server_build_autojoin (struct t_irc_server *server) { /* add channel with key and the key */ if (*channels_with_key[0]) - weechat_string_dyn_concat (channels_with_key, ","); - weechat_string_dyn_concat (channels_with_key, ptr_channel->name); + weechat_string_dyn_concat (channels_with_key, ",", -1); + weechat_string_dyn_concat (channels_with_key, + ptr_channel->name, + -1); if (*keys[0]) - weechat_string_dyn_concat (keys, ","); - weechat_string_dyn_concat (keys, ptr_channel->key); + weechat_string_dyn_concat (keys, ",", -1); + weechat_string_dyn_concat (keys, ptr_channel->key, -1); } else { /* add channel without key */ if (*channels_others[0]) - weechat_string_dyn_concat (channels_others, ","); - weechat_string_dyn_concat (channels_others, ptr_channel->name); + weechat_string_dyn_concat (channels_others, ",", -1); + weechat_string_dyn_concat (channels_others, + ptr_channel->name, + -1); } } } @@ -5375,13 +5379,13 @@ irc_server_build_autojoin (struct t_irc_server *server) if (*channels_others[0]) { if (*channels_with_key[0]) - weechat_string_dyn_concat (channels_with_key, ","); - weechat_string_dyn_concat (channels_with_key, *channels_others); + weechat_string_dyn_concat (channels_with_key, ",", -1); + weechat_string_dyn_concat (channels_with_key, *channels_others, -1); } if (*keys[0]) { - weechat_string_dyn_concat (channels_with_key, " "); - weechat_string_dyn_concat (channels_with_key, *keys); + weechat_string_dyn_concat (channels_with_key, " ", -1); + weechat_string_dyn_concat (channels_with_key, *keys, -1); } weechat_string_dyn_free (channels_others, 1); diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c index df03dc4e5..30c042ac8 100644 --- a/src/plugins/lua/weechat-lua.c +++ b/src/plugins/lua/weechat-lua.c @@ -258,7 +258,6 @@ int weechat_lua_output (lua_State *L) { const char *msg, *ptr_msg, *ptr_newline; - char *message; if (lua_gettop (L) < 1) return 0; @@ -267,14 +266,13 @@ weechat_lua_output (lua_State *L) ptr_msg = msg; while ((ptr_newline = strchr (ptr_msg, '\n')) != NULL) { - message = weechat_strndup (ptr_msg, ptr_newline - ptr_msg); - weechat_string_dyn_concat (lua_buffer_output, message); - if (message) - free (message); + weechat_string_dyn_concat (lua_buffer_output, + ptr_msg, + ptr_newline - ptr_msg); weechat_lua_output_flush (); ptr_msg = ++ptr_newline; } - weechat_string_dyn_concat (lua_buffer_output, ptr_msg); + weechat_string_dyn_concat (lua_buffer_output, ptr_msg, -1); return 0; } diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c index 264921d1c..996a51398 100644 --- a/src/plugins/perl/weechat-perl.c +++ b/src/plugins/perl/weechat-perl.c @@ -292,7 +292,7 @@ weechat_perl_output_flush () XS (weechat_perl_output) { - char *msg, *ptr_msg, *ptr_newline, *message; + char *msg, *ptr_msg, *ptr_newline; dXSARGS; if (items < 1) @@ -302,14 +302,13 @@ XS (weechat_perl_output) ptr_msg = msg; while ((ptr_newline = strchr (ptr_msg, '\n')) != NULL) { - message = weechat_strndup (ptr_msg, ptr_newline - ptr_msg); - weechat_string_dyn_concat (perl_buffer_output, message); - if (message) - free (message); + weechat_string_dyn_concat (perl_buffer_output, + ptr_msg, + ptr_newline - ptr_msg); weechat_perl_output_flush (); ptr_msg = ++ptr_newline; } - weechat_string_dyn_concat (perl_buffer_output, ptr_msg); + weechat_string_dyn_concat (perl_buffer_output, ptr_msg, -1); } /* diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index 2515f6f08..d9731784d 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -444,13 +444,13 @@ weechat_python_output (PyObject *self, PyObject *args) ptr_msg = msg; while ((ptr_newline = strchr (ptr_msg, '\n')) != NULL) { - ptr_newline[0] = '\0'; - weechat_string_dyn_concat (python_buffer_output, ptr_msg); + weechat_string_dyn_concat (python_buffer_output, + ptr_msg, + ptr_newline - ptr_msg); weechat_python_output_flush (); - ptr_newline[0] = '\n'; ptr_msg = ++ptr_newline; } - weechat_string_dyn_concat (python_buffer_output, ptr_msg); + weechat_string_dyn_concat (python_buffer_output, ptr_msg, -1); } Py_INCREF(Py_None); diff --git a/src/plugins/ruby/weechat-ruby.c b/src/plugins/ruby/weechat-ruby.c index faa2e354c..160361063 100644 --- a/src/plugins/ruby/weechat-ruby.c +++ b/src/plugins/ruby/weechat-ruby.c @@ -428,24 +428,23 @@ weechat_ruby_output_flush () static VALUE weechat_ruby_output (VALUE self, VALUE str) { - char *msg, *m, *p; + char *msg, *ptr_msg, *ptr_newline; /* make C compiler happy */ (void) self; msg = strdup (StringValuePtr (str)); - m = msg; - while ((p = strchr (m, '\n')) != NULL) + ptr_msg = msg; + while ((ptr_newline = strchr (ptr_msg, '\n')) != NULL) { - *p = '\0'; - weechat_string_dyn_concat (ruby_buffer_output, m); + weechat_string_dyn_concat (ruby_buffer_output, + ptr_msg, + ptr_newline - ptr_msg); weechat_ruby_output_flush (); - *p = '\n'; - m = ++p; + ptr_msg = ++ptr_newline; } - - weechat_string_dyn_concat (ruby_buffer_output, m); + weechat_string_dyn_concat (ruby_buffer_output, ptr_msg, -1); if (msg) free (msg); diff --git a/src/plugins/script/script-action.c b/src/plugins/script/script-action.c index bb79f4534..faedbfb84 100644 --- a/src/plugins/script/script-action.c +++ b/src/plugins/script/script-action.c @@ -121,25 +121,29 @@ script_action_list_input (int send_to_buffer, int translated) { if (*buf[0]) { - weechat_string_dyn_concat (buf, ", "); + weechat_string_dyn_concat (buf, ", ", -1); } else { weechat_string_dyn_concat ( buf, - (translated) ? _("Scripts loaded:") : "Scripts loaded:"); - weechat_string_dyn_concat (buf, " "); + (translated) ? _("Scripts loaded:") : "Scripts loaded:", + -1); + weechat_string_dyn_concat (buf, " ", -1); } weechat_string_dyn_concat (buf, weechat_hdata_string (hdata, ptr_script, - "name")); - weechat_string_dyn_concat (buf, "."); - weechat_string_dyn_concat (buf, script_extension[i]); - weechat_string_dyn_concat (buf, " "); - weechat_string_dyn_concat (buf, weechat_hdata_string (hdata, - ptr_script, - "version")); + "name"), + -1); + weechat_string_dyn_concat (buf, ".", -1); + weechat_string_dyn_concat (buf, script_extension[i], -1); + weechat_string_dyn_concat (buf, " ", -1); + weechat_string_dyn_concat (buf, + weechat_hdata_string (hdata, + ptr_script, + "version"), + -1); ptr_script = weechat_hdata_move (hdata, ptr_script, 1); } } @@ -148,7 +152,8 @@ script_action_list_input (int send_to_buffer, int translated) { weechat_string_dyn_concat ( buf, - (translated) ? _("No scripts loaded") : "No scripts loaded"); + (translated) ? _("No scripts loaded") : "No scripts loaded", + -1); } if (send_to_buffer) diff --git a/src/plugins/spell/spell-bar-item.c b/src/plugins/spell/spell-bar-item.c index b0b6e7ed3..473e957ba 100644 --- a/src/plugins/spell/spell-bar-item.c +++ b/src/plugins/spell/spell-bar-item.c @@ -117,11 +117,13 @@ spell_bar_item_suggest (const void *pointer, void *data, str_suggest, weechat_color ( weechat_config_string ( - spell_config_color_suggestion_delimiter_dict))); + spell_config_color_suggestion_delimiter_dict)), + -1); weechat_string_dyn_concat ( str_suggest, weechat_config_string ( - spell_config_look_suggestion_delimiter_dict)); + spell_config_look_suggestion_delimiter_dict), + -1); } suggestions2 = weechat_string_split ( suggestions[i], @@ -142,18 +144,21 @@ spell_bar_item_suggest (const void *pointer, void *data, str_suggest, weechat_color ( weechat_config_string ( - spell_config_color_suggestion_delimiter_word))); + spell_config_color_suggestion_delimiter_word)), + -1); weechat_string_dyn_concat ( str_suggest, weechat_config_string ( - spell_config_look_suggestion_delimiter_word)); + spell_config_look_suggestion_delimiter_word), + -1); } weechat_string_dyn_concat ( str_suggest, weechat_color ( weechat_config_string ( - spell_config_color_suggestion))); - weechat_string_dyn_concat (str_suggest, suggestions2[j]); + spell_config_color_suggestion)), + -1); + weechat_string_dyn_concat (str_suggest, suggestions2[j], -1); } weechat_string_free_split (suggestions2); } diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index b8cf10456..e2ba4cec2 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -67,7 +67,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20200822-01" +#define WEECHAT_PLUGIN_API_VERSION "20200823-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -350,7 +350,7 @@ struct t_weechat_plugin struct t_hashtable *options); char **(*string_dyn_alloc) (int size_alloc); int (*string_dyn_copy) (char **string, const char *new_string); - int (*string_dyn_concat) (char **string, const char *add); + int (*string_dyn_concat) (char **string, const char *add, int bytes); char *(*string_dyn_free) (char **string, int free_string); /* UTF-8 strings */ @@ -1292,8 +1292,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); (weechat_plugin->string_dyn_alloc)(__size_alloc) #define weechat_string_dyn_copy(__string, __new_string) \ (weechat_plugin->string_dyn_copy)(__string, __new_string) -#define weechat_string_dyn_concat(__string, __add) \ - (weechat_plugin->string_dyn_concat)(__string, __add) +#define weechat_string_dyn_concat(__string, __add, __bytes) \ + (weechat_plugin->string_dyn_concat)(__string, __add, __bytes) #define weechat_string_dyn_free(__string, __free_string) \ (weechat_plugin->string_dyn_free)(__string, __free_string) diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 9812a2367..d12b2acea 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -2160,7 +2160,7 @@ TEST(CoreString, Dyn) ptr_string_dyn = (struct t_string_dyn *)str; /* check concat with NULL */ - LONGS_EQUAL(1, string_dyn_concat (str, NULL)); + LONGS_EQUAL(1, string_dyn_concat (str, NULL, -1)); LONGS_EQUAL(1, ptr_string_dyn->size_alloc); LONGS_EQUAL(1, ptr_string_dyn->size); POINTERS_EQUAL(ptr_string_dyn->string, *str); @@ -2168,46 +2168,81 @@ TEST(CoreString, Dyn) STRCMP_EQUAL("", *str); /* check concat with an empty string */ - LONGS_EQUAL(1, string_dyn_concat (str, "")); + LONGS_EQUAL(1, string_dyn_concat (str, "", -1)); LONGS_EQUAL(1, ptr_string_dyn->size_alloc); LONGS_EQUAL(1, ptr_string_dyn->size); POINTERS_EQUAL(ptr_string_dyn->string, *str); STRCMP_EQUAL("", ptr_string_dyn->string); STRCMP_EQUAL("", *str); - /* check concat with some strings */ - LONGS_EQUAL(1, string_dyn_concat (str, "a")); + /* check concat with some strings and automatic length */ + LONGS_EQUAL(1, string_dyn_concat (str, "a", -1)); LONGS_EQUAL(2, ptr_string_dyn->size_alloc); LONGS_EQUAL(2, ptr_string_dyn->size); POINTERS_EQUAL(ptr_string_dyn->string, *str); STRCMP_EQUAL("a", ptr_string_dyn->string); STRCMP_EQUAL("a", *str); - LONGS_EQUAL(1, string_dyn_concat (str, "bcd")); + LONGS_EQUAL(1, string_dyn_concat (str, "bcd", -1)); LONGS_EQUAL(5, ptr_string_dyn->size_alloc); LONGS_EQUAL(5, ptr_string_dyn->size); POINTERS_EQUAL(ptr_string_dyn->string, *str); STRCMP_EQUAL("abcd", ptr_string_dyn->string); STRCMP_EQUAL("abcd", *str); - LONGS_EQUAL(1, string_dyn_concat (str, "e")); + LONGS_EQUAL(1, string_dyn_concat (str, "e", -1)); LONGS_EQUAL(7, ptr_string_dyn->size_alloc); LONGS_EQUAL(6, ptr_string_dyn->size); POINTERS_EQUAL(ptr_string_dyn->string, *str); STRCMP_EQUAL("abcde", ptr_string_dyn->string); STRCMP_EQUAL("abcde", *str); - LONGS_EQUAL(1, string_dyn_concat (str, "fg")); + LONGS_EQUAL(1, string_dyn_concat (str, "fg", -1)); LONGS_EQUAL(10, ptr_string_dyn->size_alloc); LONGS_EQUAL(8, ptr_string_dyn->size); POINTERS_EQUAL(ptr_string_dyn->string, *str); STRCMP_EQUAL("abcdefg", ptr_string_dyn->string); STRCMP_EQUAL("abcdefg", *str); + string_dyn_free (str, 1); + + str = string_dyn_alloc (1); + ptr_string_dyn = (struct t_string_dyn *)str; + + /* check concat with some strings and fixed length */ + LONGS_EQUAL(1, string_dyn_copy (str, "abcd")); + LONGS_EQUAL(1, string_dyn_concat (str, "xyz", 0)); + LONGS_EQUAL(5, ptr_string_dyn->size_alloc); + LONGS_EQUAL(5, ptr_string_dyn->size); + POINTERS_EQUAL(ptr_string_dyn->string, *str); + STRCMP_EQUAL("abcd", ptr_string_dyn->string); + STRCMP_EQUAL("abcd", *str); + + LONGS_EQUAL(1, string_dyn_concat (str, "xyz", 1)); + LONGS_EQUAL(7, ptr_string_dyn->size_alloc); + LONGS_EQUAL(6, ptr_string_dyn->size); + POINTERS_EQUAL(ptr_string_dyn->string, *str); + STRCMP_EQUAL("abcdx", ptr_string_dyn->string); + STRCMP_EQUAL("abcdx", *str); + + LONGS_EQUAL(1, string_dyn_concat (str, "xyz", 2)); + LONGS_EQUAL(10, ptr_string_dyn->size_alloc); + LONGS_EQUAL(8, ptr_string_dyn->size); + POINTERS_EQUAL(ptr_string_dyn->string, *str); + STRCMP_EQUAL("abcdxxy", ptr_string_dyn->string); + STRCMP_EQUAL("abcdxxy", *str); + + LONGS_EQUAL(1, string_dyn_concat (str, "xyz", 3)); + LONGS_EQUAL(15, ptr_string_dyn->size_alloc); + LONGS_EQUAL(11, ptr_string_dyn->size); + POINTERS_EQUAL(ptr_string_dyn->string, *str); + STRCMP_EQUAL("abcdxxyxyz", ptr_string_dyn->string); + STRCMP_EQUAL("abcdxxyxyz", *str); + str_ptr = *str; string_dyn_free (str, 0); - STRCMP_EQUAL("abcdefg", str_ptr); + STRCMP_EQUAL("abcdxxyxyz", str_ptr); free (str_ptr); }