summaryrefslogtreecommitdiff
path: root/scheme
diff options
context:
space:
mode:
authormichele.simionato <devnull@localhost>2009-03-16 14:35:59 +0000
committermichele.simionato <devnull@localhost>2009-03-16 14:35:59 +0000
commit9f04f84ea15a3fd178000ead508f958d6f6cee78 (patch)
tree4f72a38e8001204f78b7859a1ce89955244c6dea /scheme
parentf5cf1e37d3d993e83b8ccd64d273a4f0f983636d (diff)
downloadmicheles-9f04f84ea15a3fd178000ead508f958d6f6cee78.tar.gz
Added a string-utils library with a string-split function
Diffstat (limited to 'scheme')
-rw-r--r--scheme/aps/string-utils.sls21
1 files changed, 21 insertions, 0 deletions
diff --git a/scheme/aps/string-utils.sls b/scheme/aps/string-utils.sls
new file mode 100644
index 0000000..8e8aaf1
--- /dev/null
+++ b/scheme/aps/string-utils.sls
@@ -0,0 +1,21 @@
+(library (aps string-utils)
+(export string-split)
+(import (rnrs))
+
+(define (string-split str ch)
+ (define len (string-length str))
+ (define (split a b)
+ (cond
+ ((>= b len)
+ (if (= a b) '()
+ (list (substring str a b))))
+ ((char=? ch (string-ref str b))
+ (if (= a b) (split (+ 1 a) (+ 1 b))
+ (cons (substring str a b) (split b b))))
+ (else (split a (+ 1 b)))))
+ (split 0 0))
+)
+
+;(display (string-split "a.b" #\.))
+;(display (string-split ".b" #\.))
+;(display (string-split "a." #\.))