diff options
Diffstat (limited to 'misc/examples/sview_split.c')
| -rw-r--r-- | misc/examples/sview_split.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/misc/examples/sview_split.c b/misc/examples/sview_split.c new file mode 100644 index 00000000..d22fccd1 --- /dev/null +++ b/misc/examples/sview_split.c @@ -0,0 +1,20 @@ +#define STC_IMPLEMENT +#include <stc/cstr.h> +#include <stc/csview.h> + +int main() +{ + // No memory allocations or string length calculations! + const csview date = c_SV("2021/03/12"); + size_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_ARGSV(year), c_ARGSV(month), c_ARGSV(day)); + + c_auto (cstr, y, m, d) { + 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)); + } +} |
