modified: dyaml/exception.d

modified:   dyaml/representer.d
This commit is contained in:
John-Colvin 2012-12-11 15:32:25 +00:00
parent 75e2e7f80a
commit 397ac65baa
2 changed files with 6 additions and 5 deletions

View file

@ -11,6 +11,7 @@ module dyaml.exception;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
///Base class for all exceptions thrown by D:YAML.
@ -45,7 +46,7 @@ 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" : "");}
string clamped(ushort v){return to!string(v + 1) ~ (v == ushort.max ? " or higher" : "");}
return format("line ", clamped(line_), ",column ", clamped(column_));
}
}

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