diff options
author | Ludovic Courtès <ludo@gnu.org> | 2013-04-30 17:06:00 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-04-30 17:06:00 +0200 |
commit | 0734a9a8131525d6da2e7bf802402dc0350eda98 (patch) | |
tree | f43bef210f6513b12c14ee9494bb47e4f80e99d0 /guix/utils.scm | |
parent | e0fbbc889d724678e9e310432ad3a3fb8345cf9a (diff) | |
parent | 01155b1808b17f0a4f54388261ab0c6f5fee2f1b (diff) | |
download | gnu-guix-0734a9a8131525d6da2e7bf802402dc0350eda98.tar gnu-guix-0734a9a8131525d6da2e7bf802402dc0350eda98.tar.gz |
Merge branch 'core-updates'
Diffstat (limited to 'guix/utils.scm')
-rw-r--r-- | guix/utils.scm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm index aec07301da..7c8e914c01 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -61,6 +61,7 @@ version-compare version>? package-name->name+version + string-tokenize* file-extension call-with-temporary-output-file fold2 @@ -517,6 +518,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 |