aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-03-27 22:50:36 +0300
committerBonfaceKilz2023-04-05 16:17:11 +0300
commit510a6056fa73b537481abca9b8027675b3d03f94 (patch)
tree637eb842ff3111fa082914e243aab3de2032a094
parentdc1cdc6c11be05cb21e5b68b6f0d147165867864 (diff)
downloadgn-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-xdump.scm21
1 files changed, 21 insertions, 0 deletions
diff --git a/dump.scm b/dump.scm
index 1f0a262..9a8cc07 100755
--- a/dump.scm
+++ b/dump.scm
@@ -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)