earthquake changes of std.regexp to come

bearophile bearophileHUGS at lycos.com
Tue Feb 17 14:11:32 PST 2009


Andrei Alexandrescu:
> string a = ",a,  bcd, def,gh,";
> foreach (e; splitter(a, pattern(", *"))
>      writeln("[", e, "]");

(I often use xplit() that is like split but yields items lazily, for larger strings it's much faster).

A better approach is to fuse the xsplit and such xsplitter function in a single lazy generator that can take as a second argument a string or char or RE pattern.
A 3rd optional argument can be the max number of splits (so after such max it yields all the rest of the string).

You can then add an eager splitter function with the same signature, that outputs an array.

Bye,
bearophile



More information about the Digitalmars-d mailing list