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]

Reply via email to