certik / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

YAML::BeginDoc should add [%YAML:1.0] rather than 19! #167

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

YAML::Node config = YAML::LoadFile("config.yaml");
config["lastLogin"] = getCurrentDateTime();

std::ofstream fout("config.yaml");
fout << YAML::BeginDoc;
fout << config;
fout << YAML::EndDoc;

What is the expected output? What do you see instead?
In my view YAML::BeginDoc should add [%YAML:1.0], otherwise this yaml docs will 
not be compatible to other yaml parser. However, it added 19 (the enum value)

What version of the product are you using? On what operating system?
Cloned 23-07-2012 code from repository.

Please provide any additional information below.
Though I could add [fout << "%YAML:1.0\n";] but this looks better/systematic 
[fout << YAML::BeginDoc;] as yaml version support will change in future etc.

Original issue reported on code.google.com by rudrapou...@gmail.com on 23 Jul 2012 at 1:14

GoogleCodeExporter commented 9 years ago
YAML::BeginDoc is only intended to be used with the emitter. When streaming a 
node, it automatically creates an emitter for you and uses YAML::BeginDoc. 
There's no way to add metadata to a standard stream, so we can't have 
YAML::BeginDoc do anything.

Also, yaml-cpp outputs YAML 1.2, not YAML 1.0, so if it emitted any version 
information, it would say that.

There's an existing case (Issue 163) to add the ability to emit directives, so 
you can follow that. However, to use this, you'd (probably) need to use the 
emitter manually, not stream the node.

Original comment by jbe...@gmail.com on 24 Jul 2012 at 4:45