diff options
Diffstat (limited to 'examples/sview_split.c')
| -rw-r--r-- | examples/sview_split.c | 17 |
1 files changed, 17 insertions, 0 deletions
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 <stc/csview.h>
+#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 |
