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.array;
import std.string;
import std.conv;
alias to!string str;
///Base class for all exceptions thrown by D:YAML.
@ -45,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 format(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 " ~ clamped(line_) ~ ",column " ~ clamped(column_);
}
}

View file

@ -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)
{

View file

@ -24,6 +24,7 @@ import std.format;
import std.math;
import std.stream;
import std.typecons;
import std.string;
import dyaml.exception;
import dyaml.node;
@ -151,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);
* }
@ -198,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);
* }
* }
*
@ -208,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);
* }
@ -267,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);
* }
* --------------------
@ -592,10 +593,9 @@ Node representPairs(ref Node node, Representer representer) @system
}
//Unittests
//These should really all be encapsulated in unittests.
private:
import std.string;
import dyaml.dumper;
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.
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);
}
@ -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);
}
}
@ -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.
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);
}

View file

@ -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);
}