Next: str_tokenize_free, Previous: str_tokcnt, Up: Strings [Contents]
tokenize a string at specified delimiters
#include <suplib/str.h> int str_tokenize( char *string, const char *delim, char ***string_argv, int skip, int restore );
char *string
string to parse
const char *delim
the delimiters to use
char ***string_argv
to store the parsed tokens
int skip
true if consecutive delimiters are treated as a single delimiter
int restore
true if
str_tokq
should restore the delimiter character from the previous invocation
This routine tokenizes the string using str_tokq
. The
invoking routine calls str_tokenize
once to parse all the tokens
for a given delimiter. The tokens are stored in string_argv.
if the restore
argument is false, str_tokenize
will
allocate memory for each of the tokens; otherwise it will return
pointers to the locations in the original string.
The routine str_tokenize_free
is provided to free the memory
allocated by str_tokenize
The number of tokens. The third argument, string_argv
,
contains the parsed tokens.
On error, str_tokenize
returns 0
and sets errno
accordingly. The following errors are recognized:
EINVAL
There were unbalanced quotes or the last character in the string was an escape character (i.e., no character to escape).
ENOMEM
A memory allocation failed
Dan Nguyen
Diab Jerius