Skip to content

Commit 347d735

Browse files
committed
FIX: split/at when the delimiter is not found
resolves: Oldes/Rebol-issues#2490
1 parent c4547d9 commit 347d735

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/mezz/mezz-series.reb

+13-14
Original file line numberDiff line numberDiff line change
@@ -504,22 +504,21 @@ split: function [
504504
return res
505505
]
506506
if at [
507-
return reduce either integer? dlm [
508-
[
509-
copy/part series dlm
510-
copy lib/at series dlm + 1
511-
]
512-
][
513-
;-- Without adding a /tail refinement, we don't know if they want
514-
; to split at the head or tail of the delimiter, so we'll exclude
515-
; the delimiter from the result entirely. They know what the dlm
516-
; was that they passed in, so they can add it back to either side
517-
; of the result if they want to.
518-
[
519-
copy/part series find series :dlm
520-
copy find/tail series :dlm
507+
unless integer? :dlm [
508+
return reduce either dlm: find series :dlm [
509+
dlm: index? dlm
510+
[
511+
copy/part series dlm - 1 ; excluding the delimiter
512+
copy lib/at series dlm + 1
513+
]
514+
][
515+
[copy series]
521516
]
522517
]
518+
return reduce [
519+
copy/part series dlm
520+
copy lib/at series dlm + 1
521+
]
523522
]
524523
;print ['split 'parts? parts mold series mold dlm]
525524
either all [block? dlm parse dlm [some integer!]][

src/tests/units/series-test.r3

+13
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,19 @@ Rebol [
20042004
;@@ https://github.com/Oldes/Rebol-issues/issues/690
20052005
--assert (split "This! is a. test? to see " charset "!?.") = ["This" " is a" " test" " to see "]
20062006

2007+
--test-- "split/at"
2008+
;@@ https://github.com/Oldes/Rebol-issues/issues/2490
2009+
--assert (split/at "a:b" #":") = ["a" "b"]
2010+
--assert (split/at "a:b:c" #":") = ["a" "b:c"]
2011+
--assert (split/at "a" #":") = ["a"]
2012+
--assert (split/at "a:" #":") = ["a" ""]
2013+
--assert (split/at ":b" #":") = ["" "b"]
2014+
--assert (split/at [1 a 2] 'a) = [[1] [2]]
2015+
--assert (split/at [1 a 2 3] 'a) = [[1] [2 3]]
2016+
--assert (split/at [1 a 2 a 3] 'a) = [[1] [2 a 3]]
2017+
--assert (split/at [1 2] 'a) = [[1 2]]
2018+
2019+
20072020
===end-group===
20082021

20092022

0 commit comments

Comments
 (0)