View source code
Display the source code in std/regex.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.regex.replaceAllInto
A variation on replaceAll
that instead of allocating a new string
on each call outputs the result piece-wise to the sink
. In particular
this enables efficient construction of a final output incrementally.
void replaceAllInto(Sink, R, C, RegEx)
(
Sink sink,
R input,
RegEx re,
const(C)[] format
) @trusted
if (isOutputRange!(Sink, dchar) && isSomeString!R && is(C : dchar) && isRegexFor!(RegEx, R));
void replaceAllInto(alias fun, Sink, R, RegEx)
(
Sink sink,
R input,
RegEx re
) @trusted
if (isOutputRange!(Sink, dchar) && isSomeString!R && isRegexFor!(RegEx, R));
As with replaceAll
there are 2 overloads - one with a format string,
the other one with a user defined functor.
Example
// insert comma as thousands delimiter in fifty randomly produced big numbers
import std .array, std .conv, std .random, std .range;
static re = regex(`(?<=\d)(?=(\d\d\d)+\b)`, "g");
auto sink = appender!(char [])();
enum ulong min = 10UL ^^ 10, max = 10UL ^^ 19;
foreach (i; 0 .. 50)
{
sink .clear();
replaceAllInto(sink, text(uniform(min, max)), re, ",");
foreach (pos; iota(sink .data .length - 4, 0, -4))
writeln(sink .data[pos]); // ','
}
Authors
Dmitry Olshansky,
API and utility constructs are modeled after the original std
by Walter Bright and Andrei Alexandrescu.
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.