allow empty strings in regexp-split

This commit is contained in:
Alex Shinn 2017-10-11 22:41:39 +09:00
parent 334539f1fc
commit b2cdeba142
2 changed files with 8 additions and 5 deletions

View file

@ -207,10 +207,13 @@
(test '("123" "456" "789") (regexp-extract '(+ digit) "abc123def456ghi789")) (test '("123" "456" "789") (regexp-extract '(+ digit) "abc123def456ghi789"))
(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 '("abc" "def" "ghi" "") (regexp-split '(+ digit) "abc123def456ghi789"))
(test '("a" "b" "c" "d" "e" "f" "g" "h" "i") ;; (test '("a" "b" "c" "d" "e" "f" "g" "h" "i")
(regexp-split '(* digit) "abc123def456ghi789")) ;; (regexp-split '(* digit) "abc123def456ghi789"))
(test '("a" "b") (regexp-split '(+ whitespace) "a b")) (test '("a" "b") (regexp-split '(+ whitespace) "a b"))
(test '("a" "" "b" "")
(regexp-split '(",;") "a,,b,"))
(test '("한" "글") (test '("한" "글")
(regexp-extract (regexp-extract
'grapheme 'grapheme

View file

@ -1034,11 +1034,11 @@
rx rx
(lambda (from md str a) (lambda (from md str a)
(let ((i (regexp-match-submatch-start md 0))) (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 str
(lambda (from md str a) (lambda (from md str a)
(reverse (if (< from end) (cons (substring str from end) a) a))) (reverse (cons (substring str from end) a)))
start start
end))) end)))