From 6749cc21a2045d307c239d82891cb860687dfd2a Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 14 Dec 2021 19:50:10 +0100 Subject: Added and renamed some examples. --- examples/sview_split.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/sview_split.c (limited to 'examples/sview_split.c') diff --git a/examples/sview_split.c b/examples/sview_split.c new file mode 100644 index 00000000..3a079583 --- /dev/null +++ b/examples/sview_split.c @@ -0,0 +1,17 @@ +#include +#define c_arg(a) a +int main() +{ + // No memory allocations or string length calculations! + const csview date = c_sv("2021/03/12"); + const csview year = csview_first_token(date, c_sv("/")); + const csview month = csview_next_token(date, c_sv("/"), year); + const csview day = csview_next_token(date, c_sv("/"), month); + + printf(c_svfmt ", " c_svfmt ", " c_svfmt "\n", c_svarg(year), c_svarg(month), c_svarg(day)); + + c_auto (cstr, y, m, d) { + y = cstr_from_v(year), m = cstr_from_v(month), d = cstr_from_v(day); + printf("%s, %s, %s\n", y.str, m.str, d.str); + } +} \ No newline at end of file -- cgit v1.2.3