dlang-community / D-YAML

YAML parser and emitter for the D programming language
https://dlang-community.github.io/D-YAML/
Boost Software License 1.0
118 stars 38 forks source link

Dumper doesn't dump yaml document #50

Closed ghost closed 7 years ago

ghost commented 7 years ago

I tried this code in DMD 2.071.0,:

import std.stdio;

import yaml;

void main() {
    char[] test =   "Hello World : [Hello, World]\n"
                    "Answer: 42".dup;
    //Read the input.
    Node root = Loader.fromString(test).load();

    //Display the data read.
    foreach(string word; root["Hello World"])
    {
        writeln(word);
    }
    writeln("The answer is ", root["Answer"].as!int);

    //Dump the loaded document to output.yaml.
    Dumper("output.yaml").dump(root);
}

then this code dumped this.:

[239, 187, 191][37, 89, 65, 77, 76, 32][49, 46, 49][10][45, 45, 45][10][72, 101, 108, 108, 111][32][87, 111, 114, 108, 100][58][32][91][72, 101, 108, 108, 111][44][32][87, 111, 114, 108, 100][93][10][65, 110, 115, 119, 101, 114][58][32][52, 50][10]

I think this is caused by dyaml.stream's writing buffer as ubyte[], not char[]. https://github.com/kiith-sa/D-YAML/blob/master/source/dyaml/stream.d#L64

forbjok commented 7 years ago

I ran into the same thing yesterday, although using the dyaml-dlang-tour version, since this one is broken and doesn't even compile at the moment.

forbjok commented 7 years ago

I think this is caused by dyaml.stream's writing buffer as ubyte[], not char[].

It seems you were correct. I created a pull request for this fix.