From 056cbf3990bdb8b47a9a01469482848095c4cd75 Mon Sep 17 00:00:00 2001 From: Philipp Marek Date: Wed, 8 Mar 2017 13:00:17 +0100 Subject: [PATCH] Fix Perl compatibility for (SPLIT ... :LIMIT -1). A negative limit means infinity. --- api.lisp | 5 +++++ test/simple | 3 +++ 2 files changed, 8 insertions(+) diff --git a/api.lisp b/api.lisp index 1580fee..4c11c45 100644 --- a/api.lisp +++ b/api.lisp @@ -594,6 +594,11 @@ structure with TARGET-STRING." ;; push start of match on list unless this would be an empty ;; string adjacent to the last element pushed onto the list (when (and limit + ;; perlfunc(1) says + ;; If LIMIT is negative, it is treated as if + ;; it were instead arbitrarily large; + ;; as many fields as possible are produced. + (plusp limit) (>= (incf counter) limit)) (return)) (push match-start pos-list) diff --git a/test/simple b/test/simple index 632301c..2aa1446 100644 --- a/test/simple +++ b/test/simple @@ -142,6 +142,9 @@ frob") (equal (split ":" "a:b:c:d:e:f:g::" :limit 1000) '("a" "b" "c" "d" "e" "f" "g" "" "")) +(equal (split ":" "a:b:c:d:e:f:g::" :limit -1) + '("a" "b" "c" "d" "e" "f" "g" "" "")) + (equal (multiple-value-list (regex-replace "fo+" "foo bar" "frob")) (list "frob bar" t))