mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
(SDK) Add documentation to string_list
This commit is contained in:
parent
f2be2ddc0c
commit
c255387282
@ -51,23 +51,93 @@ struct string_list
|
||||
size_t cap;
|
||||
};
|
||||
|
||||
/**
|
||||
* string_list_find_elem:
|
||||
* @list : pointer to string list
|
||||
* @elem : element to find inside the string list.
|
||||
*
|
||||
* Searches for an element (@elem) inside the string list.
|
||||
*
|
||||
* Returns: true (1) if element could be found, otherwise false (0).
|
||||
*/
|
||||
bool string_list_find_elem(const struct string_list *list, const char *elem);
|
||||
|
||||
/**
|
||||
* string_list_find_elem_prefix:
|
||||
* @list : pointer to string list
|
||||
* @prefix : prefix to append to @elem
|
||||
* @elem : element to find inside the string list.
|
||||
*
|
||||
* Searches for an element (@elem) inside the string list. Will
|
||||
* also search for the same element prefixed by @prefix.
|
||||
*
|
||||
* Returns: true (1) if element could be found, otherwise false (0).
|
||||
*/
|
||||
bool string_list_find_elem_prefix(const struct string_list *list,
|
||||
const char *prefix, const char *elem);
|
||||
|
||||
/**
|
||||
* string_split:
|
||||
* @str : string to turn into a string list
|
||||
* @delim : delimiter character to use for splitting the string.
|
||||
*
|
||||
* Creates a new string list based on string @str, delimited by @delim.
|
||||
*
|
||||
* Returns: new string list if successful, otherwise NULL.
|
||||
*/
|
||||
struct string_list *string_split(const char *str, const char *delim);
|
||||
|
||||
/**
|
||||
* string_list_new:
|
||||
*
|
||||
* Creates a new string list. Has to be freed manually.
|
||||
*
|
||||
* Returns: new string list if successful, otherwise NULL.
|
||||
*/
|
||||
struct string_list *string_list_new(void);
|
||||
|
||||
/**
|
||||
* string_list_append:
|
||||
* @list : pointer to string list
|
||||
* @elem : element to add to the string list
|
||||
* @attr : attributes of new element.
|
||||
*
|
||||
* Appends a new element to the string list.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool string_list_append(struct string_list *list, const char *elem,
|
||||
union string_list_elem_attr attr);
|
||||
|
||||
/**
|
||||
* string_list_free
|
||||
* @list : pointer to string list object
|
||||
*
|
||||
* Frees a string list.
|
||||
*/
|
||||
void string_list_free(struct string_list *list);
|
||||
|
||||
/**
|
||||
* string_list_join_concat:
|
||||
* @buffer : buffer that @list will be joined to.
|
||||
* @size : length of @buffer.
|
||||
* @list : pointer to string list.
|
||||
* @delim : delimiter character for @list.
|
||||
*
|
||||
* A string list will be joined/concatenated as a
|
||||
* string to @buffer, delimited by @delim.
|
||||
*/
|
||||
void string_list_join_concat(char *buffer, size_t size,
|
||||
const struct string_list *list, const char *sep);
|
||||
|
||||
/**
|
||||
* string_list_set:
|
||||
* @list : pointer to string list
|
||||
* @idx : index of element in string list
|
||||
* @str : value for the element.
|
||||
*
|
||||
* Set value of element inside string list.
|
||||
**/
|
||||
void string_list_set(struct string_list *list, unsigned idx,
|
||||
const char *str);
|
||||
|
||||
|
@ -28,6 +28,12 @@
|
||||
#include <compat/strl.h>
|
||||
#include <compat/posix_string.h>
|
||||
|
||||
/**
|
||||
* string_list_free
|
||||
* @list : pointer to string list object
|
||||
*
|
||||
* Frees a string list.
|
||||
*/
|
||||
void string_list_free(struct string_list *list)
|
||||
{
|
||||
size_t i;
|
||||
@ -40,6 +46,15 @@ void string_list_free(struct string_list *list)
|
||||
free(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_capacity:
|
||||
* @list : pointer to string list
|
||||
* @cap : new capacity for string list.
|
||||
*
|
||||
* Change maximum capacity of string list's size.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
static bool string_list_capacity(struct string_list *list, size_t cap)
|
||||
{
|
||||
struct string_list_elem *new_data = NULL;
|
||||
@ -56,6 +71,13 @@ static bool string_list_capacity(struct string_list *list, size_t cap)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_new:
|
||||
*
|
||||
* Creates a new string list. Has to be freed manually.
|
||||
*
|
||||
* Returns: new string list if successful, otherwise NULL.
|
||||
*/
|
||||
struct string_list *string_list_new(void)
|
||||
{
|
||||
struct string_list *list = (struct string_list*)
|
||||
@ -73,6 +95,16 @@ struct string_list *string_list_new(void)
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_append:
|
||||
* @list : pointer to string list
|
||||
* @elem : element to add to the string list
|
||||
* @attr : attributes of new element.
|
||||
*
|
||||
* Appends a new element to the string list.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool string_list_append(struct string_list *list, const char *elem,
|
||||
union string_list_elem_attr attr)
|
||||
{
|
||||
@ -92,6 +124,14 @@ bool string_list_append(struct string_list *list, const char *elem,
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_set:
|
||||
* @list : pointer to string list
|
||||
* @idx : index of element in string list
|
||||
* @str : value for the element.
|
||||
*
|
||||
* Set value of element inside string list.
|
||||
**/
|
||||
void string_list_set(struct string_list *list,
|
||||
unsigned idx, const char *str)
|
||||
{
|
||||
@ -99,10 +139,21 @@ void string_list_set(struct string_list *list,
|
||||
rarch_assert(list->elems[idx].data = strdup(str));
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_join_concat:
|
||||
* @buffer : buffer that @list will be joined to.
|
||||
* @size : length of @buffer.
|
||||
* @list : pointer to string list.
|
||||
* @delim : delimiter character for @list.
|
||||
*
|
||||
* A string list will be joined/concatenated as a
|
||||
* string to @buffer, delimited by @delim.
|
||||
*/
|
||||
void string_list_join_concat(char *buffer, size_t size,
|
||||
const struct string_list *list, const char *sep)
|
||||
const struct string_list *list, const char *delim)
|
||||
{
|
||||
size_t i, len = strlen(buffer);
|
||||
|
||||
rarch_assert(len < size);
|
||||
buffer += len;
|
||||
size -= len;
|
||||
@ -111,10 +162,19 @@ void string_list_join_concat(char *buffer, size_t size,
|
||||
{
|
||||
strlcat(buffer, list->elems[i].data, size);
|
||||
if ((i + 1) < list->size)
|
||||
strlcat(buffer, sep, size);
|
||||
strlcat(buffer, delim, size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* string_split:
|
||||
* @str : string to turn into a string list
|
||||
* @delim : delimiter character to use for splitting the string.
|
||||
*
|
||||
* Creates a new string list based on string @str, delimited by @delim.
|
||||
*
|
||||
* Returns: new string list if successful, otherwise NULL.
|
||||
*/
|
||||
struct string_list *string_split(const char *str, const char *delim)
|
||||
{
|
||||
char *save = NULL;
|
||||
@ -150,9 +210,19 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_find_elem:
|
||||
* @list : pointer to string list
|
||||
* @elem : element to find inside the string list.
|
||||
*
|
||||
* Searches for an element (@elem) inside the string list.
|
||||
*
|
||||
* Returns: true (1) if element could be found, otherwise false (0).
|
||||
*/
|
||||
bool string_list_find_elem(const struct string_list *list, const char *elem)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!list)
|
||||
return false;
|
||||
|
||||
@ -165,6 +235,17 @@ bool string_list_find_elem(const struct string_list *list, const char *elem)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* string_list_find_elem_prefix:
|
||||
* @list : pointer to string list
|
||||
* @prefix : prefix to append to @elem
|
||||
* @elem : element to find inside the string list.
|
||||
*
|
||||
* Searches for an element (@elem) inside the string list. Will
|
||||
* also search for the same element prefixed by @prefix.
|
||||
*
|
||||
* Returns: true (1) if element could be found, otherwise false (0).
|
||||
*/
|
||||
bool string_list_find_elem_prefix(const struct string_list *list,
|
||||
const char *prefix, const char *elem)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user