summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2018-07-29 12:51:38 +0200
committerEugen Wissner <belka@caraus.de>2018-07-29 12:51:38 +0200
commitfe0576a2d6d18ebfe9d44dc5bdb577c79d650dae (patch)
tree1e4f104bdfa6506befe8fcae7d6108bfcf951dbe /source
parenta5b84deca7c7a1cfe4c61d0683cdc1a21714a5b7 (diff)
downloadtanya-fe0576a2d6d18ebfe9d44dc5bdb577c79d650dae.tar.gz
Fix format printing only the first argument
Diffstat (limited to 'source')
-rw-r--r--source/tanya/format.d19
1 files changed, 13 insertions, 6 deletions
diff --git a/source/tanya/format.d b/source/tanya/format.d
index 89c7259..86f5de6 100644
--- a/source/tanya/format.d
+++ b/source/tanya/format.d
@@ -2327,7 +2327,7 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
{
static if (FormatSpecFilter!spec)
{
- printToString!"{}"(formatted, args);
+ printToString!"{}"(formatted, args[spec.position]);
}
else static if (isSomeString!(typeof(spec)))
{
@@ -2341,6 +2341,12 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
return formatted;
}
+// doesn't print the first argument repeatedly
+@nogc nothrow pure @safe unittest
+{
+ assert(format!"{}{}"(1, 2) == "12");
+}
+
@nogc nothrow pure @safe unittest
{
assert(format!"Without arguments"() == "Without arguments");
@@ -2574,6 +2580,7 @@ nothrow pure @safe unittest
private struct FormatSpec
{
+ const size_t position;
}
// Returns the position of `tag` in `fmt`. If `tag` can't be found, returns the
@@ -2590,7 +2597,7 @@ private size_t specPosition(string fmt, char tag)()
return fmt.length;
}
-private template ParseFmt(string fmt, size_t pos = 0)
+private template ParseFmt(string fmt, size_t arg = 0, size_t pos = 0)
{
static if (fmt.length == 0)
{
@@ -2602,7 +2609,7 @@ private template ParseFmt(string fmt, size_t pos = 0)
{
enum size_t pos = specPosition!(fmt[2 .. $], '{') + 2;
alias ParseFmt = AliasSeq!(fmt[1 .. pos],
- ParseFmt!(fmt[pos .. $], pos));
+ ParseFmt!(fmt[pos .. $], arg, pos));
}
else
{
@@ -2613,8 +2620,8 @@ private template ParseFmt(string fmt, size_t pos = 0)
}
else static if (pos == 1)
{
- alias ParseFmt = AliasSeq!(FormatSpec(),
- ParseFmt!(fmt[pos + 1 .. $], pos + 1));
+ alias ParseFmt = AliasSeq!(FormatSpec(arg),
+ ParseFmt!(fmt[2 .. $], arg + 1, 2));
}
else
{
@@ -2626,7 +2633,7 @@ private template ParseFmt(string fmt, size_t pos = 0)
{
enum size_t pos = specPosition!(fmt, '{');
alias ParseFmt = AliasSeq!(fmt[0 .. pos],
- ParseFmt!(fmt[pos .. $], pos));
+ ParseFmt!(fmt[pos .. $], arg, pos));
}
}