Next: , Previous: str_tokqcnt, Up: Strings


4.11 str_tokbqenize

tokenize a string at specified delimiters

Synopsis

     #include <suplib/str.h>
     
     
     
int str_tokbqenize( char *string, char ***string_argv, const char *delim, const char *open_quote, const char *close_quote, char escape_char, int actions, struct str_tokbqdata *tbqd, int *error );

Parameters

char *string
the string to parse
char ***string_argv
to store the parsed tokens
const char *delim
the set of characters that delimit tokens
const char *open_quote
the set of characters that delimit opening quotes. e.g., ‘"'{[
const char *close_quote
the set of matching characters that delimit closing quotes. These must be in the same order as the opening characters in open_quote, e.g., ‘"'}]
char escape_char
the escape character
int actions
skip, restore, and escape modes
struct str_tokbqdata *tbqd
state information
int *error
returned error code

Description

This routine tokenizes the string using str_tokbq. The invoking routine calls str_tokbqenize once to parse all the tokens for a given delimiter. The tokens are stored in string_argv.

if the restore argument is false, str_tokbqenize will allocate memory for each of the tokens; otherwise it will return pointers to the locations in the original string.

The routine str_tokbqenize_free is provided to free the memory allocated by str_tokbqenize

Returns

The number of tokens. The third argument, string_argv, contains the parsed tokens.

Errors

On error, str_tokbqenize 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

Author

Diab Jerius Dan Nguyen