summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc2
-rw-r--r--ReleaseNotes.adoc16
-rw-r--r--doc/en/weechat_plugin_api.en.adoc16
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc19
-rw-r--r--doc/it/weechat_plugin_api.it.adoc21
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc20
-rw-r--r--doc/sr/weechat_plugin_api.sr.adoc20
-rw-r--r--src/core/hook/wee-hook-hsignal.c2
-rw-r--r--src/core/hook/wee-hook-line.c2
-rw-r--r--src/core/hook/wee-hook-signal.c2
-rw-r--r--src/core/wee-command.c2
-rw-r--r--src/core/wee-config-file.c2
-rw-r--r--src/core/wee-dir.c2
-rw-r--r--src/core/wee-input.c2
-rw-r--r--src/core/wee-string.c41
-rw-r--r--src/core/wee-string.h3
-rw-r--r--src/gui/gui-buffer.c6
-rw-r--r--src/gui/gui-filter.c3
-rw-r--r--src/gui/gui-focus.c3
-rw-r--r--src/plugins/fset/fset-option.c2
-rw-r--r--src/plugins/guile/weechat-guile-api.c2
-rw-r--r--src/plugins/irc/irc-mode.c2
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp2
-rw-r--r--src/plugins/lua/weechat-lua-api.c2
-rw-r--r--src/plugins/perl/weechat-perl-api.c2
-rw-r--r--src/plugins/python/weechat-python-api.c2
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c2
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c2
-rw-r--r--src/plugins/trigger/trigger-callback.c2
-rw-r--r--src/plugins/weechat-plugin.h13
-rw-r--r--tests/unit/core/test-core-string.cpp86
31 files changed, 240 insertions, 63 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 3399f4f9d..4f248539a 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -20,7 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
New features::
- * api: rename function string_build_with_split_string to string_rebuild_split_string
+ * api: rename function string_build_with_split_string to string_rebuild_split_string, add arguments "index_start" and "index_end"
* api: add info "uptime_current"
Bug fixes::
diff --git a/ReleaseNotes.adoc b/ReleaseNotes.adoc
index cb626cce6..8b0d45a94 100644
--- a/ReleaseNotes.adoc
+++ b/ReleaseNotes.adoc
@@ -17,6 +17,22 @@ https://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
(file _ChangeLog.adoc_ in sources).
+[[v3.7]]
+== Version 3.7 (under dev)
+
+[[v3.7_api_string_rebuild_split_string]]
+=== Function string_rebuild_split_string
+
+The API function string_build_with_split_string has been renamed to
+link:https://weechat.org/doc/plugin/#_string_rebuild_split_string[string_rebuild_split_string]
+and two new arguments have been added: _index_start_ and _index_end_.
+
+To stay compatible, the existing calls to the function must be done with the
+new function name and these values:
+
+* _index_start_: `0`
+* _index_end_: `-1`
+
[[v3.6]]
== Version 3.6 (2022-07-10)
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc
index 0434bf54f..8d857272d 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -1790,20 +1790,28 @@ This function is not available in scripting API.
==== string_rebuild_split_string
-Rebuild a string with a split string.
+_Updated in 3.7._
+
+Rebuild a string with a split string, using optional separator and index of
+first/last string to use.
Prototype:
[source,c]
----
char *weechat_string_rebuild_split_string (char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
----
Arguments:
* _split_string_: string split by function <<_string_split,string_split>>
-* _separator_: string used to separate strings
+* _separator_: string used to separate strings (can be NULL or empty string)
+* _index_start_: index of first string to use (≥ 0)
+* _index_end_: index of last string to use
+ (must be ≥ _index_start_; special value -1 can be used to use all arguments
+ until NULL is found)
Return value:
@@ -1816,7 +1824,7 @@ C example:
char **argv;
int argc;
argv = weechat_string_split ("abc def ghi", " ", 0, 0, &argc);
-char *str = weechat_string_rebuild_split_string (argv, ";");
+char *str = weechat_string_rebuild_split_string (argv, ";", 0, -1);
/* str == "abc;def;ghi" */
/* ... */
free (str);
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index c978d7175..df324b4ad 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -1822,20 +1822,29 @@ Cette fonction n'est pas disponible dans l'API script.
==== string_rebuild_split_string
-Reconstruire une chaîne à partir d'une chaîne découpée.
+_Mis à jour dans la 3.7._
+
+Reconstruire une chaîne à partir d'une chaîne découpée, d'un séparateur facultatif
+et d'un index de première/dernière chaîne à utiliser.
Prototype :
[source,c]
----
-char *weechat_string_rebuild_split_string (char **split_string
- const char *separator);
+char *weechat_string_rebuild_split_string (char **split_string,
+ const char *separator,
+ int index_start, int index_end);
----
Paramètres :
* _split_string_ : chaîne découpée par la fonction <<_string_split,string_split>>
-* _separator_ : chaîne utilisée pour séparer les différentes chaînes
+* _separator_ : chaîne utilisée pour séparer les différentes chaînes (peut être
+ NULL ou une chaîne vide)
+* _index_start_ : index de la première chaîne à utiliser (≥ 0)
+* _index_end_ : index de la dernière chaîne à utiliser (doit être ≥ _index_start_ ;
+ la valeur spéciale -1 peut être utilisée pour utiliser toutes les chaînes
+ jusqu'à ce que NULL soit trouvé)
Valeur de retour :
@@ -1849,7 +1858,7 @@ Exemple en C :
char **argv;
int argc;
argv = weechat_string_split ("abc def ghi", " ", 0, 0, &argc);
-char *str = weechat_string_rebuild_split_string (argv, ";");
+char *str = weechat_string_rebuild_split_string (argv, ";", 0, -1);
/* str == "abc;def;ghi" */
/* ... */
free (str);
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index 7b2ae3e40..250289be9 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -1873,20 +1873,33 @@ Questa funzione non è disponibile nelle API per lo scripting.
==== string_rebuild_split_string
-Compila una stringa con una stringa divisa.
+// TRANSLATION MISSING
+_Updated in 3.7._
+
+// TRANSLATION MISSING
+Rebuild a string with a split string, using optional separator and index of
+first/last string to use.
Prototipo:
[source,c]
----
char *weechat_string_rebuild_split_string (char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
----
Argomenti:
* _split_string_: stringa divisa dalla funzione <<_string_split,string_split>>
-* _separator_: stringa usata per separare le stringhe
+// TRANSLATION MISSING
+* _separator_: string used to separate strings (can be NULL or empty string)
+// TRANSLATION MISSING
+* _index_start_: index of first string to use (≥ 0)
+// TRANSLATION MISSING
+* _index_end_: index of last string to use
+ (must be ≥ _index_start_; special value -1 can be used to use all arguments
+ until NULL is found)
Valore restituito:
@@ -1900,7 +1913,7 @@ Esempio in C:
char **argv;
int argc;
argv = weechat_string_split ("abc def ghi", " ", 0, 0, &argc);
-char *str = weechat_string_rebuild_split_string (argv, ";");
+char *str = weechat_string_rebuild_split_string (argv, ";", 0, -1);
/* str == "abc;def;ghi" */
/* ... */
free (str);
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index 0254abc38..5f72dafcb 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -1811,21 +1811,33 @@ weechat_string_free_split (argv);
==== string_rebuild_split_string
-分割文字列から文字列を作る。
+_WeeChat バージョン 3.7 で更新。_
+
+// TRANSLATION MISSING
+Rebuild a string with a split string, using optional separator and index of
+first/last string to use.
プロトタイプ:
[source,c]
----
char *weechat_string_rebuild_split_string (char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
----
引数:
* _split_string_: 関数 <<_string_split,string_split>>
が返した分割文字列の配列
-* _separator_: 文字列を分割する区切り文字
+// TRANSLATION MISSING
+* _separator_: string used to separate strings (can be NULL or empty string)
+// TRANSLATION MISSING
+* _index_start_: index of first string to use (≥ 0)
+// TRANSLATION MISSING
+* _index_end_: index of last string to use
+ (must be ≥ _index_start_; special value -1 can be used to use all arguments
+ until NULL is found)
戻り値:
@@ -1838,7 +1850,7 @@ C 言語での使用例:
char **argv;
int argc;
argv = weechat_string_split ("abc def ghi", " ", 0, 0, &argc);
-char *str = weechat_string_rebuild_split_string (argv, ";");
+char *str = weechat_string_rebuild_split_string (argv, ";", 0, -1);
/* str == "abc;def;ghi" */
/* ... */
free (str);
diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc
index c3a8e182b..b3abeb02c 100644
--- a/doc/sr/weechat_plugin_api.sr.adoc
+++ b/doc/sr/weechat_plugin_api.sr.adoc
@@ -1713,20 +1713,32 @@ weechat_string_free_split (argv);
==== string_rebuild_split_string
-Изграђује стринг од подељеног стринга.
+_Ажурирано у верзији 3.7._
+
+// TRANSLATION MISSING
+Rebuild a string with a split string, using optional separator and index of
+first/last string to use.
Прототип:
[source,c]
----
char *weechat_string_rebuild_split_string (char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
----
Аргументи:
* _split_string_: стринг подељен функцијом <<_string_split,string_split>>
-* _separator_: стринг који се користи за раздвајање стрингова
+// TRANSLATION MISSING
+* _separator_: string used to separate strings (can be NULL or empty string)
+// TRANSLATION MISSING
+* _index_start_: index of first string to use (≥ 0)
+// TRANSLATION MISSING
+* _index_end_: index of last string to use
+ (must be ≥ _index_start_; special value -1 can be used to use all arguments
+ until NULL is found)
Повратна вредност:
@@ -1739,7 +1751,7 @@ C пример:
char **argv;
int argc;
argv = weechat_string_split ("abc def ghi", " ", 0, 0, &argc);
-char *str = weechat_string_rebuild_split_string (argv, ";");
+char *str = weechat_string_rebuild_split_string (argv, ";", 0, -1);
/* str == "abc;def;ghi" */
/* ... */
free (str);
diff --git a/src/core/hook/wee-hook-hsignal.c b/src/core/hook/wee-hook-hsignal.c
index 37dfa32a8..505336688 100644
--- a/src/core/hook/wee-hook-hsignal.c
+++ b/src/core/hook/wee-hook-hsignal.c
@@ -44,7 +44,7 @@ char *
hook_hsignal_get_description (struct t_hook *hook)
{
return string_rebuild_split_string (
- (const char **)(HOOK_HSIGNAL(hook, signals)), ";");
+ (const char **)(HOOK_HSIGNAL(hook, signals)), ";", 0, -1);
}
/*
diff --git a/src/core/hook/wee-hook-line.c b/src/core/hook/wee-hook-line.c
index fa787eba1..00bd7f138 100644
--- a/src/core/hook/wee-hook-line.c
+++ b/src/core/hook/wee-hook-line.c
@@ -167,7 +167,7 @@ hook_line_exec (struct t_gui_line *line)
HASHTABLE_SET_STR_NOT_NULL("str_time", line->data->str_time);
HASHTABLE_SET_INT("tags_count", line->data->tags_count);
str_tags = string_rebuild_split_string (
- (const char **)line->data->tags_array, ",");
+ (const char **)line->data->tags_array, ",", 0, -1);
HASHTABLE_SET_STR_NOT_NULL("tags", str_tags);
if (str_tags)
free (str_tags);
diff --git a/src/core/hook/wee-hook-signal.c b/src/core/hook/wee-hook-signal.c
index 9cd72efcb..f08f20550 100644
--- a/src/core/hook/wee-hook-signal.c
+++ b/src/core/hook/wee-hook-signal.c
@@ -44,7 +44,7 @@ char *
hook_signal_get_description (struct t_hook *hook)
{
return string_rebuild_split_string (
- (const char **)(HOOK_SIGNAL(hook, signals)), ";");
+ (const char **)(HOOK_SIGNAL(hook, signals)), ";", 0, -1);
}
/*
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index a34ef109d..5006b67be 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -5583,7 +5583,7 @@ COMMAND_CALLBACK(repeat)
repeat_args[1] = strdup (argv_eol[arg_count + 1]);
repeat_args[2] = (input_commands_allowed) ?
string_rebuild_split_string (
- (const char **)input_commands_allowed, ",") : NULL;
+ (const char **)input_commands_allowed, ",", 0, -1) : NULL;
hook_timer (NULL, interval, 0, count - 1,
&command_repeat_timer_cb, repeat_args, NULL);
}
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index 68a1d457a..297c20b6b 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -3388,7 +3388,7 @@ config_file_add_option_to_infolist (struct t_infolist *infolist,
goto error;
}
string_values = string_rebuild_split_string (
- (const char **)option->string_values, "|");
+ (const char **)option->string_values, "|", 0, -1);
if (!infolist_new_var_string (ptr_item, "string_values", string_values))
{
if (string_values)
diff --git a/src/core/wee-dir.c b/src/core/wee-dir.c
index e0a0a7361..7a0b702e0 100644
--- a/src/core/wee-dir.c
+++ b/src/core/wee-dir.c
@@ -1036,5 +1036,5 @@ dir_get_string_home_dirs ()
dirs[3] = weechat_runtime_dir;
dirs[4] = NULL;
- return string_rebuild_split_string ((const char **)dirs, ":");
+ return string_rebuild_split_string ((const char **)dirs, ":", 0, -1);
}
diff --git a/src/core/wee-input.c b/src/core/wee-input.c
index 3635ffce4..e635e8dfc 100644
--- a/src/core/wee-input.c
+++ b/src/core/wee-input.c
@@ -428,7 +428,7 @@ input_data_delayed (struct t_gui_buffer *buffer, const char *data,
else if (input_commands_allowed)
{
new_commands_allowed = string_rebuild_split_string (
- (const char **)input_commands_allowed, ",");
+ (const char **)input_commands_allowed, ",", 0, -1);
}
else
{
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 7d27ab367..e0f3af037 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -2445,39 +2445,58 @@ string_free_split_shared (char **split_string)
}
/*
- * Rebuilds a split string using a delimiter.
+ * Rebuilds a split string using a delimiter and optional index of start/end
+ * string.
+ *
+ * If index_end < 0, then all arguments are used until NULL is found.
+ * If NULL is found before index_end, then the build stops there (at NULL).
*
* Note: result must be free after use.
*/
char *
string_rebuild_split_string (const char **split_string,
- const char *separator)
+ const char *separator,
+ int index_start, int index_end)
{
int i, length, length_separator;
char *result;
- if (!split_string)
+ if (!split_string || (index_start < 0)
+ || ((index_end >= 0) && (index_end < index_start)))
+ {
return NULL;
+ }
length = 0;
length_separator = (separator) ? strlen (separator) : 0;
for (i = 0; split_string[i]; i++)
{
- length += strlen (split_string[i]) + length_separator;
+ if ((index_end >= 0) && (i > index_end))
+ break;
+ if (i >= index_start)
+ length += strlen (split_string[i]) + length_separator;
}
+ if (length == 0)
+ return strdup ("");
+
result = malloc (length + 1);
- if (result)
- {
- result[0] = '\0';
+ if (!result)
+ return NULL;
- for (i = 0; split_string[i]; i++)
+ result[0] = '\0';
+
+ for (i = index_start; split_string[i]; i++)
+ {
+ if ((index_end >= 0) && (i > index_end))
+ break;
+ strcat (result, split_string[i]);
+ if (separator && ((index_end < 0) || (i + 1 <= index_end))
+ && split_string[i + 1])
{
- strcat (result, split_string[i]);
- if (separator && split_string[i + 1])
- strcat (result, separator);
+ strcat (result, separator);
}
}
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index 450829db1..abf65b8c1 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -97,7 +97,8 @@ extern char **string_split_shell (const char *string, int *num_items);
extern void string_free_split (char **split_string);
extern void string_free_split_shared (char **split_string);
extern char *string_rebuild_split_string (const char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
extern char **string_split_command (const char *command, char separator);
extern void string_free_split_command (char **split_command);
extern char ***string_split_tags (const char *tags, int *num_tags);
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index cb9c46562..889b86a6b 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -4703,7 +4703,8 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer)
if (message_without_colors)
free (message_without_colors);
tags = string_rebuild_split_string ((const char **)ptr_line->data->tags_array,
- ",");
+ ",",
+ 0, -1);
log_printf (" tags: '%s', displayed: %d, highlight: %d",
(tags) ? tags : "(none)",
ptr_line->data->displayed,
@@ -4921,7 +4922,8 @@ gui_buffer_print_log ()
{
num--;
tags = string_rebuild_split_string ((const char **)ptr_line->data->tags_array,
- ",");
+ ",",
+ 0, -1);
log_printf (" line N-%05d: y:%d, str_time:'%s', tags:'%s', "
"displayed:%d, highlight:%d, refresh_needed:%d, "
"prefix:'%s'",
diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c
index e5d877706..356770879 100644
--- a/src/gui/gui-filter.c
+++ b/src/gui/gui-filter.c
@@ -593,7 +593,8 @@ gui_filter_add_to_infolist (struct t_infolist *infolist,
{
snprintf (option_name, sizeof (option_name), "tag_%05d", i + 1);
tags = string_rebuild_split_string ((const char **)filter->tags_array[i],
- "+");
+ "+",
+ 0, -1);
if (tags)
{
if (!infolist_new_var_string (ptr_item, option_name, tags))
diff --git a/src/gui/gui-focus.c b/src/gui/gui-focus.c
index a57b5a7a9..3e57a0408 100644
--- a/src/gui/gui-focus.c
+++ b/src/gui/gui-focus.c
@@ -201,7 +201,8 @@ gui_focus_to_hashtable (struct t_gui_focus_info *focus_info, const char *key)
{
str_time = gui_color_decode (((focus_info->chat_line)->data)->str_time, NULL);
str_prefix = gui_color_decode (((focus_info->chat_line)->data)->prefix, NULL);
- str_tags = string_rebuild_split_string ((const char **)((focus_info->chat_line)->data)->tags_array, ",");
+ str_tags = string_rebuild_split_string (
+ (const char **)((focus_info->chat_line)->data)->tags_array, ",", 0, -1);
str_message = gui_color_decode (((focus_info->chat_line)->data)->message, NULL);
nick = gui_line_get_nick_tag (focus_info->chat_line);
HASHTABLE_SET_POINTER("_chat_line", focus_info->chat_line);
diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c
index ce2a02a0e..2ee03a7b9 100644
--- a/src/plugins/fset/fset-option.c
+++ b/src/plugins/fset/fset-option.c
@@ -571,7 +571,7 @@ fset_option_set_values (struct t_fset_option *fset_option,
if (ptr_string_values)
{
fset_option->string_values = weechat_string_rebuild_split_string (
- ptr_string_values, ",");
+ ptr_string_values, ",", 0, -1);
}
else
{
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index 5d1309990..e847f6167 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -2601,7 +2601,7 @@ weechat_guile_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c
index 7174bce24..4fe3f7187 100644
--- a/src/plugins/irc/irc-mode.c
+++ b/src/plugins/irc/irc-mode.c
@@ -69,7 +69,7 @@ irc_mode_get_arguments (const char *arguments)
argv2[argc] = NULL;
new_arguments = weechat_string_rebuild_split_string (
- (const char **)argv2, " ");
+ (const char **)argv2, " ", 0, -1);
weechat_string_free_split (argv);
free (argv2);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index 8c0e95b6c..271108387 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -2521,7 +2521,7 @@ weechat_js_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index fdbe2ed13..678061137 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -2736,7 +2736,7 @@ weechat_lua_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index c3b70d5cf..895730620 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -2631,7 +2631,7 @@ weechat_perl_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index dbbe6d1e0..3bacf63f7 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -2642,7 +2642,7 @@ weechat_python_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index 74f240a83..8bad2f8e2 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -3216,7 +3216,7 @@ weechat_ruby_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index 0eee83317..6e4d2b1d5 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -2936,7 +2936,7 @@ weechat_tcl_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c
index 0659911f4..b5bc3585c 100644
--- a/src/plugins/trigger/trigger-callback.c
+++ b/src/plugins/trigger/trigger-callback.c
@@ -1030,7 +1030,7 @@ trigger_callback_print_cb (const void *pointer, void *data,
free (str_no_color);
}
- str_tags = weechat_string_rebuild_split_string (tags, ",");
+ str_tags = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (str_tags)
{
/* build string with tags and commas around: ",tag1,tag2,tag3," */
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 8146031d8..43e04964c 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -68,7 +68,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 "20220720-01"
+#define WEECHAT_PLUGIN_API_VERSION "20220720-02"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -333,7 +333,8 @@ struct t_weechat_plugin
char **(*string_split_shell) (const char *string, int *num_items);
void (*string_free_split) (char **split_string);
char *(*string_rebuild_split_string) (const char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
char **(*string_split_command) (const char *command, char separator);
void (*string_free_split_command) (char **split_command);
char *(*string_format_size) (unsigned long long size);
@@ -1286,9 +1287,13 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
#define weechat_string_free_split(__split_string) \
(weechat_plugin->string_free_split)(__split_string)
#define weechat_string_rebuild_split_string(__split_string, \
- __separator) \
+ __separator, \
+ __index_start, \
+ __index_end) \
(weechat_plugin->string_rebuild_split_string)(__split_string, \
- __separator)
+ __separator, \
+ __index_start, \
+ __index_end)
#define weechat_string_split_command(__command, __separator) \
(weechat_plugin->string_split_command)(__command, __separator)
#define weechat_string_free_split_command(__split_command) \
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index f14e572a6..5639d2aae 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -1708,7 +1708,7 @@ TEST(CoreString, RebuildSplitString)
char **argv, *str;
int argc, flags;
- str = string_rebuild_split_string (NULL, NULL);
+ str = string_rebuild_split_string (NULL, NULL, 0, -1);
POINTERS_EQUAL(NULL, str);
flags = WEECHAT_STRING_SPLIT_STRIP_LEFT
@@ -1716,18 +1716,96 @@ TEST(CoreString, RebuildSplitString)
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS;
argv = string_split (" abc de fghi ", " ", NULL, flags, 0, &argc);
- str = string_rebuild_split_string ((const char **)argv, NULL);
+ /* invalid index_end, which is < index_start */
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 0);
+ POINTERS_EQUAL(NULL, str);
+ str = string_rebuild_split_string ((const char **)argv, NULL, 2, 1);
+ POINTERS_EQUAL(NULL, str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, -1);
+ STRCMP_EQUAL("abcdefghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 0);
+ STRCMP_EQUAL("abc", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 1);
+ STRCMP_EQUAL("abcde", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 2);
STRCMP_EQUAL("abcdefghi", str);
free (str);
- str = string_rebuild_split_string ((const char **)argv, "");
+ str = string_rebuild_split_string ((const char **)argv, NULL, 0, 3);
STRCMP_EQUAL("abcdefghi", str);
free (str);
- str = string_rebuild_split_string ((const char **)argv, ";;");
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 1);
+ STRCMP_EQUAL("de", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 2);
+ STRCMP_EQUAL("defghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 1, 3);
+ STRCMP_EQUAL("defghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 2, 2);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, NULL, 2, 3);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, "", 0, -1);
+ STRCMP_EQUAL("abcdefghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, -1);
+ STRCMP_EQUAL("abc;;de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 0);
+ STRCMP_EQUAL("abc", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 1);
+ STRCMP_EQUAL("abc;;de", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 2);
+ STRCMP_EQUAL("abc;;de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 0, 3);
STRCMP_EQUAL("abc;;de;;fghi", str);
free (str);
+ str = string_rebuild_split_string ((const char **)argv, ";;", 1, 1);
+ STRCMP_EQUAL("de", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 1, 2);
+ STRCMP_EQUAL("de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 1, 3);
+ STRCMP_EQUAL("de;;fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 2, 2);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
+ str = string_rebuild_split_string ((const char **)argv, ";;", 2, 3);
+ STRCMP_EQUAL("fghi", str);
+ free (str);
+
string_free_split (argv);
}