Minor fixes in examples and the 'custom types' tutorial.
This commit is contained in:
parent
278b60e896
commit
6ccda33467
|
@ -202,6 +202,7 @@ Add this to your code to add implicit resolution of ``!color``.
|
|||
//code from the previous example...
|
||||
|
||||
auto resolver = new Resolver;
|
||||
import std.regex;
|
||||
resolver.addImplicitResolver("!color", std.regex.regex("[0-9a-fA-F]{6}"),
|
||||
"0123456789abcdefABCDEF");
|
||||
|
||||
|
@ -302,6 +303,7 @@ such as the color being white.
|
|||
representer.addRepresenter!Color(&representColor);
|
||||
|
||||
auto resolver = new Resolver;
|
||||
import std.regex;
|
||||
resolver.addImplicitResolver("!color", std.regex.regex("[0-9a-fA-F]{6}"),
|
||||
"0123456789abcdefABCDEF");
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import std.ascii;
|
||||
import std.stdio;
|
||||
import std.string;
|
||||
import dyaml.all;
|
||||
|
@ -32,6 +31,7 @@ Color constructColorScalar(ref Node node)
|
|||
//Get value of a hex digit.
|
||||
uint hex(char c)
|
||||
{
|
||||
import std.ascii;
|
||||
if(!std.ascii.isHexDigit(c))
|
||||
{
|
||||
throw new Exception("Invalid color: " ~ value);
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
Hello World :
|
||||
- Hello
|
||||
- World
|
||||
Hello World : [Hello, World]
|
||||
Answer : 42
|
||||
|
|
|
@ -43,6 +43,7 @@ void main()
|
|||
representer.addRepresenter!Color(&representColor);
|
||||
|
||||
auto resolver = new Resolver;
|
||||
import std.regex;
|
||||
resolver.addImplicitResolver("!color", std.regex.regex("[0-9a-fA-F]{6}"),
|
||||
"0123456789abcdefABCDEF");
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import std.ascii;
|
||||
import std.stdio;
|
||||
import std.string;
|
||||
import dyaml.all;
|
||||
|
@ -32,6 +31,7 @@ Color constructColorScalar(ref Node node)
|
|||
//Get value of a hex digit.
|
||||
uint hex(char c)
|
||||
{
|
||||
import std.ascii;
|
||||
if(!std.ascii.isHexDigit(c))
|
||||
{
|
||||
throw new Exception("Invalid color: " ~ value);
|
||||
|
@ -79,6 +79,7 @@ void main()
|
|||
constructor.addConstructorMapping("!color-mapping", &constructColorMapping);
|
||||
|
||||
auto resolver = new Resolver;
|
||||
import std.regex;
|
||||
resolver.addImplicitResolver("!color", std.regex.regex("[0-9a-fA-F]{6}"),
|
||||
"0123456789abcdefABCDEF");
|
||||
|
||||
|
|
|
@ -12,14 +12,14 @@ void help()
|
|||
{
|
||||
string help =
|
||||
"D:YAML benchmark\n"
|
||||
"Copyright (C) 2011 Ferdinand Majerech\n"
|
||||
"Copyright (C) 2011-2014 Ferdinand Majerech\n"
|
||||
"Usage: yaml_bench [OPTION ...] [YAML_FILE]\n"
|
||||
"\n"
|
||||
"Loads and optionally extracts data and/or dumps a YAML file.\n"
|
||||
"\n"
|
||||
"Available options:\n"
|
||||
" -h --help Show this help information.\n"
|
||||
" -g --get Extract data from the file (using Node.get()).\n"
|
||||
" -g --get Extract data from the file (using Node.as()).\n"
|
||||
" -d --dump Dump the loaded data (to YAML_FILE.dump).\n"
|
||||
" -r --runs=NUM Repeat the benchmark NUM times.\n";
|
||||
writeln(help);
|
||||
|
|
|
@ -36,7 +36,7 @@ static this()
|
|||
generators["set"] = &genSet;
|
||||
}
|
||||
|
||||
real randomNormalized(in string distribution = "linear")
|
||||
real randomNormalized(const string distribution = "linear")
|
||||
{
|
||||
auto generator = Random(unpredictableSeed());
|
||||
const r = uniform!"[]"(0.0L, 1.0L, generator);
|
||||
|
@ -55,17 +55,17 @@ real randomNormalized(in string distribution = "linear")
|
|||
}
|
||||
}
|
||||
|
||||
long randomLong(in long min, in long max, in string distribution = "linear")
|
||||
long randomLong(const long min, const long max, const string distribution = "linear")
|
||||
{
|
||||
return min + cast(long)round((max - min) * randomNormalized(distribution));
|
||||
}
|
||||
|
||||
real randomReal(in real min, in real max, in string distribution = "linear")
|
||||
real randomReal(const real min, const real max, const string distribution = "linear")
|
||||
{
|
||||
return min + (max - min) * randomNormalized(distribution);
|
||||
}
|
||||
|
||||
char randomChar(in string chars)
|
||||
char randomChar(const string chars)
|
||||
{
|
||||
return chars[randomLong(0, chars.length - 1)];
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ Node genBinary(bool root = false)
|
|||
return Node(result);
|
||||
}
|
||||
|
||||
Node nodes(in bool root, Node range, in string tag, in bool set = false)
|
||||
Node nodes(const bool root, Node range, const string tag, const bool set = false)
|
||||
{
|
||||
auto types = config["collection-keys"].as!bool ? typesCollection : [];
|
||||
types ~= (set ? typesScalarKey : typesScalar);
|
||||
|
@ -244,13 +244,13 @@ Node genPairs(bool root = false)
|
|||
return pairs(root, complex, range, "tag:yaml.org,2002:pairs");
|
||||
}
|
||||
|
||||
Node generateNode(in string type, bool root = false)
|
||||
Node generateNode(const string type, bool root = false)
|
||||
{
|
||||
++totalNodes;
|
||||
return generators[type](root);
|
||||
}
|
||||
|
||||
Node[] generate(in string configFileName)
|
||||
Node[] generate(const string configFileName)
|
||||
{
|
||||
config = Loader(configFileName).load();
|
||||
|
||||
|
|
Loading…
Reference in a new issue