Thread overview
[Issue 5508] New: Update startsWith to take a range of ranges
Jan 30, 2011
Jesse Phillips
Apr 22, 2012
SomeDude
Jan 08, 2013
Jesse Phillips
Jan 09, 2013
Jesse Phillips
Jan 09, 2013
Jesse Phillips
January 30, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5508

           Summary: Update startsWith to take a range of ranges
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: andrei@metalanguage.com
        ReportedBy: Jesse.K.Phillips+D@gmail.com
                CC: Jesse.K.Phillips+D@gmail.com


--- Comment #0 from Jesse Phillips <Jesse.K.Phillips+D@gmail.com> 2011-01-30 11:28:48 PST ---
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"]));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5508


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5508


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com
           Platform|Other                       |All
         OS/Version|Linux                       |All
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5508



--- Comment #1 from Andrei Alexandrescu <andrei@erdani.com> 2013-01-08 00:56:59 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5508



--- Comment #2 from Jesse Phillips <Jesse.K.Phillips+D@gmail.com> 2013-01-08 08:02:11 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5508


Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |INVALID


--- Comment #3 from Andrei Alexandrescu <andrei@erdani.com> 2013-01-08 09:51:54 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5508



--- Comment #4 from Jesse Phillips <Jesse.K.Phillips+D@gmail.com> 2013-01-08 16:24:24 PST ---
(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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5508



--- Comment #5 from Andrei Alexandrescu <andrei@erdani.com> 2013-01-08 17:47:31 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5508



--- Comment #6 from Jesse Phillips <Jesse.K.Phillips+D@gmail.com> 2013-01-08 17:52:39 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------