diff options
| author | Tyge Løvset <[email protected]> | 2021-05-20 23:35:57 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-05-20 23:35:57 +0200 |
| commit | 188717d9c7ca04e7b0e63e48cea0c55e5db11f05 (patch) | |
| tree | 4cf706655ef40de018a2eedcb8141878ea348244 /docs | |
| parent | 6db18f878aac53c192b10e43c7cda2465d5496c8 (diff) | |
| download | STC-modified-188717d9c7ca04e7b0e63e48cea0c55e5db11f05.tar.gz STC-modified-188717d9c7ca04e7b0e63e48cea0c55e5db11f05.zip | |
Added csview tokenizer (split string).
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/csview_api.md | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/docs/csview_api.md b/docs/csview_api.md index fed7f6f4..e605c2bf 100644 --- a/docs/csview_api.md +++ b/docs/csview_api.md @@ -84,11 +84,11 @@ uint64_t csview_hash_ref(const csview* x, size_t ignored); ## Constants and macros -| Name | Value | Usage | -|:-----------------|:------------------ -|:---------------------------------| -| `csview_null` | same as `c_lit("")` | `sview = csview_null;` | -| `c_lit(literal)` | csview constructor | `sview = c_lit("hello, world");` | -| `csview_ARG(sv)` | printf argument | `printf("%.*s", csview_ARG(sv));`| +| Name | Value | Usage | +|:-----------------|:--------------------|:----------------------------------| +| `csview_null` | same as `c_lit("")` | `sview = csview_null;` | +| `c_lit(literal)` | csview constructor | `sview = c_lit("hello, world");` | +| `csview_ARG(sv)` | printf argument | `printf("%.*s", csview_ARG(sv));` | ## Container adaptors ``` @@ -169,3 +169,26 @@ Last element world: 200 ``` +### Example 2: string view tokensizer +Splits strings into tokens. **No** memory allocations, *strlen()*, or string zero-termination dependency. +```c +#include <stc/csview.h> + +void splitstring(csview str, csview sep) +{ + csview token = csview_first_token(str, sep); + for (;;) { + printf("token: \"%.*s\"\n", csview_ARG(token)); + if (csview_end(&token).ref == csview_end(&str).ref) break; + token = csview_next_token(str, sep, token); + } + puts("--"); +} + +int main() +{ + splitstring(c_lit("//This is//double slash//separated//string"), c_lit("//")); + splitstring(c_lit("This has no matching separator"), c_lit("xx")); + splitstring(c_lit("Split,this,string,now,ok,"), c_lit(",")); +} +``` |
