mes: Add string-downcase, string-upcase, string-tokenize.

* mes/module/srfi/srfi-13.mes (string-downcase, string-upcase,
string-tokenize): New function.
This commit is contained in:
Jan Nieuwenhuizen 2018-11-11 10:00:04 +01:00
parent 9543962ece
commit 9da1fd92b6
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -182,3 +182,21 @@
(string->list (string-take string (or start1 0)))
(string->list replace)
(string->list (string-drop string (or end1 (string-length string))))))))
(define (string-downcase string)
(string-map char-downcase string))
(define (string-upcase string)
(string-map char-upcase string))
(define (string-tokenize string char-set)
(let loop ((lst (string->list string)) (result '()))
(if (null? lst) (reverse result)
(let match ((lst lst) (found '()))
(if (null? lst) (loop lst (if (null? found) (reverse result)
(cons (list->string (reverse found)) result)))
(let ((c (car lst)))
(if (not (char-set-contains? char-set c)) (loop (cdr lst)
(if (null? found) result
(cons (list->string (reverse found)) result)))
(match (cdr lst) (cons c found)))))))))