summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2017-12-16 09:42:57 +0100
committerEugen Wissner <belka@caraus.de>2017-12-16 09:42:57 +0100
commit12de700706c0ef69b4257f91b736b4d1b5aa5151 (patch)
tree1f8ae1ed7bce5e7dedb217796e454ddc0b5562ca
parent78a8afdf75404526ea02d6bc80d130e85682dd81 (diff)
downloadtanya-12de700706c0ef69b4257f91b736b4d1b5aa5151.tar.gz
Fix formatting null class references
-rw-r--r--source/tanya/format/package.d24
1 files changed, 10 insertions, 14 deletions
diff --git a/source/tanya/format/package.d b/source/tanya/format/package.d
index b444cbf..d948edb 100644
--- a/source/tanya/format/package.d
+++ b/source/tanya/format/package.d
@@ -742,19 +742,13 @@ private ref String printToString(string fmt, Args...)(return ref String result,
{
result.insertBack(args[0] ? "true" : "false");
}
- else static if (isSomeString!Arg) // String
+ else static if (isSomeChar!Arg || isSomeString!Arg) // String or char
{
- if (args[0] is null)
- {
- result.insertBack("null");
- }
- else
- {
- result.insertBack(args[0]);
- }
+ result.insertBack(args[0]);
}
- else static if (isSomeChar!Arg // Supported by String.insertBack()
- || (isInputRange!Arg && isSomeChar!(ElementType!Arg)))
+ else static if (isInputRange!Arg
+ && !isInfinite!Arg
+ && isSomeChar!(ElementType!Arg)) // Stringish range
{
result.insertBack(args[0]);
}
@@ -764,7 +758,7 @@ private ref String printToString(string fmt, Args...)(return ref String result,
}
else static if (is(Arg == class))
{
- result.insertBack(args[0].toString());
+ result.insertBack(args[0] is null ? "null" : args[0].toString());
}
else static if (is(Arg == interface))
{
@@ -804,7 +798,8 @@ private ref String printToString(string fmt, Args...)(return ref String result,
}
else
{
- result.insertBack(Arg.stringof);
+ static assert(false,
+ "Formatting type " ~ Arg.stringof ~ " is not supported");
}
return result;
@@ -830,7 +825,7 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
// String printing.
assert(format!"{}"("Some weired string") == "Some weired string");
- assert(format!"{}"(cast(string) null) == "null");
+ assert(format!"{}"(cast(string) null) == "");
assert(format!"{}"('c') == "c");
// Integer.
@@ -943,6 +938,7 @@ package(tanya) String format(string fmt, Args...)(auto ref Args args)
auto instance = defaultAllocator.unique!A();
assert(format!"{}"(instance.get()) == instance.get.toString());
assert(format!"{}"(cast(I) instance.get()) == I.classinfo.name);
+ assert(format!"{}"(cast(A) null) == "null");
}
// Ranges.