From 2b1abda154fa462d11092591fb07e9fb4d63779f Mon Sep 17 00:00:00 2001 From: John-Colvin Date: Tue, 11 Dec 2012 16:06:20 +0000 Subject: [PATCH] Fix remaining format errors --- dyaml/exception.d | 6 ++++-- dyaml/node.d | 2 +- dyaml/reader.d | 4 ++-- dyaml/representer.d | 10 +++++----- dyaml/scanner.d | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dyaml/exception.d b/dyaml/exception.d index 3f2c4b9..9353a36 100644 --- a/dyaml/exception.d +++ b/dyaml/exception.d @@ -13,6 +13,8 @@ import std.array; import std.string; import std.conv; +alias to!string str; + ///Base class for all exceptions thrown by D:YAML. class YAMLException : Exception @@ -46,8 +48,8 @@ struct Mark string toString() const @trusted { //Line/column numbers start at zero internally, make them start at 1. - string clamped(ushort v){return to!string(v + 1) ~ (v == ushort.max ? " or higher" : "");} - return format("line ", clamped(line_), ",column ", clamped(column_)); + string clamped(ushort v){return str(v + 1) ~ (v == ushort.max ? " or higher" : "");} + return "line " ~ str(clamped(line_)) ~ ",column " ~ str(clamped(column_)); } } diff --git a/dyaml/node.d b/dyaml/node.d index f497478..6cca76b 100644 --- a/dyaml/node.d +++ b/dyaml/node.d @@ -98,7 +98,7 @@ package class YAMLContainer(T) if (!Node.allowed!T): YAMLObject } else { - return format("YAMLContainer(", value_.toString(), ")"); + return format("YAMLContainer(%s)", value_.toString()); } } diff --git a/dyaml/reader.d b/dyaml/reader.d index 9bf916d..22f9238 100644 --- a/dyaml/reader.d +++ b/dyaml/reader.d @@ -319,8 +319,8 @@ final class Reader catch(UTFException e) { const position = stream_.position; - throw new ReaderException(format("Unicode decoding error between bytes ", - oldPosition, " and ", position, " : ", e.msg)); + throw new ReaderException(format("Unicode decoding error between bytes %s and %s : %s", + oldPosition, position, e.msg)); } catch(ReadException e) { diff --git a/dyaml/representer.d b/dyaml/representer.d index a785cb1..3e5156d 100644 --- a/dyaml/representer.d +++ b/dyaml/representer.d @@ -152,7 +152,7 @@ final class Representer * //The node is guaranteed to be MyStruct as we add representer for MyStruct. * auto value = node.as!MyStruct; * //Using custom scalar format, x:y:z. - * auto scalar = format(value.x, ":", value.y, ":", value.z); + * auto scalar = format("%s:%s:%s", value.x, value.y, value.z); * //Representing as a scalar, with custom tag to specify this data type. * return representer.representScalar("!mystruct.tag", scalar); * } @@ -199,7 +199,7 @@ final class Representer * ///Useful for Node.as!string . * override string toString() * { - * return format("MyClass(", x, ", ", y, ", ", z, ")"); + * return format("MyClass(%s, %s, %s)", x, y, z); * } * } * @@ -209,7 +209,7 @@ final class Representer * //The node is guaranteed to be MyClass as we add representer for MyClass. * auto value = node.as!MyClass; * //Using custom scalar format, x:y:z. - * auto scalar = format(value.x, ":", value.y, ":", value.z); + * auto scalar = format("%s:%s:%s", value.x, value.y, value.z); * //Representing as a scalar, with custom tag to specify this data type. * return representer.representScalar("!myclass.tag", scalar); * } @@ -268,7 +268,7 @@ final class Representer * Node representMyStruct(ref Node node, Representer representer) * { * auto value = node.as!MyStruct; - * auto scalar = format(value.x, ":", value.y, ":", value.z); + * auto scalar = format("%s:%s:%s", value.x, value.y, value.z); * return representer.representScalar("!mystruct.tag", scalar); * } * -------------------- @@ -661,7 +661,7 @@ class MyClass ///Useful for Node.as!string . override string toString() @trusted { - return format("MyClass(", x, ", ", y, ", ", z, ")"); + return format("MyClass(%s, %s, %s)", x, y, z); } } diff --git a/dyaml/scanner.d b/dyaml/scanner.d index 2482619..970feb3 100644 --- a/dyaml/scanner.d +++ b/dyaml/scanner.d @@ -281,8 +281,8 @@ final class Scanner if(checkPlain()) {return fetchPlain();} throw new Error(format("While scanning for the next token, found " - "character \'", c, "\', index ",to!int(c), - " that cannot start any token"), reader_.mark); + "character \'%s\', index %s that cannot start any token" + , c, to!int(c)), reader_.mark); }