2011-08-16 12:53:13 +00:00
|
|
|
import std.stdio;
|
|
|
|
import std.string;
|
2018-04-27 03:17:09 +00:00
|
|
|
import dyaml;
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
struct Color
|
|
|
|
{
|
|
|
|
ubyte red;
|
|
|
|
ubyte green;
|
|
|
|
ubyte blue;
|
2012-01-23 14:57:26 +00:00
|
|
|
|
2019-01-15 07:37:50 +00:00
|
|
|
this(ubyte r, ubyte g, ubyte b) @safe
|
2012-01-23 14:57:26 +00:00
|
|
|
{
|
2019-01-15 07:37:50 +00:00
|
|
|
red = r;
|
|
|
|
green = g;
|
|
|
|
blue = b;
|
2012-01-23 14:57:26 +00:00
|
|
|
}
|
2011-10-17 10:53:38 +00:00
|
|
|
|
2019-01-15 07:37:50 +00:00
|
|
|
this(const Node node, string tag) @safe
|
|
|
|
{
|
|
|
|
if (tag == "!color-mapping")
|
2011-10-17 10:53:38 +00:00
|
|
|
{
|
2019-01-15 07:37:50 +00:00
|
|
|
//Will throw if a value is missing, is not an integer, or is out of range.
|
|
|
|
red = node["r"].as!ubyte;
|
|
|
|
green = node["g"].as!ubyte;
|
|
|
|
blue = node["b"].as!ubyte;
|
2011-10-17 10:53:38 +00:00
|
|
|
}
|
2019-01-15 07:37:50 +00:00
|
|
|
else
|
2011-10-17 10:53:38 +00:00
|
|
|
{
|
2019-01-15 07:37:50 +00:00
|
|
|
string value = node.as!string;
|
|
|
|
|
|
|
|
if(value.length != 6)
|
|
|
|
{
|
|
|
|
throw new Exception("Invalid color: " ~ value);
|
|
|
|
}
|
|
|
|
//We don't need to check for uppercase chars this way.
|
|
|
|
value = value.toLower();
|
|
|
|
|
|
|
|
//Get value of a hex digit.
|
|
|
|
uint hex(char c)
|
|
|
|
{
|
|
|
|
import std.ascii;
|
|
|
|
if(!std.ascii.isHexDigit(c))
|
|
|
|
{
|
|
|
|
throw new Exception("Invalid color: " ~ value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(std.ascii.isDigit(c))
|
|
|
|
{
|
|
|
|
return c - '0';
|
|
|
|
}
|
|
|
|
return c - 'a' + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
red = cast(ubyte)(16 * hex(value[0]) + hex(value[1]));
|
|
|
|
green = cast(ubyte)(16 * hex(value[2]) + hex(value[3]));
|
|
|
|
blue = cast(ubyte)(16 * hex(value[4]) + hex(value[5]));
|
2011-10-17 10:53:38 +00:00
|
|
|
}
|
2019-01-15 07:37:50 +00:00
|
|
|
}
|
2011-08-16 12:53:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 07:37:50 +00:00
|
|
|
void main(string[] args)
|
2011-08-16 12:53:13 +00:00
|
|
|
{
|
2019-01-15 07:37:50 +00:00
|
|
|
auto red = Color(255, 0, 0);
|
2011-08-16 12:53:13 +00:00
|
|
|
auto orange = Color(255, 255, 0);
|
|
|
|
|
2019-01-15 07:37:50 +00:00
|
|
|
string path = "input.yaml";
|
|
|
|
if (args.length > 1)
|
2011-08-16 12:53:13 +00:00
|
|
|
{
|
2019-01-15 07:37:50 +00:00
|
|
|
path = args[1];
|
|
|
|
}
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2019-01-15 07:37:50 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
auto root = Loader.fromFile(path).load();
|
2011-08-16 12:53:13 +00:00
|
|
|
|
2014-08-01 15:09:05 +00:00
|
|
|
if(root["scalar-red"].as!Color == red &&
|
|
|
|
root["mapping-red"].as!Color == red &&
|
|
|
|
root["scalar-orange"].as!Color == orange &&
|
2011-10-22 15:06:32 +00:00
|
|
|
root["mapping-orange"].as!Color == orange)
|
2011-08-16 12:53:13 +00:00
|
|
|
{
|
|
|
|
writeln("SUCCESS");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(YAMLException e)
|
|
|
|
{
|
|
|
|
writeln(e.msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
writeln("FAILURE");
|
|
|
|
}
|