To make simple token list manipulation easier.
any name starting with a _ should be considered like C++'s private. If you have a CSS broswer actual code usable in tokens.h will have a black background, and samples will have a white background. Everything else will have a silver background.
The only include is #include <sys/types.h>
, and
that is for the size_t type.
One creates a tokens structure using C code like: tokens foo; tokInit(&foo); and frees it up for reuse with tokFree(&foo);.
This structure should never be destroyed or created but the user of this this library. It is, however, ok for to reference elements in it. Every instance of tokens will have one of these structures for every token in the list.
typedef struct token_s {
struct token_s* next;
- Points to the next token in the token list.
char* tok;
- The actual token ("" is legal but NULL is not).
size_t len;
- This holds the length of tok, this is the length not including the terminating NULL character.
} _token;
typedef struct tokens_s {
struct token_s* first;
- Pointer to the first token on the list. NULL if no tokens are defined.
struct token_s* last;
- Pointer to the last token on the list. It equals first if there is only token on the list.
size_t count;
- The number of tokens in this list.
char *_string; /* place to hold string to print. */ } tokens;
Please note, I would of written this in C++ but I needed it in C. So you might notice some C++ish conventions.
tokens* tokInit(tokens* this);
tokens* tokFree(tokens* this);
tokens* tokFree_first(tokens* this);
int tokFree_one(tokens* this, const char* remove);
tokens* tokAdd(tokens* this, const char*
list, const char* delim);
tokens* tokAdd_unique(tokens* this, const char* list, const
char* delim);
int tokMatch(tokens* this, const char*
find);
const char* tok2string(tokens* this,
const char* delim);