| 625 | } |
| 626 | |
| 627 | void Param::remove(const std::string& key) |
| 628 | { |
| 629 | std::string keyname = key; |
| 630 | if (!key.empty() && key.back() == ':') // delete section |
| 631 | { |
| 632 | keyname = key.substr(0, key.length() - 1); |
| 633 | |
| 634 | ParamNode* node_parent = root_.findParentOf(keyname); |
| 635 | if (node_parent != nullptr) |
| 636 | { |
| 637 | Param::ParamNode::NodeIterator it = node_parent->findNode(node_parent->suffix(keyname)); |
| 638 | if (it != node_parent->nodes.end()) |
| 639 | { |
| 640 | std::string name = it->name; |
| 641 | node_parent->nodes.erase(it); // will automatically delete subnodes |
| 642 | if (node_parent->nodes.empty() && node_parent->entries.empty()) |
| 643 | { |
| 644 | // delete last section name (could be partial) |
| 645 | remove(keyname.substr(0, keyname.size() - name.size())); // keep last ':' to indicate deletion of a section |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | else |
| 651 | { |
| 652 | ParamNode* node = root_.findParentOf(keyname); |
| 653 | if (node != nullptr) |
| 654 | { |
| 655 | std::string entryname = node->suffix(keyname); // get everything beyond last ':' |
| 656 | Param::ParamNode::EntryIterator it = node->findEntry(entryname); |
| 657 | if (it != node->entries.end()) |
| 658 | { |
| 659 | node->entries.erase(it); // delete entry |
| 660 | if (node->nodes.empty() && node->entries.empty()) |
| 661 | { |
| 662 | // delete if section is now empty |
| 663 | remove(keyname.substr(0, keyname.length() - entryname.length())); // keep last ':' to indicate deletion of a section |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | void Param::removeAll(const std::string& prefix) |
| 671 | { |