0

Suppose that I have a YAML entry like foo: bar. Can I use yaml-cpp to rename the key foo to buz without having to copy all the content? In other words, I know that I can do this:

YAML::Node node = YAML::Load("foo:bar");
YAML::Node new_node;
new_node["buz"] = node["foo"];

However, this seems wasteful and I wonder if there is a built-in ability to just rename the key foo?

space_voyager
  • 1,984
  • 3
  • 20
  • 31

1 Answers1

2

Well you can do something like

YAML::Node node = YAML::Load("foo: bar");
for (auto it = node.begin(); it != node.end(); ++it) {
  if (it->first.as<std::string>() == "foo") {
    it->first = "buz";
    break;
  }
}

For all I know, yaml-cpp stores its mapping items as list of pairs, so a lookup would execute a loop like this anyway.

flyx
  • 35,506
  • 7
  • 89
  • 126