Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
tokenize.h File Reference

String tokenization. More...

#include <assert.h>
#include <stddef.h>
#include <string.h>
#include <util/strview.h>
Include dependency graph for tokenize.h:
This graph shows which files directly or indirectly include this file:

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
 

Detailed Description

This is essentially equivalent to strtok but with two main improvements:

  1. The input string is not modified. This means, if you have a 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.
  2. No global state. All the state for tokenization is contained in the 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.

Function Documentation

◆ tok()

static tok_t tok ( const char *  input,
const char *  separators 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tok_end()

static bool tok_end ( const tok_t t)
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().

Here is the caller graph for this function:

◆ tok_get()

static strview_t tok_get ( const tok_t t)
inlinestatic

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().

Here is the caller graph for this function:

◆ tok_next()

static void tok_next ( tok_t t)
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().

Here is the caller graph for this function: