How to specify the output format for Null node in yaml-cpp?

1.9k views Asked by At

I use current(2013/12/12) latest revision of yaml-cpp.

I noticed that both YAML::Load("") and YAML::Load("---\n...") results in a Null node, i.e. YAML::Load("").Type() == YAML::NodeType::Null yet when sent to std::ostream the former outputs an empty string but the latter outputs tilde (~).

I want both nodes to output an empty string. How can I achieve it?

I want to do so because I noticed tilde is interpreted as a string when I use YAML::Load.

Here is the code to show this difference.

#include <yaml-cpp/yaml.h>
#include <iostream>
#include <cassert>

int main() {
    YAML::Node node1 = YAML::Load("");
    YAML::Node node2 = YAML::Load("---\n...");

    assert (node1.Type() == YAML::NodeType::Null);
    assert (node2.Type() == YAML::NodeType::Null);

    std::cout << node1 << std::endl;
    std::cout << node2 << std::endl;
}

/* OUTPUT:

~
*/
1

There are 1 answers

0
Yuki Inoue On BEST ANSWER

According to the Github Issue, this behavior was fixed in 2016.