split a string based on a list of character separators More...


Functions | |
| CGUL_BEGIN_C CGUL_EXPORT void | cgul_split (cgul_exception_t *cex, const char *s, const char *separators, int allow_empty_parts, cgul_vector_t parts) |
Split a string based on a list of character separators.
| CGUL_BEGIN_C CGUL_EXPORT void cgul_split | ( | cgul_exception_t * | cex, |
| const char * | s, | ||
| const char * | separators, | ||
| int | allow_empty_parts, | ||
| cgul_vector_t | parts | ||
| ) |
This function splits s into parts. Each part is separated by one or more consecutive characters from the separators string. Each part is appended to parts as a new C-style string. The caller is responsible for calling free() on each part.
The allow_empty_parts boolean determines whether this function inserts empty strings to indicate that one separator directly followed another without any non-separator characters in the middle. If this boolean is set to 0, any sequence of separators in s will be treated as just a single separator.
This function can fail if memory cannot be allocated for the strings that are appended to parts. If an error occurs, parts will not be altered, and an exception will be thrown.
| [in,out] | cex | c-style exception |
| [in] | s | string |
| [in] | separators | string of characters that separate parts |
| [in] | allow_empty_parts | whether to allow empty parts |
| [out] | parts | parts of s |