aboutsummaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-04-28 21:38:40 +0200
committerLudovic Courtès <ludo@gnu.org>2013-04-28 23:19:03 +0200
commit2bcfb9e065ac6abb6abf7ac9a263ba3c4d70124f (patch)
tree2b68896d8f18ed5b1b67c982f9677c84066b357c /guix/utils.scm
parent19cb51701266404e023eda5a50c026bccb0dc6a0 (diff)
downloadgnu-guix-2bcfb9e065ac6abb6abf7ac9a263ba3c4d70124f.tar
gnu-guix-2bcfb9e065ac6abb6abf7ac9a263ba3c4d70124f.tar.gz
utils: Add `string-tokenize*'.
* guix/utils.scm (string-tokenize*): New procedure. * tests/utils.scm ("string-tokenize*"): New test.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm28
1 files changed, 28 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 3cbed2fd0f..0b09affffd 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -60,6 +60,7 @@
version-compare
version>?
package-name->name+version
+ string-tokenize*
file-extension
call-with-temporary-output-file
fold2))
@@ -471,6 +472,33 @@ introduce the version part."
(let ((dot (string-rindex file #\.)))
(and dot (substring file (+ 1 dot) (string-length file)))))
+(define (string-tokenize* string separator)
+ "Return the list of substrings of STRING separated by SEPARATOR. This is
+like `string-tokenize', but SEPARATOR is a string."
+ (define (index string what)
+ (let loop ((string string)
+ (offset 0))
+ (cond ((string-null? string)
+ #f)
+ ((string-prefix? what string)
+ offset)
+ (else
+ (loop (string-drop string 1) (+ 1 offset))))))
+
+ (define len
+ (string-length separator))
+
+ (let loop ((string string)
+ (result '()))
+ (cond ((index string separator)
+ =>
+ (lambda (offset)
+ (loop (string-drop string (+ offset len))
+ (cons (substring string 0 offset)
+ result))))
+ (else
+ (reverse (cons string result))))))
+
(define (call-with-temporary-output-file proc)
"Call PROC with a name of a temporary file and open output port to that
file; close the file and delete it when leaving the dynamic extent of this