mirror of
https://github.com/weechat/weechat.git
synced 2026-07-08 10:43:13 +02:00
api: add arguments "index_start" and "index_end" in function string_rebuild_split_string
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
+31
-12
@@ -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;
|
||||
}
|
||||
|
||||
result = malloc (length + 1);
|
||||
if (result)
|
||||
{
|
||||
result[0] = '\0';
|
||||
if (length == 0)
|
||||
return strdup ("");
|
||||
|
||||
for (i = 0; split_string[i]; i++)
|
||||
result = malloc (length + 1);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user