From 26c3532e282f549f5634f131f042c4c13349e69b Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 3 Dec 2017 19:53:06 +0100 Subject: [PATCH] Wrap formatting into printToString printToString gets the output string as argument and can be called recursive with the same output string to format ranges. --- source/tanya/format/package.d | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/tanya/format/package.d b/source/tanya/format/package.d index d542529..e283c3d 100644 --- a/source/tanya/format/package.d +++ b/source/tanya/format/package.d @@ -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 {