diff options
| author | gingerBill <bill@gingerbill.org> | 2022-02-28 12:32:51 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-02-28 12:32:51 +0000 |
| commit | 45124e4d5c19d477c2fc80282e153cc0bb7ac6ff (patch) | |
| tree | b5bd3d72b4b5f7909f67d65358e6e3ad25fb8714 /core/strings/strings.odin | |
| parent | 32988b03632912bbdb788e3dc319592a1dab9bfe (diff) | |
| parent | 7681c43b144015278b75b2788b824a5630f6ccd6 (diff) | |
Merge branch 'master' into freestanding_amd64
Diffstat (limited to 'core/strings/strings.odin')
| -rw-r--r-- | core/strings/strings.odin | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 4daa0bacd..670da166b 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -280,10 +280,29 @@ _split :: proc(s_, sep: string, sep_save, n_: int, allocator := context.allocato return res[:i+1] } +/* + Splits a string into parts, based on a separator. + Returned strings are substrings of 's'. + ``` + s := "aaa.bbb.ccc.ddd.eee" // 5 parts + ss := split(s, ".") + fmt.println(ss) // [aaa, bbb, ccc, ddd, eee] + ``` +*/ split :: proc(s, sep: string, allocator := context.allocator) -> []string { return _split(s, sep, 0, -1, allocator) } +/* + Splits a string into a total of 'n' parts, based on a separator. + Returns fewer parts if there wasn't enough occurrences of the separator. + Returned strings are substrings of 's'. + ``` + s := "aaa.bbb.ccc.ddd.eee" // 5 parts present + ss := split_n(s, ".", 3) // total of 3 wanted + fmt.println(ss) // [aaa, bbb, ccc.ddd.eee] + ``` +*/ split_n :: proc(s, sep: string, n: int, allocator := context.allocator) -> []string { return _split(s, sep, 0, n, allocator) } |