mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 18:46:18 +00:00
a/util: Add a new constructor and a new method to u_string_list
This commit is contained in:
parent
d057f00b54
commit
9b9e23be62
|
@ -58,6 +58,22 @@ u_string_list_create_from_list(struct u_string_list *usl)
|
|||
}
|
||||
}
|
||||
|
||||
struct u_string_list *
|
||||
u_string_list_create_from_array(const char *const *arr, uint32_t size)
|
||||
{
|
||||
if (arr == nullptr || size == 0) {
|
||||
return u_string_list_create();
|
||||
}
|
||||
try {
|
||||
auto ret = std::make_unique<u_string_list>(xrt::auxiliary::util::StringList{size});
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
ret->list.push_back(arr[i]);
|
||||
}
|
||||
return ret.release();
|
||||
} catch (std::exception const &) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
u_string_list_get_size(const struct u_string_list *usl)
|
||||
|
@ -95,6 +111,23 @@ u_string_list_append(struct u_string_list *usl, const char *str)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
u_string_list_append_array(struct u_string_list *usl, const char *const *arr, uint32_t size)
|
||||
{
|
||||
|
||||
if (usl == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
usl->list.push_back(arr[i]);
|
||||
}
|
||||
return 1;
|
||||
} catch (std::exception const &) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
u_string_list_append_unique(struct u_string_list *usl, const char *str)
|
||||
{
|
||||
|
|
|
@ -48,6 +48,18 @@ u_string_list_create_with_capacity(uint32_t capacity);
|
|||
struct u_string_list *
|
||||
u_string_list_create_from_list(struct u_string_list *usl);
|
||||
|
||||
/*!
|
||||
* @brief Create a new string list from an array of suitable strings.
|
||||
*
|
||||
* @param arr an array of zero or more non-null, null-terminated string that must live at least as long as the list,
|
||||
* preferably string literals.
|
||||
* @param size the number of elements in the array.
|
||||
*
|
||||
* @public @memberof u_string_list
|
||||
*/
|
||||
struct u_string_list *
|
||||
u_string_list_create_from_array(const char *const *arr, uint32_t size);
|
||||
|
||||
/*!
|
||||
* @brief Retrieve the number of elements in the list
|
||||
*
|
||||
|
@ -77,6 +89,21 @@ u_string_list_get_data(const struct u_string_list *usl);
|
|||
int
|
||||
u_string_list_append(struct u_string_list *usl, const char *str);
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Append an array of new string literals to the list.
|
||||
*
|
||||
* @param usl self pointer
|
||||
* @param arr an array of zero or more non-null, null-terminated string that must live at least as long as the list,
|
||||
* preferably string literals.
|
||||
* @param size the number of elements in the array.
|
||||
* @return 1 if successfully added, negative for errors.
|
||||
*
|
||||
* @public @memberof u_string_list
|
||||
*/
|
||||
int
|
||||
u_string_list_append_array(struct u_string_list *usl, const char *const *arr, uint32_t size);
|
||||
|
||||
/*!
|
||||
* @brief Append a new string literal to the list, if it's not the same as a string already in the list.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue