Utility function to create a loader from string (avoids API-break in future).
This commit is contained in:
parent
f493ad540e
commit
4ccd938a43
|
@ -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)
|
||||
* {
|
||||
|
@ -126,6 +126,20 @@ struct Loader
|
|||
}
|
||||
}
|
||||
|
||||
/// 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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue