Implements the empty range primitive.
Implements the front range primitive.
Load single YAML document.
Set stream name. Used in debugging messages.
Implements the popFront range primitive.
Specify custom Resolver to use.
Construct a Loader to load YAML from a buffer.
Construct a Loader to load YAML from a file.
Construct a Loader to load YAML from a string.
Load single YAML document from a file:
write("example.yaml", "Hello world!"); auto rootNode = Loader.fromFile("example.yaml").load(); assert(rootNode == "Hello world!");
Load single YAML document from an already-opened file:
// Open a temporary file auto file = File.tmpfile; // Write valid YAML file.write("Hello world!"); // Return to the beginning file.seek(0); // Load document auto rootNode = Loader.fromFile(file).load(); assert(rootNode == "Hello world!");
Load all YAML documents from a file:
import std.array : array; import std.file : write; write("example.yaml", "---\n"~ "Hello world!\n"~ "...\n"~ "---\n"~ "Hello world 2!\n"~ "...\n" ); auto nodes = Loader.fromFile("example.yaml").array; assert(nodes.length == 2);
Iterate over YAML documents in a file, lazily loading them:
import std.file : write; write("example.yaml", "---\n"~ "Hello world!\n"~ "...\n"~ "---\n"~ "Hello world 2!\n"~ "...\n" ); auto loader = Loader.fromFile("example.yaml"); foreach(ref node; loader) { //Do something }
Load YAML from a string:
string yaml_input = ("red: '#ff0000'\n" ~ "green: '#00ff00'\n" ~ "blue: '#0000ff'"); auto colors = Loader.fromString(yaml_input).load(); foreach(string color, string value; colors) { // Do something with the color and its value... }
Load a file into a buffer in memory and then load YAML from that buffer:
import std.file : read, write; import std.stdio : writeln; // Create a yaml document write("example.yaml", "---\n"~ "Hello world!\n"~ "...\n"~ "---\n"~ "Hello world 2!\n"~ "...\n" ); try { string buffer = readText("example.yaml"); auto yamlNode = Loader.fromString(buffer); // Read data from yamlNode here... } catch(FileException e) { writeln("Failed to read file 'example.yaml'"); }
Use a custom resolver to support custom data types and/or implicit tags:
import std.file : write; // Create a yaml document write("example.yaml", "---\n"~ "Hello world!\n"~ "...\n" ); auto loader = Loader.fromFile("example.yaml"); // Add resolver expressions here... // loader.resolver.addImplicitResolver(...); auto rootNode = loader.load();
Loads YAML documents from files or char[].
User specified Constructor and/or Resolver can be used to support new tags / data types.