diff options
| author | Tyge Løvset <[email protected]> | 2022-06-01 16:28:07 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-06-01 16:28:07 +0200 |
| commit | de629774cb912aa3d563f24d99258142713c3fcd (patch) | |
| tree | c37e2851d6cb049bc0863a59b6ecf5945fb88619 /examples/splitstr.c | |
| parent | 7fb43a24a17da787dd809114ca26c1231b058493 (diff) | |
| download | STC-modified-de629774cb912aa3d563f24d99258142713c3fcd.tar.gz STC-modified-de629774cb912aa3d563f24d99258142713c3fcd.zip | |
Converted all files with DOS line endings to LINUX.
Diffstat (limited to 'examples/splitstr.c')
| -rw-r--r-- | examples/splitstr.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/examples/splitstr.c b/examples/splitstr.c index 0cd48067..a155830c 100644 --- a/examples/splitstr.c +++ b/examples/splitstr.c @@ -1,39 +1,39 @@ -#define i_implement
-#include <stc/cstr.h>
-#define i_implement
-#include <stc/csview.h>
-#define i_val_str
-#include <stc/cvec.h>
-
-void print_split(csview str, csview sep)
-{
- size_t pos = 0;
- while (pos != str.size) {
- csview tok = csview_token(str, sep, &pos);
- // print non-null-terminated csview
- printf("[%" c_PRIsv "]\n", c_ARGsv(tok));
- }
-}
-
-cvec_str string_split(csview str, csview sep)
-{
- cvec_str vec = cvec_str_init();
- size_t pos = 0;
- while (pos != str.size) {
- csview tok = csview_token(str, sep, &pos);
- cvec_str_push_back(&vec, cstr_from_sv(tok));
- }
- return vec;
-}
-
-int main()
-{
- print_split(c_sv("//This is a//double-slash//separated//string"), c_sv("//"));
- puts("");
- print_split(c_sv("This has no matching separator"), c_sv("xx"));
- puts("");
-
- c_autovar (cvec_str v = string_split(c_sv("Split,this,,string,now,"), c_sv(",")), cvec_str_drop(&v))
- c_foreach (i, cvec_str, v)
- printf("[%s]\n", cstr_str(i.ref));
-}
+#define i_implement +#include <stc/cstr.h> +#define i_implement +#include <stc/csview.h> +#define i_val_str +#include <stc/cvec.h> + +void print_split(csview str, csview sep) +{ + size_t pos = 0; + while (pos != str.size) { + csview tok = csview_token(str, sep, &pos); + // print non-null-terminated csview + printf("[%" c_PRIsv "]\n", c_ARGsv(tok)); + } +} + +cvec_str string_split(csview str, csview sep) +{ + cvec_str vec = cvec_str_init(); + size_t pos = 0; + while (pos != str.size) { + csview tok = csview_token(str, sep, &pos); + cvec_str_push_back(&vec, cstr_from_sv(tok)); + } + return vec; +} + +int main() +{ + print_split(c_sv("//This is a//double-slash//separated//string"), c_sv("//")); + puts(""); + print_split(c_sv("This has no matching separator"), c_sv("xx")); + puts(""); + + c_autovar (cvec_str v = string_split(c_sv("Split,this,,string,now,"), c_sv(",")), cvec_str_drop(&v)) + c_foreach (i, cvec_str, v) + printf("[%s]\n", cstr_str(i.ref)); +} |
