Bug 5508 – Update startsWith to take a range of ranges
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-01-30T11:28:00Z
Last change time
2013-01-08T17:52:39Z
Assigned to
andrei
Creator
Jesse.K.Phillips+D
Comments
Comment #0 by Jesse.K.Phillips+D — 2011-01-30T11:28:48Z
Currently std.algorithm.startsWith accepts any number of ranges. It would be nice if this case below could pass:
import std.algorithm;
void main() {
auto a = ["\r\nHello"];
assert(startsWith(a, ["\n","\r\n"], ["H"]));
}
Comment #1 by andrei — 2013-01-08T00:56:59Z
Not sure I get the semantics. Currently the assertion fails because the first array does not start with any of the other arrays. Please advise.
Comment #2 by Jesse.K.Phillips+D — 2013-01-08T08:02:11Z
(In reply to comment #1)
> Not sure I get the semantics. Currently the assertion fails because the first
> array does not start with any of the other arrays. Please advise.
The array starts with \r\n which is the second element in the second array.
Comment #3 by andrei — 2013-01-08T09:51:54Z
(In reply to comment #2)
> (In reply to comment #1)
> > Not sure I get the semantics. Currently the assertion fails because the first
> > array does not start with any of the other arrays. Please advise.
>
> The array starts with \r\n which is the second element in the second array.
I understand. But that conflicts with the current semantics, which say that for x and y of type T[], x.startsWith(y) is true iff y is a prefix of x.
Comment #4 by Jesse.K.Phillips+D — 2013-01-08T16:24:24Z
(In reply to comment #3)
> I understand. But that conflicts with the current semantics, which say that for
> x and y of type T[], x.startsWith(y) is true iff y is a prefix of x.
But Y is of type Range!(T[]).
I guess it is to boyerMooreFinder[1] as startsWith is to find.
1. http://dlang.org/phobos/std_algorithm.html#boyerMooreFinder
Comment #5 by andrei — 2013-01-08T17:47:31Z
(In reply to comment #4)
> (In reply to comment #3)
> > I understand. But that conflicts with the current semantics, which say that for
> > x and y of type T[], x.startsWith(y) is true iff y is a prefix of x.
>
> But Y is of type Range!(T[]).
No, look again at your example. All ranges have type string[]. Did you actually mean this?
import std.algorithm;
void main() {
auto a = "\r\nHello";
assert(startsWith(a, ["\n","\r\n"], ["H"]));
}
Note that now a is of type string.
Comment #6 by Jesse.K.Phillips+D — 2013-01-08T17:52:39Z
(In reply to comment #5)
> No, look again at your example. All ranges have type string[]. Did you actually
> mean this?
>
> import std.algorithm;
>
> void main() {
> auto a = "\r\nHello";
> assert(startsWith(a, ["\n","\r\n"], ["H"]));
> }
>
> Note that now a is of type string.
It has been awhile since I wrote this, but I'm at least currently interested in what you have written.