jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.78k forks source link

How to preserve Double Quotes for explicit string values using Emitter? #1199

Closed Levi-Armstrong closed 12 months ago

Levi-Armstrong commented 12 months ago

It looks like there is no way to reproduce the following yaml using the Emitter. I would assume that if this can be parsed then there should be a way to reproduce the exact contents using the Emitter. I tried calling SetStringFormat(YAML::DoubleQuoted) but this also put double quotes on the keys which is not the same if you are trying to leverage the tag "!' to know if it is an explicit string or not.

config:
  boolean: true
  string: "input_data"
  int: 100
  float: 100.5;

Using SetStringFormat(YAML::DoubleQuoted) which does not produce the same.

"config":
  "boolean": "true"
  "string": "input_data"
  "int": "100"
  "float": "100.5"
jbeder commented 12 months ago

There's no (current) way to do so. The input that's quoted (input_data) will be implicitly tagged as a string, so yaml-cpp doesn't preserve that fact that it was quoted originally when writing to the emitter.