Graphviz 13.0.0~dev.20241220.2304
|
String tokenization. More...
Go to the source code of this file.
Data Structures | |
struct | tok_t |
state for an in-progress string tokenization More... | |
Functions | |
static tok_t | tok (const char *input, const char *separators) |
begin tokenization of a new string | |
static bool | tok_end (const tok_t *t) |
is this tokenizer exhausted? | |
static strview_t | tok_get (const tok_t *t) |
get the current token | |
static void | tok_next (tok_t *t) |
advance to the next token in the string being scanned | |
This is essentially equivalent to strtok
but with two main improvements:
const
string, you do not need to strdup
it in order to tokenize it. This (combined with other properties like no opaque struct pointers) enables you to tokenize a string with no heap allocation.tok_t
struct.The above two properties are intended to make string tokenization scalable (no locks, no thread-shared state) and transparent to the compiler (a good optimizing compiler implements all the string.h functions we use as built-ins and, if separators
is a compile-time literal, can typically flatten everything into a tight loop with no function calls).
Sample usage:
const char my_input[] = "foo; bar:/baz"; for (tok_t t = tok(my_input, ";:/"); !tok_end(&t); tok_next(&t)) { strview_t s = tok_get(&t); printf("%.*s\n", (int)s.size, s.data); } // prints “foo”, “ bar”, “baz”
Definition in file tokenize.h.
|
inlinestatic |
Definition at line 43 of file tokenize.h.
References strview_t::data, tok_t::next, NULL, s1(), and tok_t::start.
Referenced by _agstrcanon(), addItem(), boxof(), exsplit(), extokens(), mkDirlist(), parse_layers(), parseSegs(), parseStyle(), scanNum(), and update_columns().
|
inlinestatic |
Definition at line 68 of file tokenize.h.
References strview_t::data, tok_t::next, and NULL.
Referenced by mkDirlist(), parseSegs(), parseStyle(), and update_columns().
Definition at line 76 of file tokenize.h.
References strview_t::data, tok_t::next, and NULL.
Referenced by mkDirlist(), parseSegs(), parseStyle(), and update_columns().
|
inlinestatic |
Definition at line 85 of file tokenize.h.
References strview_t::data, tok_t::next, NULL, tok_t::separators, strview_t::size, and tok_t::start.
Referenced by mkDirlist(), parseSegs(), parseStyle(), and update_columns().