Utility function to create a loader from string (avoids API-break in future).

This commit is contained in:
kiith-sa 2012-11-02 14:31:50 +01:00
parent f493ad540e
commit 4ccd938a43

View file

@ -64,7 +64,7 @@ import dyaml.token;
* "green: '#00ff00'\n"
* "blue: '#0000ff'";
*
* auto colors = Loader(new MemoryStream(cast(char[])yaml_input)).load();
* auto colors = Loader.fromString(yaml_input).load();
*
* foreach(string color, string value; colors)
* {
@ -125,6 +125,20 @@ struct Loader
" for YAML loading: " ~ e.msg);
}
}
/// Construct a Loader to load YAML from a string.
///
/// Params: data = String to load YAML from.
///
/// Returns: Loader loading YAML from given string.
static Loader fromString(string data)
{
return Loader(new MemoryStream(cast(char[])data));
}
unittest
{
assert(Loader.fromString("42").load().as!int == 42);
}
/**
* Construct a Loader to load YAML from a _stream.