std.string.format compatibility fixes (by John Colvin)

This commit is contained in:
Kiith-Sa 2012-12-27 21:21:18 +01:00
commit 163b3c9d54
4 changed files with 18 additions and 15 deletions

View file

@ -11,6 +11,9 @@ module dyaml.exception;
import std.algorithm; import std.algorithm;
import std.array; import std.array;
import std.string; import std.string;
import std.conv;
alias to!string str;
///Base class for all exceptions thrown by D:YAML. ///Base class for all exceptions thrown by D:YAML.
@ -45,8 +48,8 @@ struct Mark
string toString() const @trusted string toString() const @trusted
{ {
//Line/column numbers start at zero internally, make them start at 1. //Line/column numbers start at zero internally, make them start at 1.
string clamped(ushort v){return format(v + 1, v == ushort.max ? " or higher" : "");} string clamped(ushort v){return str(v + 1) ~ (v == ushort.max ? " or higher" : "");}
return format("line ", clamped(line_), ",column ", clamped(column_)); return "line " ~ clamped(line_) ~ ",column " ~ clamped(column_);
} }
} }

View file

@ -319,8 +319,8 @@ final class Reader
catch(UTFException e) catch(UTFException e)
{ {
const position = stream_.position; const position = stream_.position;
throw new ReaderException(format("Unicode decoding error between bytes ", throw new ReaderException(format("Unicode decoding error between bytes %s and %s : %s",
oldPosition, " and ", position, " : ", e.msg)); oldPosition, position, e.msg));
} }
catch(ReadException e) catch(ReadException e)
{ {

View file

@ -24,6 +24,7 @@ import std.format;
import std.math; import std.math;
import std.stream; import std.stream;
import std.typecons; import std.typecons;
import std.string;
import dyaml.exception; import dyaml.exception;
import dyaml.node; import dyaml.node;
@ -151,7 +152,7 @@ final class Representer
* //The node is guaranteed to be MyStruct as we add representer for MyStruct. * //The node is guaranteed to be MyStruct as we add representer for MyStruct.
* auto value = node.as!MyStruct; * auto value = node.as!MyStruct;
* //Using custom scalar format, x:y:z. * //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. * //Representing as a scalar, with custom tag to specify this data type.
* return representer.representScalar("!mystruct.tag", scalar); * return representer.representScalar("!mystruct.tag", scalar);
* } * }
@ -198,7 +199,7 @@ final class Representer
* ///Useful for Node.as!string . * ///Useful for Node.as!string .
* override string toString() * override string toString()
* { * {
* return format("MyClass(", x, ", ", y, ", ", z, ")"); * return format("MyClass(%s, %s, %s)", x, y, z);
* } * }
* } * }
* *
@ -208,7 +209,7 @@ final class Representer
* //The node is guaranteed to be MyClass as we add representer for MyClass. * //The node is guaranteed to be MyClass as we add representer for MyClass.
* auto value = node.as!MyClass; * auto value = node.as!MyClass;
* //Using custom scalar format, x:y:z. * //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. * //Representing as a scalar, with custom tag to specify this data type.
* return representer.representScalar("!myclass.tag", scalar); * return representer.representScalar("!myclass.tag", scalar);
* } * }
@ -267,7 +268,7 @@ final class Representer
* Node representMyStruct(ref Node node, Representer representer) * Node representMyStruct(ref Node node, Representer representer)
* { * {
* auto value = node.as!MyStruct; * 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); * return representer.representScalar("!mystruct.tag", scalar);
* } * }
* -------------------- * --------------------
@ -592,10 +593,9 @@ Node representPairs(ref Node node, Representer representer) @system
} }
//Unittests //Unittests
//These should really all be encapsulated in unittests.
private: private:
import std.string;
import dyaml.dumper; import dyaml.dumper;
struct MyStruct struct MyStruct
@ -616,7 +616,7 @@ Node representMyStruct(ref Node node, Representer representer) @system
//The node is guaranteed to be MyStruct as we add representer for MyStruct. //The node is guaranteed to be MyStruct as we add representer for MyStruct.
auto value = node.as!MyStruct; auto value = node.as!MyStruct;
//Using custom scalar format, x:y:z. //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. //Representing as a scalar, with custom tag to specify this data type.
return representer.representScalar("!mystruct.tag", scalar); return representer.representScalar("!mystruct.tag", scalar);
} }
@ -661,7 +661,7 @@ class MyClass
///Useful for Node.as!string . ///Useful for Node.as!string .
override string toString() @trusted override string toString() @trusted
{ {
return format("MyClass(", x, ", ", y, ", ", z, ")"); return format("MyClass(%s, %s, %s)", x, y, z);
} }
} }
@ -671,7 +671,7 @@ Node representMyClass(ref Node node, Representer representer) @system
//The node is guaranteed to be MyClass as we add representer for MyClass. //The node is guaranteed to be MyClass as we add representer for MyClass.
auto value = node.as!MyClass; auto value = node.as!MyClass;
//Using custom scalar format, x:y:z. //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. //Representing as a scalar, with custom tag to specify this data type.
return representer.representScalar("!myclass.tag", scalar); return representer.representScalar("!myclass.tag", scalar);
} }

View file

@ -281,8 +281,8 @@ final class Scanner
if(checkPlain()) {return fetchPlain();} if(checkPlain()) {return fetchPlain();}
throw new Error(format("While scanning for the next token, found " throw new Error(format("While scanning for the next token, found "
"character \'", c, "\', index ",to!int(c), "character \'%s\', index %s that cannot start any token"
" that cannot start any token"), reader_.mark); , c, to!int(c)), reader_.mark);
} }