std.algorithm.skipOver broken / misbehaving?

Era Scarecrow rtcvb32 at yahoo.com
Fri Oct 5 01:39:15 PDT 2012


  Although this likely isn't the most efficient way to do this, 
it's cropped up and here's what I have so far. The idea is to 
drop all the unwanted pathname and only leave the filename (I'm 
sure there's a function there already, just not finding it off 
hand).

  Why is this failing?

[quote]
bool skipOver(alias pred = "a == b", R1, R2)(ref R1 r1, R2 r2);
     If startsWith(r1, r2), consume the corresponding elements off 
r1 and return true. Otherwise, leave r1 unchanged and return 
false.
[/quote]

[code]
import std.algorithm;
import std.stdio;

void main() {
   string filename = r"something/long\or short";
   bool skipped;
     do {
       skipped = false;
       //try to handle either slash in this case.
       skipped |= filename.skipOver('\\');
       skipped |= filename.skipOver('/');
       skipped |= filename.skipOver(r"\");
       skipped |= filename.skipOver(r"/");
     } while (skipped);

   //originally was: do {} while(filename.skipOver('\\'));

   //asserts, filename hasn't changed.
   assert(filename == "or short", filename);
}
[/code]


More information about the Digitalmars-d-learn mailing list