Design Pattern Examples
Overview of object-oriented design patterns
stringlist.c File Reference

Implementation of the supporting functions for the StringList structure that works with a list of allocated strings. More...

#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include "strdup.h"
#include "stringlist.h"
Include dependency graph for stringlist.c:

Go to the source code of this file.

Functions

void StringList_Initialize (StringList *stringList)
 Initialize the given string list.
 
void StringList_Clear (StringList *stringList)
 Clear the specified string list. All strings in the list are released. The string list can then be used to add new strings.
 
bool StringList_AddString (StringList *stringList, const char *string)
 Add a string to the given string list.
 
bool StringList_AddStrings (StringList *stringList, const char **strings, size_t numStrings)
 Add an array of strings to the given string list.
 
void StringList_Remove (StringList *stringList, int removeIndex)
 Remove the specified string from 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.
 

Detailed Description

Implementation of the supporting functions for the StringList structure that works with a list of allocated strings.

Definition in file stringlist.c.

Function Documentation

◆ StringList_AddString()

bool StringList_AddString ( StringList stringList,
const char *  string 
)

Add a string to the given string list.

Parameters
stringListA pointer to a StringList representing the list of strings.
stringThe string to add to the list. The string is duplicated and appended to the list.
Returns
Returns true if the string was added to the list; otherwise, returns false, indicating an out of memory condition has occurred (the original string list is untouched in this case).

Definition at line 49 of file stringlist.c.

References STRDUP.

Referenced by Group_AddUser(), Group_GetAllUsers(), Groups_GetAllGroups(), Groups_GetGroupsWithUser(), ParseOptions(), and Users_GetAllUsers().

◆ StringList_AddStrings()

bool StringList_AddStrings ( StringList stringList,
const char **  strings,
size_t  numStrings 
)

Add an array of strings to the given string list.

Parameters
stringListA pointer to a StringList representing the list of strings.
stringsPointer to an array of strings to add to the list. The strings are duplicated and appended to the list.
numStringsNumber of strings in the strings parameter to add.
Returns
Returns true if the string was added to the list; otherwise, returns false, indicating an out of memory condition has occurred (the original string list is untouched in this case).

Definition at line 90 of file stringlist.c.

References STRDUP.

◆ StringList_Clear()

void StringList_Clear ( StringList stringList)

Clear the specified string list. All strings in the list are released. The string list can then be used to add new strings.

Parameters
stringListThe StringList to clear.

Definition at line 30 of file stringlist.c.

References StringList_Initialize().

Referenced by _Mediator_Example_AddUserToGroup(), _Mediator_Example_RemoveUser(), _Mediator_Example_RemoveUserFromAllGroups(), _Mediator_Example_RemoveUserFromGroup(), _Mediator_Example_ShowAllGroups(), _Mediator_Example_ShowAllGroupsContainingUser(), _Mediator_Example_ShowAllUsers(), _Mediator_Example_ShowUsersInGroup(), Group_Destroy(), and main().

◆ StringList_Find()

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.

Parameters
stringListA pointer to a StringList representing the list of string to search.
stringThe string to search for.
Returns
Returns an index into the string list of the string if found; otherwise, returns -1 if the string is not found.

Definition at line 157 of file stringlist.c.

Referenced by Group_FindUser(), and main().

◆ StringList_Initialize()

void StringList_Initialize ( StringList stringList)

Initialize the given string list.

Parameters
stringListPointer to a StringList structure that is to be initialized. Cannot be NULL

Definition at line 17 of file stringlist.c.

Referenced by Group_Create(), main(), and StringList_Clear().

◆ StringList_Remove()

void StringList_Remove ( StringList stringList,
int  removeIndex 
)

Remove the specified string from the given string list.

Parameters
stringListA pointer to a StringList representing the list of strings.
removeIndexIndex of the string to remove from the list. Call StringList_Find() to get the index.

Definition at line 137 of file stringlist.c.

Referenced by Group_RemoveUser().