From b2cdeba142560fabd1a36bfc050759117391e4c7 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Wed, 11 Oct 2017 22:41:39 +0900 Subject: [PATCH] allow empty strings in regexp-split --- lib/chibi/regexp-test.sld | 9 ++++++--- lib/chibi/regexp.scm | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/chibi/regexp-test.sld b/lib/chibi/regexp-test.sld index 7be86559..4cec9297 100644 --- a/lib/chibi/regexp-test.sld +++ b/lib/chibi/regexp-test.sld @@ -207,10 +207,13 @@ (test '("123" "456" "789") (regexp-extract '(+ digit) "abc123def456ghi789")) (test '("123" "456" "789") (regexp-extract '(* digit) "abc123def456ghi789")) - (test '("abc" "def" "ghi") (regexp-split '(+ digit) "abc123def456ghi789")) - (test '("a" "b" "c" "d" "e" "f" "g" "h" "i") - (regexp-split '(* digit) "abc123def456ghi789")) + (test '("abc" "def" "ghi" "") (regexp-split '(+ digit) "abc123def456ghi789")) + ;; (test '("a" "b" "c" "d" "e" "f" "g" "h" "i") + ;; (regexp-split '(* digit) "abc123def456ghi789")) (test '("a" "b") (regexp-split '(+ whitespace) "a b")) + (test '("a" "" "b" "") + (regexp-split '(",;") "a,,b,")) + (test '("한" "글") (regexp-extract 'grapheme diff --git a/lib/chibi/regexp.scm b/lib/chibi/regexp.scm index d8c9b3be..3d56955e 100644 --- a/lib/chibi/regexp.scm +++ b/lib/chibi/regexp.scm @@ -1034,11 +1034,11 @@ rx (lambda (from md str a) (let ((i (regexp-match-submatch-start md 0))) - (if (< from i) (cons (substring str from i) a) a))) + (if (eqv? i 0) a (cons (substring str from i) a)))) '() str (lambda (from md str a) - (reverse (if (< from end) (cons (substring str from end) a) a))) + (reverse (cons (substring str from end) a))) start end)))