Wrap formatting into printToString

printToString gets the output string as argument and can be called
recursive with the same output string to format ranges.
This commit is contained in:
Eugen Wissner 2017-12-03 19:53:06 +01:00
parent 75ce854192
commit 26c3532e28
1 changed files with 8 additions and 3 deletions

View File

@ -505,10 +505,9 @@ if (T.sizeof == U.sizeof)
copy((&src)[0 .. 1], (&dest)[0 .. 1]);
}
package(tanya) String format(string fmt, Args...)(auto ref Args args)
private ref String printToString(string fmt, Args...)(return ref String result,
auto ref Args args)
{
String result;
static if (is(Unqual!(Args[0]) == typeof(null)))
{
result.insertBack("null");
@ -758,6 +757,12 @@ ParamEnd:
return result;
}
package(tanya) String format(string fmt, Args...)(auto ref Args args)
{
String formatted;
return printToString!fmt(formatted, args);
}
// One argument tests.
@nogc pure @safe unittest
{