You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
E.g. if I render a string with the value true or 1.1, when parsed back they become a boolean and a number respectively.
Is there a way to determine if a certain string doesn't round trip and therefore needs quotes added when emitting it?
The text was updated successfully, but these errors were encountered:
It has been a while since I raised this, and we made a workaround in the meantime, but the situation was roughly this:
We have a function that takes some object provided by the user and converts it to YAML
It uses YAML::Emitter's operator<< to output the object
Previously, if the user object was a string, it would just call out << str, which blindly outputs the string without consideration of whether it has some special format such that when parsed back it turns into something else such as a number, boolean, null etc.
This was causing problems when the user object was something like ["my", "true", "love"], where the "true" value would be printed out without the quotes, so when parsed back, it would become the boolean value true instead of the string "true"
The workaround was to create a dedicated "render string" function that matches the input against a laundry list of regexes, such as those for all the number formats, infinities, true/false etc., and if any of them match, does out << YAML::SingleQuoted first. Since this looks like a common operation for anyone who would like to output YAML from user data, I was wondering if there was some level of support in the library itself, such as an "is special value" function that encapsulates the check for whether the string would round-trip without the quotes.
E.g. if I render a string with the value
true
or1.1
, when parsed back they become a boolean and a number respectively.Is there a way to determine if a certain string doesn't round trip and therefore needs quotes added when emitting it?
The text was updated successfully, but these errors were encountered: