Added a char[] fromString.

This commit is contained in:
Ferdinand Majerech 2014-07-31 02:08:08 +02:00
parent 24a8e945bd
commit e919f4be51

View file

@ -129,9 +129,26 @@ struct Loader
{ {
return Loader(cast(ubyte[])data.dup); return Loader(cast(ubyte[])data.dup);
} }
/// Construct a Loader to load YAML from a string (char []).
///
/// Params: data = String to load YAML from. $(B will) be overwritten during
/// parsing as D:YAML reuses memory. Use data.dup if you don't
/// want to modify the original string.
///
/// Returns: Loader loading YAML from given string.
///
/// Throws:
///
/// YAMLException if data could not be read (e.g. a decoding error)
static Loader fromString(char[] data) @safe
{
return Loader(cast(ubyte[])data);
}
///
unittest unittest
{ {
assert(Loader.fromString("42").load().as!int == 42); assert(Loader.fromString(cast(char[])"42").load().as!int == 42);
} }
import std.stream; import std.stream;