modified: dyaml/exception.d
modified: dyaml/representer.d
This commit is contained in:
parent
75e2e7f80a
commit
397ac65baa
|
@ -11,6 +11,7 @@ module dyaml.exception;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.array;
|
import std.array;
|
||||||
import std.string;
|
import std.string;
|
||||||
|
import std.conv;
|
||||||
|
|
||||||
|
|
||||||
///Base class for all exceptions thrown by D:YAML.
|
///Base class for all exceptions thrown by D:YAML.
|
||||||
|
@ -45,7 +46,7 @@ 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 to!string(v + 1) ~ (v == ushort.max ? " or higher" : "");}
|
||||||
return format("line ", clamped(line_), ",column ", clamped(column_));
|
return format("line ", clamped(line_), ",column ", clamped(column_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue