LAL  7.1.7.1-56c71ae

Converts a string into a series of tokens, for use by other routines. More...

Prototypes

void LALCreateTokenList (LALStatus *stat, TokenList **list, const CHAR *string, const CHAR *delimiters)
 
int XLALCreateTokenList (TokenList **list, const CHAR *string, const CHAR *delimiters)
 Split given input string into a list of 'tokens' separated by any of the characters given in 'delimiters'. More...
 
void LALDestroyTokenList (LALStatus *stat, TokenList **list)
 
void XLALDestroyTokenList (TokenList *list)
 See StringToken.c for documentation. More...
 

Detailed Description

Converts a string into a series of tokens, for use by other routines.

Author
Creighton, T. D.

Description

The routine XLALCreateTokenList() parses *string as a sequence of tokens (substrings of non-null characters that do not appear in delimiters), separated by delimiters (substrings consisting only of characters that appear in delimiters), and terminated by the null character '\0'. The structure **list is created, storing the sequence of tokens as a list null-terminated character strings.

The output list should be a non-NULL handle that points to the value NULL (i.e. list \(\neq\)NULL but *list=NULL). Even if no tokens were found, *list will be created, but will have (*list)->nTokens=0, (*list)->tokens[0]=NULL, and (*list)->list=NULL. Note that this is not an error, so the calling routine need not guarantee in advance that string contain any non-delimiter characters.

The routine XLALDestroyTokenList() destroys a list of tokens as created by XLALCreateTokenList(), setting *list to NULL.

Algorithm

The XLALCreateTokenList() function is not particularly memory-efficient, requiring internal storage up to twice the length of *string. It first creates a working copy of string->data, and replaces all occurences of characters appearing in *delimiters with '\0', while at the same time keeping track of the number and total length of all tokens. It then allocates a contiguous block of memory to store all the tokens (separated by and terminated with single '\0' characters), and a set of CHAR * pointers to point to the individual tokens in this block. Then the routine proceeds through the working copy one last time, copying tokens into the token list and setting the token pointers accordingly, before destroying the working copy.

Definition in file StringToken.c.

Go to the source code of this file.

Function Documentation

◆ LALCreateTokenList()

void LALCreateTokenList ( LALStatus stat,
TokenList **  list,
const CHAR string,
const CHAR delimiters 
)
Deprecated:
Use XLALCreateTokenList() instead

Definition at line 76 of file StringToken.c.

◆ XLALCreateTokenList()

int XLALCreateTokenList ( TokenList **  list,
const CHAR string,
const CHAR delimiters 
)

Split given input string into a list of 'tokens' separated by any of the characters given in 'delimiters'.

Parameters
[out]listlist of tokens
[in]stringstring to split into tokens
[in]delimitersset of token-delimiter characters

Definition at line 168 of file StringToken.c.

◆ LALDestroyTokenList()

void LALDestroyTokenList ( LALStatus stat,
TokenList **  list 
)
Deprecated:
Use XLALDestroyTokenList() instead

Definition at line 241 of file StringToken.c.

◆ XLALDestroyTokenList()

void XLALDestroyTokenList ( TokenList list)

See StringToken.c for documentation.

Definition at line 262 of file StringToken.c.