Summary: String splitting with empty separator
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: patch
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from 2011-05-10 16:30:55 PDT ---
This D2 program seems to go in infinte loop (dmd 2.053beta):

import std.string;
void main() {
    split("a test", "");


My suggestion is to add code like this in std.array.split():

if (delim.length == 0)
    return split(s);

This means that en empty splitting string is like splitting on generic
whitespace. This is useful in code like:

auto foo(string txt, string delim="") {
    return txt.split(delim);

This means that calling foo with no arguments splits txt on whitespace,
otherwise splits on the given string. This allows to use the two forms of split
in foo() without if conditions. This is done in Python too, where None is used
instead of an empty string.

The modified split is something like (there is a isSomeString!S2 because are
special, they aren't generic arrays, splitting on whitespace is meaningful for
strings only):

Unqual!(S1)[] split(S1, S2)(S1 s, S2 delim)
if (isForwardRange!(Unqual!S1) && isForwardRange!S2)
    Unqual!S1 us = s;
    if (isSomeString!S2 && delim.length == 0)
        return split(s);
        auto app = appender!(Unqual!(S1)[])();
        foreach (word; std.algorithm.splitter(us, delim))

Beside this change, I presume std.algorithm.splitter() too needs to test for an
empty delim.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to