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

Implementation of the functions for working with the SplitList structure that is used for splitting a string based on one or more delimiters. More...

#include <stdlib.h>
#include <string.h>
#include "split.h"
Include dependency graph for split.c:

Go to the source code of this file.

Functions

void SplitList_Initialize (SplitList *list)
 Initialize the given SplitList object.
 
void SplitList_Clear (SplitList *list)
 Clear the given SplitList object so it can be reused again. Releases the list of sub-strings (but does not delete the sub-strings themselves, which are assumed to be pointers into an existing string).
 
void SplitList_AddString (SplitList *list, const char *s)
 Add a string to the given SplitList object. The string is not duplicated but instead is just copied into the list.
 
void split (char *s, const char *splitChars, SplitList *components)
 Split the given path into multiple strings based on the given delimiter. The pointers to each string are returned in the given StringList object.
 

Detailed Description

Implementation of the functions for working with the SplitList structure that is used for splitting a string based on one or more delimiters.

Definition in file split.c.

Function Documentation

◆ split()

void split ( char *  s,
const char *  splitChars,
SplitList components 
)

Split the given path into multiple strings based on the given delimiter. The pointers to each string are returned in the given StringList object.

Parameters
sString to split into components. Will be altered.
splitCharsA list of one or more characters on which to split the string. If NULL or empty, defaults to a single space.
componentsA SplitList object that will be updated with pointers to the sub-strings and the count of sub-strings. This object is cleared of any previous strings before being filled up again.

Definition at line 72 of file split.c.

References SplitList_AddString(), and SplitList_Clear().

Referenced by _FindEntry(), _State_DisplayText(), and getcursorposition().

◆ SplitList_AddString()

void SplitList_AddString ( SplitList list,
const char *  s 
)

Add a string to the given SplitList object. The string is not duplicated but instead is just copied into the list.

Parameters
listThe SplitList object to update.
sThe string to add to the SplitList object.

Definition at line 46 of file split.c.

References SplitList::strings, and SplitList::strings_count.

Referenced by split().

◆ SplitList_Clear()

void SplitList_Clear ( SplitList list)

Clear the given SplitList object so it can be reused again. Releases the list of sub-strings (but does not delete the sub-strings themselves, which are assumed to be pointers into an existing string).

Parameters
listA SplitList object to clear.

Definition at line 30 of file split.c.

References SplitList::strings, and SplitList::strings_count.

Referenced by _FindEntry(), getcursorposition(), and split().

◆ SplitList_Initialize()

void SplitList_Initialize ( SplitList list)

Initialize the given SplitList object.

Parameters
listA SplitList object to initialize.

Definition at line 15 of file split.c.

References SplitList::strings, and SplitList::strings_count.