How is std.regex.replaceAllInto more efficient?

Sönke Ludwig via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 19 02:23:21 PDT 2015


Am 17.10.2015 um 12:06 schrieb Shriramana Sharma:
> Dmitry Olshansky wrote:
>
>> Feel free to improve on the examples, I'd gladly pull such patches.
>
> How about this, using the "comifying" regex from the replaceAll example:
>
>      auto re = ctRegex!(`(?<=\d)(?=(\d\d\d)+\b)`, "g");
>      auto sink = appender!(char [])();
>      foreach (line; stdin.byLine())
>      {
>          sink.clear();
>          replaceAllInto(sink, line, re, ",");
>          writeln(sink.data());
>      }
>

How about going one step further:

     auto re = ctRegex!(`(?<=\d)(?=(\d\d\d)+\b)`, "g");
     foreach (line; stdin.byLine())
     {
         replaceAllInto(stdout.lockingTextWriter, line, re, ",");
         writeln();
     }



More information about the Digitalmars-d mailing list