diff options
author | Munyoki Kilyungi | 2023-03-27 22:50:36 +0300 |
---|---|---|
committer | BonfaceKilz | 2023-04-05 16:17:11 +0300 |
commit | 510a6056fa73b537481abca9b8027675b3d03f94 (patch) | |
tree | 637eb842ff3111fa082914e243aab3de2032a094 | |
parent | dc1cdc6c11be05cb21e5b68b6f0d147165867864 (diff) | |
download | gn-transform-databases-510a6056fa73b537481abca9b8027675b3d03f94.tar.gz |
Split substring int a list of substrings delimited by substring
* dump.scm (string-split-substring): New function.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rwxr-xr-x | dump.scm | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -98,6 +98,27 @@ (string->symbol (format #f "~s~a" field schema)))) +(define (string-split-substring str substr) + "Split the string @var{str} into a list of substrings delimited by the +substring @var{substr}." + + (define substrlen (string-length substr)) + (define strlen (string-length str)) + + (define (loop index start) + (cond + ((>= start strlen) (list "")) + ((not index) (list (substring str start))) + (else + (cons (substring str start index) + (let ((new-start (+ index substrlen))) + (loop (string-contains str substr new-start) + new-start)))))) + + (cond + ((string-contains str substr) => (lambda (idx) (loop idx 0))) + (else (list str)))) + (define (delete-substrings str . substrings) "Delete SUBSTRINGS, a list of strings, from STR." (fold (lambda (substring result) |