cgul_split.h File Reference

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

#include "cgul_common.h"
#include "cgul_exception.h"
#include "cgul_vector.h"
Include dependency graph for cgul_split.h:
This graph shows which files directly or indirectly include this file:

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)
 

Detailed Description

Split a string based on a list of character separators.

Author
Paul Serice

Function Documentation

§ cgul_split()

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.

Parameters
[in,out]cexc-style exception
[in]sstring
[in]separatorsstring of characters that separate parts
[in]allow_empty_partswhether to allow empty parts
[out]partsparts of s
See also
cgul_strtok