19 if (stringList != NULL)
21 stringList->strings = NULL;
22 stringList->strings_count = 0;
23 stringList->allocated_count = 0;
32 if (stringList != NULL)
34 if (stringList->strings != NULL && stringList->strings_count != 0)
36 for (
size_t index = 0; index < stringList->strings_count; index++)
38 free((
void *)stringList->strings[index]);
40 free(stringList->strings);
51 bool stringAdded =
false;
53 if (stringList != NULL &&
string != NULL)
55 const char** new_list = NULL;
56 if (stringList->strings == NULL)
58 new_list = malloc(
sizeof(
const char*));
59 stringList->allocated_count = 1;
61 else if (stringList->strings_count < stringList->allocated_count)
63 new_list = stringList->strings;
67 size_t newCount = stringList->allocated_count + 1;
68 new_list = realloc(stringList->strings, newCount *
sizeof(
const char*));
69 stringList->allocated_count = newCount;
74 stringList->strings = new_list;
75 char* newString =
STRDUP(
string);
76 if (newString != NULL)
78 stringList->strings[stringList->strings_count] = newString;
79 stringList->strings_count++;
92 bool stringsAdded =
false;
94 if (stringList != NULL && strings != NULL)
96 const char** new_list = NULL;
97 if (stringList->strings == NULL)
99 new_list = calloc(numStrings,
sizeof(
const char*));
100 stringList->allocated_count = numStrings;
102 else if ((stringList->strings_count + numStrings) < stringList->allocated_count)
104 new_list = stringList->strings;
108 size_t newCount = stringList->allocated_count + numStrings;
109 new_list = realloc(stringList->strings, newCount *
sizeof(
const char*));
110 stringList->allocated_count = newCount;
112 if (new_list != NULL)
115 stringList->strings = new_list;
116 size_t offset = stringList->strings_count;
117 for (
size_t index = 0; index < numStrings; index++)
119 char *newString =
STRDUP(strings[index]);
120 if (newString == NULL)
122 stringsAdded =
false;
125 stringList->strings[offset + index] = newString;
126 stringList->strings_count++;
139 if (stringList != NULL && stringList->strings != NULL)
141 if (removeIndex >= 0 && (
size_t)removeIndex < stringList->strings_count)
143 const char* stringToRemove = stringList->strings[removeIndex];
144 for (
size_t stringIndex = removeIndex; stringIndex < stringList->allocated_count - 1; stringIndex++)
146 stringList->strings[stringIndex] = stringList->strings[stringIndex + 1];
148 stringList->strings_count--;
149 free((
char*)stringToRemove);
161 if (stringList != NULL &&
string != NULL)
163 for (
size_t index = 0; index < stringList->strings_count; index++)
165 if (strcmp(
string, stringList->strings[index]) == 0)
167 foundIndex = (int)index;
Declaration of the StringList and StringListW typedefs for declaring a vector of strings.
std::vector< std::string > StringList
Typedef for a vector of std::string.
Declaration of the STRDUP macro that hides the differences between how strdup() is declared in differ...
#define STRDUP
Define STRDUP to be the operating system-specific version of strdup().
void StringList_Clear(StringList *stringList)
Clear the specified string list. All strings in the list are released. The string list can then be us...
bool StringList_AddStrings(StringList *stringList, const char **strings, size_t numStrings)
Add an array of strings to the given string list.
int StringList_Find(StringList *stringList, const char *string)
Search the given string list for the given string. If found, return the index of the found string.
void StringList_Initialize(StringList *stringList)
Initialize the given string list.
void StringList_Remove(StringList *stringList, int removeIndex)
Remove the specified string from the given string list.
bool StringList_AddString(StringList *stringList, const char *string)
Add a string to the given string list.