www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8866] New: Splitter(R1, R2) CANNOT be bidirectional.

http://d.puremagic.com/issues/show_bug.cgi?id=8866

           Summary: Splitter(R1, R2) CANNOT be bidirectional.
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com



Because long story short: If a splitter "element" overlaps with another, the
the orientation of the splitting will influence the splitting. For example:
Given the string "aaab", and the splitter "ab":

//----
import std.string;
import std.algorithm;
import std.range;
import std.stdio;

void main()
{
  auto r = "aaab";
  auto sep = "aa";
  auto s = r.splitter(sep);

  //Normal split
  s.writeln();

  //Split using back/popBack:
  s.retro().array().retro().writeln();
}
//----

Produces:
["", "ab"]
["a", "b"]

This creates two different results.

I don't have a source for this, but I'm 99% sure that iterating a range
backwards should produce the same output as the reverse of the range iterated
forward.

Suggest removing backwards iteration on splitter(R1, R2), and add suggestion to
use splitter(R1.retro, R2.retro)

----
Note; splitter(R, Value) and splitter(terminator)(R) should be able to safely
iterate backwards.

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