From be0e64a9a19d3ca459284c61c497d141a78df1d7 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Thu, 17 Aug 2023 05:34:38 +0200 Subject: Renamed "internal" csview member .str => .buf, as it is not null terminated like crawstr .str member. --- misc/examples/coroutines/cotasks1.c | 12 ++++++------ misc/examples/coroutines/cotasks2.c | 12 ++++++------ misc/examples/regularexpressions/regex_match.c | 2 +- misc/examples/regularexpressions/regex_replace.c | 2 +- misc/tests/cregex_test.c | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'misc') diff --git a/misc/examples/coroutines/cotasks1.c b/misc/examples/coroutines/cotasks1.c index db9632e6..cffd6620 100644 --- a/misc/examples/coroutines/cotasks1.c +++ b/misc/examples/coroutines/cotasks1.c @@ -36,24 +36,24 @@ void print_time() struct produce_items { struct next_value next; - cstr str; + cstr text; int cco_state; }; int produce_items(struct produce_items* p) { cco_routine (p) { - p->str = cstr_init(); + p->text = cstr_init(); while (true) { cco_await(next_value(&p->next) != CCO_AWAIT); - cstr_printf(&p->str, "item %d", p->next.val); + cstr_printf(&p->text, "item %d", p->next.val); print_time(); - printf("produced %s\n", cstr_str(&p->str)); + printf("produced %s\n", cstr_str(&p->text)); cco_yield(); } cco_final: - cstr_drop(&p->str); + cstr_drop(&p->text); puts("done produce"); } return 0; @@ -74,7 +74,7 @@ int consume_items(struct consume_items* c, struct produce_items* p) printf("consume #%d\n", c->i); cco_await(produce_items(p) != CCO_AWAIT); print_time(); - printf("consumed %s\n", cstr_str(&p->str)); + printf("consumed %s\n", cstr_str(&p->text)); } cco_final: puts("done consume"); diff --git a/misc/examples/coroutines/cotasks2.c b/misc/examples/coroutines/cotasks2.c index 12c2c4a3..558df118 100644 --- a/misc/examples/coroutines/cotasks2.c +++ b/misc/examples/coroutines/cotasks2.c @@ -35,26 +35,26 @@ void print_time() cco_task_struct (produce_items, struct next_value next; - cstr str; + cstr text; ); int produce_items(struct produce_items* p, cco_runtime* rt) { cco_routine (p) { - p->str = cstr_init(); + p->text = cstr_init(); p->next.cco_func = next_value; while (true) { // await for next CCO_YIELD (or CCO_DONE) in next_value cco_await_task(&p->next, rt, CCO_YIELD); - cstr_printf(&p->str, "item %d", p->next.val); + cstr_printf(&p->text, "item %d", p->next.val); print_time(); - printf("produced %s\n", cstr_str(&p->str)); + printf("produced %s\n", cstr_str(&p->text)); cco_yield(); } cco_final: - cstr_drop(&p->str); + cstr_drop(&p->text); puts("done produce"); } return 0; @@ -77,7 +77,7 @@ int consume_items(struct consume_items* c, cco_runtime* rt) printf("consume #%d\n", c->i); cco_await_task(&c->produce, rt, CCO_YIELD); print_time(); - printf("consumed %s\n", cstr_str(&c->produce.str)); + printf("consumed %s\n", cstr_str(&c->produce.text)); } cco_final: diff --git a/misc/examples/regularexpressions/regex_match.c b/misc/examples/regularexpressions/regex_match.c index 11426d2d..9106ffbd 100644 --- a/misc/examples/regularexpressions/regex_match.c +++ b/misc/examples/regularexpressions/regex_match.c @@ -22,7 +22,7 @@ int main(void) // extract and convert all numbers in str to floats c_formatch (i, &re, str) - cstack_float_push(&vec, (float)atof(i.match[0].str)); + cstack_float_push(&vec, (float)atof(i.match[0].buf)); c_foreach (i, cstack_float, vec) printf(" %g\n", (double)*i.ref); diff --git a/misc/examples/regularexpressions/regex_replace.c b/misc/examples/regularexpressions/regex_replace.c index f1ea2711..087387d7 100644 --- a/misc/examples/regularexpressions/regex_replace.c +++ b/misc/examples/regularexpressions/regex_replace.c @@ -5,7 +5,7 @@ bool add_10_years(int i, csview match, cstr* out) { if (i == 1) { // group 1 matches year int year; - sscanf(match.str, "%4d", &year); // scan 4 chars only + sscanf(match.buf, "%4d", &year); // scan 4 chars only cstr_printf(out, "%04d", year + 10); return true; } diff --git a/misc/tests/cregex_test.c b/misc/tests/cregex_test.c index 4e192de6..a83b7593 100644 --- a/misc/tests/cregex_test.c +++ b/misc/tests/cregex_test.c @@ -4,7 +4,7 @@ #include #include "ctest.h" -#define M_START(m) ((m).str - inp) +#define M_START(m) ((m).buf - inp) #define M_END(m) (M_START(m) + (m).size) @@ -238,7 +238,7 @@ CTEST(cregex, captures_cap) static bool add_10_years(int i, csview match, cstr* out) { if (i == 1) { // group 1 matches year int year; - sscanf(match.str, "%4d", &year); // scan 4 chars only + sscanf(match.buf, "%4d", &year); // scan 4 chars only cstr_printf(out, "%04d", year + 10); return true; } -- cgit v1.2.3