diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-02-05 09:08:39 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 14:39:30 +0100 |
commit | 561d0f0155f4906d90eb7e73a3ff9cb28909126f (patch) | |
tree | 9a606c2d7832272ea33d7052512a5fa59805d582 /script.it/shapes/matrix/Helpers.ml | |
parent | 86ec559f913c389e8dc055b494630f21a45e039b (diff) |
Update project structure
Diffstat (limited to 'script.it/shapes/matrix/Helpers.ml')
-rwxr-xr-x | script.it/shapes/matrix/Helpers.ml | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/script.it/shapes/matrix/Helpers.ml b/script.it/shapes/matrix/Helpers.ml new file mode 100755 index 0000000..6980052 --- /dev/null +++ b/script.it/shapes/matrix/Helpers.ml @@ -0,0 +1,16 @@ +(* Takes in a string and a separator, and separates the string into a list of + * substrings where each substring is between two separators or between a + * separator and the beginning/end of the string *) +let explode (s: string) (space: string) : string list = + let rec build (curr: string) (buffer: string) (lst: string list) : string list = + let len = String.length curr in + if len = 0 then buffer::lst + else + let c = String.sub curr (len - 1) 1 in + if len = 1 then (c ^ buffer)::lst + else + let s' = String.sub curr 0 (len - 1) in + if c = space then build s' "" (buffer::lst) + else build s' (c ^ buffer) lst in + build (String.trim s) "" [] + |