summaryrefslogtreecommitdiffhomepage
path: root/examples/sview_split.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-14 19:50:10 +0100
committerTyge Løvset <[email protected]>2021-12-14 19:50:10 +0100
commit6749cc21a2045d307c239d82891cb860687dfd2a (patch)
tree6987b4cd03caa9b1ad8ab29bd97a7d8d15fcaa67 /examples/sview_split.c
parentc083936d8fa46b5df921dedae6ca15e1192d6612 (diff)
downloadSTC-modified-6749cc21a2045d307c239d82891cb860687dfd2a.tar.gz
STC-modified-6749cc21a2045d307c239d82891cb860687dfd2a.zip
Added and renamed some examples.
Diffstat (limited to 'examples/sview_split.c')
-rw-r--r--examples/sview_split.c17
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