2024-11-28 17:39:34 +00:00
|
|
|
#ifndef RSTRING_LIST_H
|
|
|
|
#define RSTRING_LIST_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-11-29 06:24:30 +00:00
|
|
|
|
|
|
|
|
2024-11-28 17:39:34 +00:00
|
|
|
typedef struct rstring_list_t {
|
2024-11-29 06:24:30 +00:00
|
|
|
unsigned long long size;
|
|
|
|
unsigned long long count;
|
2024-11-28 17:39:34 +00:00
|
|
|
char **strings;
|
|
|
|
} rstring_list_t;
|
|
|
|
|
|
|
|
rstring_list_t *rstring_list_new() {
|
|
|
|
rstring_list_t *rsl = (rstring_list_t *)malloc(sizeof(rstring_list_t));
|
|
|
|
memset(rsl, 0, sizeof(rstring_list_t));
|
|
|
|
return rsl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rstring_list_free(rstring_list_t *rsl) {
|
2024-11-29 06:24:30 +00:00
|
|
|
for (unsigned long long i = 0; i < rsl->size; i++) {
|
2024-11-28 17:39:34 +00:00
|
|
|
free(rsl->strings[i]);
|
|
|
|
}
|
|
|
|
if (rsl->strings)
|
|
|
|
free(rsl->strings);
|
|
|
|
free(rsl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rstring_list_add(rstring_list_t *rsl, char *str) {
|
|
|
|
if (rsl->count == rsl->size) {
|
|
|
|
rsl->size++;
|
|
|
|
rsl->strings = (char **)realloc(rsl->strings, sizeof(char *) * rsl->size);
|
|
|
|
}
|
|
|
|
rsl->strings[rsl->count] = strdup(str);
|
|
|
|
rsl->count++;
|
|
|
|
}
|
|
|
|
bool rstring_list_contains(rstring_list_t *rsl, char *str) {
|
2024-11-29 06:24:30 +00:00
|
|
|
for (unsigned long long i = 0; i < rsl->count; i++) {
|
2024-11-28 17:39:34 +00:00
|
|
|
if (!strcmp(rsl->strings[i], str))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|