mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
Create string_split_noalloc
This commit is contained in:
parent
a32d027f76
commit
6df62bbccc
@ -88,6 +88,9 @@ bool string_list_find_elem_prefix(const struct string_list *list,
|
|||||||
*/
|
*/
|
||||||
struct string_list *string_split(const char *str, const char *delim);
|
struct string_list *string_split(const char *str, const char *delim);
|
||||||
|
|
||||||
|
bool string_split_noalloc(struct string_list *list,
|
||||||
|
const char *str, const char *delim);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_separate:
|
* string_separate:
|
||||||
* @str : string to turn into a string list
|
* @str : string to turn into a string list
|
||||||
|
@ -286,7 +286,7 @@ struct string_list *string_split(const char *str, const char *delim)
|
|||||||
struct string_list *list = string_list_new();
|
struct string_list *list = string_list_new();
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
copy = strdup(str);
|
copy = strdup(str);
|
||||||
if (!copy)
|
if (!copy)
|
||||||
@ -314,6 +314,40 @@ error:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool string_split_noalloc(struct string_list *list,
|
||||||
|
const char *str, const char *delim)
|
||||||
|
{
|
||||||
|
char *save = NULL;
|
||||||
|
char *copy = NULL;
|
||||||
|
const char *tmp = NULL;
|
||||||
|
|
||||||
|
if (!list)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
copy = strdup(str);
|
||||||
|
if (!copy)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tmp = strtok_r(copy, delim, &save);
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
union string_list_elem_attr attr;
|
||||||
|
|
||||||
|
attr.i = 0;
|
||||||
|
|
||||||
|
if (!string_list_append(list, tmp, attr))
|
||||||
|
{
|
||||||
|
free(copy);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = strtok_r(NULL, delim, &save);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(copy);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_separate:
|
* string_separate:
|
||||||
* @str : string to turn into a string list
|
* @str : string to turn into a string list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user