@@ -5547,7 +5547,10 @@ auto splitter(alias pred = "a == b",
55475547 Range ,
55485548 Separator)(Range r, Separator s)
55495549if (is (typeof (binaryFun! pred(r.front, s)) : bool )
5550- && ((hasSlicing! Range && hasLength! Range ) || isNarrowString! Range ))
5550+ && ((hasSlicing! Range && hasLength! Range ) || isNarrowString! Range )
5551+ && (is (ElementType! Range : Separator)
5552+ || ! (isForwardRange! Separator && (hasLength! Separator
5553+ || isNarrowString! Separator))))
55515554{
55525555 import std.algorithm.searching : find;
55535556 import std.conv : unsigned;
@@ -5619,6 +5622,7 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
56195622 assert (! empty, " Attempting to fetch the front of an empty splitter." );
56205623 static if (keepSeparators)
56215624 {
5625+ if (_frontLength != _unComputed && ! _wasSeparator) return _input[0 .. _frontLength];
56225626 if (! _wasSeparator)
56235627 {
56245628 _frontLength = _separatorLength;
@@ -6078,6 +6082,20 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
60786082 assert (" abXcdxef" .splitter! ((a, b) => a.toLower == b)(' x' ).equal([" ab" , " cd" , " ef" ]));
60796083}
60806084
6085+ // https://github.com/dlang/phobos/issues/10759
6086+ @safe unittest
6087+ {
6088+ import std.algorithm.iteration : splitter;
6089+ import std.algorithm.searching : canFind;
6090+ import std.range.primitives ;
6091+ import std.typecons : Yes;
6092+
6093+ auto range = " 16x13+0-2" .splitter! ((a, b) => " x+-" .canFind(a), Yes.keepSeparators)(0 );
6094+ assert (range.front == " 16" );
6095+ assert (range.front == " 16" );
6096+ assert (range.front == " 16" );
6097+ }
6098+
60816099// / ditto
60826100auto splitter (alias pred = " a == b" ,
60836101 Flag! " keepSeparators" keepSeparators = No.keepSeparators,
@@ -6091,7 +6109,7 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
60916109 import std.algorithm.searching : find;
60926110 import std.conv : unsigned;
60936111
6094- static struct Result
6112+ struct Result
60956113 {
60966114 private :
60976115 Range _input;
@@ -6306,6 +6324,17 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
63066324 assert (words.equal([ " i" , " am" , " pointing" ]));
63076325}
63086326
6327+ // https://github.com/dlang/phobos/issues/10760
6328+ @safe unittest
6329+ {
6330+ import std.algorithm.searching : canFind;
6331+ import std.typecons : Yes;
6332+ import std.algorithm.comparison : equal;
6333+
6334+ auto r = " 16x16+0-2" .splitter! ((a, b) => " x+-" .canFind(a), Yes.keepSeparators)(" x" );
6335+ assert (r.equal([" 16" , " x" , " 16" , " +" , " 0" , " -" , " 2" ]));
6336+ }
6337+
63096338/+ +
63106339Lazily splits a range `r` whenever a predicate `isTerminator` returns true for an element.
63116340
0 commit comments