From 39155a1ddebd4da0cd13a4bcae93395f39765c0e Mon Sep 17 00:00:00 2001 From: NalaGinrut Date: Thu, 29 Dec 2011 18:19:00 +0800 Subject: [PATCH] ADD regexp-split --- module/ice-9/regex.scm | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-) diff --git a/module/ice-9/regex.scm b/module/ice-9/regex.scm index f7b94b7..2877419 100644 --- a/module/ice-9/regex.scm +++ b/module/ice-9/regex.scm @@ -41,7 +41,7 @@ #:export (match:count match:string match:prefix match:suffix regexp-match? regexp-quote match:start match:end match:substring string-match regexp-substitute fold-matches list-matches - regexp-substitute/global)) + regexp-substitute/global regexp-split)) ;; References: ;; @@ -226,3 +226,21 @@ (begin (do-item (car items)) ; This is not. (next-item (cdr items))))))))))) + +(define regexp-split + (lambda (regex str) + (let ([ret (fold-matches + regex str (list '() 0 '("")) + (lambda (m prev) + (let* ([ll (car prev)] + [start (cadr prev)] + [tail (match:suffix m)] + [end (match:start m)] + [s (string-copy str start end)] + ) + (list `(,@ll ,s ,(match:substring m)) + (match:end m) tail) + )))]) + `(,@(car ret) ,(caddr ret)) + ))) + -- 1.7.0.4