mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-22 07:09:18 +02:00
string-split on the empty string is null, on a single space is two empty strings
This commit is contained in:
parent
98bad7bc63
commit
af8aed4c5a
2 changed files with 7 additions and 3 deletions
|
@ -54,11 +54,13 @@
|
||||||
|
|
||||||
(define (string-split str . o)
|
(define (string-split str . o)
|
||||||
(let ((pred (make-char-predicate (if (pair? o) (car o) #\space)))
|
(let ((pred (make-char-predicate (if (pair? o) (car o) #\space)))
|
||||||
(limit (if (and (pair? o) (pair? (cdr o))) (cadr o) (string-size str)))
|
(limit (if (and (pair? o) (pair? (cdr o)))
|
||||||
|
(cadr o)
|
||||||
|
(+ 1 (string-size str))))
|
||||||
(start (string-cursor-start str))
|
(start (string-cursor-start str))
|
||||||
(end (string-cursor-end str)))
|
(end (string-cursor-end str)))
|
||||||
(if (string-cursor>=? start end)
|
(if (string-cursor>=? start end)
|
||||||
(list "")
|
'()
|
||||||
(let lp ((i start) (n 1) (res '()))
|
(let lp ((i start) (n 1) (res '()))
|
||||||
(cond
|
(cond
|
||||||
((>= n limit)
|
((>= n limit)
|
||||||
|
|
|
@ -41,8 +41,10 @@
|
||||||
(test "foobarbaz" (string-join '("foo" "bar" "baz")))
|
(test "foobarbaz" (string-join '("foo" "bar" "baz")))
|
||||||
(test "foo bar baz" (string-join '("foo" "bar" "baz") " "))
|
(test "foo bar baz" (string-join '("foo" "bar" "baz") " "))
|
||||||
|
|
||||||
(test '("") (string-split ""))
|
(test '() (string-split ""))
|
||||||
|
(test '("" "") (string-split " "))
|
||||||
(test '("foo" "bar" "baz") (string-split "foo bar baz"))
|
(test '("foo" "bar" "baz") (string-split "foo bar baz"))
|
||||||
|
(test '("foo" "bar" "baz" "") (string-split "foo bar baz "))
|
||||||
(test '("foo" "bar" "baz") (string-split "foo:bar:baz" #\:))
|
(test '("foo" "bar" "baz") (string-split "foo:bar:baz" #\:))
|
||||||
(test '("" "foo" "bar" "baz") (string-split ":foo:bar:baz" #\:))
|
(test '("" "foo" "bar" "baz") (string-split ":foo:bar:baz" #\:))
|
||||||
(test '("foo" "bar" "baz" "") (string-split "foo:bar:baz:" #\:))
|
(test '("foo" "bar" "baz" "") (string-split "foo:bar:baz:" #\:))
|
||||||
|
|
Loading…
Add table
Reference in a new issue