diff options
| author | Tyge Løvset <[email protected]> | 2022-08-09 17:34:13 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-09 17:34:13 +0200 |
| commit | 90624d6d398ff1d0f79df3dd656c4ad0c9c498a9 (patch) | |
| tree | 8e45f6d00189a261c6a54979010f634df2af0d49 /examples | |
| parent | 17f1d2ed83952df00525f4be1d30a6c12e04a0f6 (diff) | |
| download | STC-modified-90624d6d398ff1d0f79df3dd656c4ad0c9c498a9.tar.gz STC-modified-90624d6d398ff1d0f79df3dd656c4ad0c9c498a9.zip | |
Experiment with other type of iterator. Does not compile.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/mmap.c | 29 | ||||
| -rw-r--r-- | examples/regex_replace.c | 2 | ||||
| -rw-r--r-- | examples/utf8replace_c.c | 2 |
3 files changed, 15 insertions, 18 deletions
diff --git a/examples/mmap.c b/examples/mmap.c index 5ca2f92a..ed78d2af 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -4,6 +4,7 @@ // Multimap entries #include <stc/cstr.h> #define i_val_str +//#define i_valdrop(x) (printf("drop %s\n", cstr_str(x)), cstr_drop(x)) #define i_extern // define _clist_mergesort() once #include <stc/clist.h> @@ -34,10 +35,11 @@ int main() { c_auto (Multimap, mmap) { + typedef struct {int a; const char* b;} pair; + // list-initialize - struct { int first; const char* second; } vals[] = - {{2, "foo"}, {2, "bar"}, {3, "baz"}, {1, "abc"}, {5, "def"}}; - c_forrange (i, c_arraylen(vals)) insert(&mmap, c_pair(&vals[i])); + c_forarray (pair, v, {{2, "foo"}, {2, "bar"}, {3, "baz"}, {1, "abc"}, {5, "def"}}) + insert(&mmap, v->a, v->b); print("#1", mmap); // insert using value_type @@ -52,24 +54,19 @@ int main() print("#4", mmap); // insert using initialization_list - insert(&mmap, 5, "one"); - insert(&mmap, 5, "two"); + c_forarray (pair, v, {{5, "one"}, {5, "two"}}) + insert(&mmap, v->a, v->b); print("#5", mmap); // FOLLOWING NOT IN ORIGINAL EXAMPLE: - // erase all entries with key 5 Multimap_erase(&mmap, 5); - print("+6", mmap); + print("+5", mmap); + - // find and erase first entry containing "bar" - clist_str_iter pos; - c_foreach (e, Multimap, mmap) { - if ((pos = clist_str_find(&e.ref->second, "bar")).ref != clist_str_end(&e.ref->second).ref) { - clist_str_erase_at(&e.ref->second, pos); - break; - } - } - print("+7", mmap); + Multimap_clear(&mmap); + c_forarray (pair, v, {{1, "ä"}, {2, "ё"}, {2, "ö"}, {3, "ü"}}) + insert(&mmap, v->a, v->b); + print("#6", mmap); } } diff --git a/examples/regex_replace.c b/examples/regex_replace.c index 1b140676..ccc90dba 100644 --- a/examples/regex_replace.c +++ b/examples/regex_replace.c @@ -36,7 +36,7 @@ int main() /* Shows how to compile RE separately */ c_autovar (cregex re = cregex_from(pattern, 0), cregex_drop(&re)) { if (cregex_captures(&re) == 0) - continue; + c_breakauto; /* European date format. */ cstr_take(&str, cregex_replace(input, &re, "$3.$2.$1", 0)); printf("euros: %s\n", cstr_str(&str)); diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c index 792654b6..1bee9b44 100644 --- a/examples/utf8replace_c.c +++ b/examples/utf8replace_c.c @@ -16,7 +16,7 @@ int main() { printf("%s\n", cstr_str(&hello)); c_foreach (c, cstr, hello) - printf("%.*s,", c_ARGsv(c.chr)); + printf("%.*s,", c_ARGsv(c.u8.chr)); puts(""); } } |
