如何将带有前导零的数字字符串转储为yaml-cpp中的有效yaml字符串? [英] How to dump a digit string with leading zeros, as a valid yaml string in yaml-cpp?
问题描述
使用yaml-cpp中的引号不会转义使用前导零创建yaml字符串.因此,将字符串写入texfile是无效的yaml-string.根据yaml 1.2规范,leading_zeros: 00005
为5(尝试一下:
Creating a yaml string with leading zeros is not escaped with quotes in yaml-cpp. So writing the string to a texfile is not a valid yaml-string.leading_zeros: 00005
is 5 according to the specification yaml 1.2 (Try yourself: http://www.yamllint.com/)
YAML::Node node;
node["leading_zeros"] = "00005";
std::cout << YAML::Dump(node)<<std::endl;
// output: leading_zeros: 00005
// instead of:leading_zeros: "00005"
如何使yaml-cpp逸出前导零的字符串?因此,不会从其他Yaml解析器中将其解释为整数吗?
How to bring yaml-cpp to escape a string with leading zeros? So that is would not be interpreted as integer from other yaml parser?
手动逃避似乎不是正确的答案.
Escaping manually does not seem to be the correct answer.
node["leading_zeros"] = "\"00005\"";
更新: 数字值存储在YAML :: Node中!我很确定这是一个错误.
Update: The digit value is stored in a YAML::Node! I am pretty sure it is a bug.
推荐答案
直接使用YAML::Emitter
:
YAML::Emitter out;
out << YAML::BeginMap;
out << YAML::Key << "leading_zeroes" << YAML::Value;
out << YAML::Value << YAML::DoubleQuoted << "00005";
out << YAML::EndMap;
这篇关于如何将带有前导零的数字字符串转储为yaml-cpp中的有效yaml字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!