summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/strings/sview_split.c
diff options
context:
space:
mode:
author_Tradam <[email protected]>2023-09-08 01:29:47 +0000
committerGitHub <[email protected]>2023-09-08 01:29:47 +0000
commit3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch)
treeafbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/strings/sview_split.c
parent0841165881871ee01b782129be681209aeed2423 (diff)
parent1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff)
downloadSTC-modified-modified.tar.gz
STC-modified-modified.zip
Merge branch 'stclib:master' into modifiedHEADmodified
Diffstat (limited to 'misc/examples/strings/sview_split.c')
-rw-r--r--misc/examples/strings/sview_split.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/misc/examples/strings/sview_split.c b/misc/examples/strings/sview_split.c
new file mode 100644
index 00000000..ac275da0
--- /dev/null
+++ b/misc/examples/strings/sview_split.c
@@ -0,0 +1,20 @@
+#define i_implement
+#include <stc/cstr.h>
+#define i_implement
+#include <stc/csview.h>
+
+int main(void)
+{
+ // No memory allocations or string length calculations!
+ const csview date = c_sv("2021/03/12");
+ intptr_t pos = 0;
+ const csview year = csview_token(date, "/", &pos);
+ const csview month = csview_token(date, "/", &pos);
+ const csview day = csview_token(date, "/", &pos);
+
+ printf("%.*s, %.*s, %.*s\n", c_SV(year), c_SV(month), c_SV(day));
+
+ cstr y = cstr_from_sv(year), m = cstr_from_sv(month), d = cstr_from_sv(day);
+ printf("%s, %s, %s\n", cstr_str(&y), cstr_str(&m), cstr_str(&d));
+ c_drop(cstr, &y, &m, &d);
+}