Browse Source

findTagNodeChild()

master
Odilitime 3 years ago
parent
commit
bc6a942195
  1. 18
      src/parsers/markup/Node.cpp
  2. 1
      src/parsers/markup/Node.h

18
src/parsers/markup/Node.cpp

@ -34,3 +34,21 @@ std::shared_ptr<Node> Node::findTagNodeParent(std::string tag, std::shared_ptr<N @@ -34,3 +34,21 @@ std::shared_ptr<Node> Node::findTagNodeParent(std::string tag, std::shared_ptr<N
}
return Node::findTagNodeParent(tag, node->parent);
}
void Node::findTagNodeChild(std::string tag, std::shared_ptr<Node> node, std::vector< std::shared_ptr<Node> > &results) {
// check self
TagNode *tagNode = dynamic_cast<TagNode*>(node.get());
if (tagNode) {
if (tagNode->tag == tag) {
results.push_back(node);
return;
}
}
// check children
for(auto child : node->children) {
Node::findTagNodeChild(tag, child, results);
}
// not in us or any of our children
return;
}

1
src/parsers/markup/Node.h

@ -25,6 +25,7 @@ public: @@ -25,6 +25,7 @@ public:
std::shared_ptr<Component> component;
static std::shared_ptr<Node> findTagNodeParent(std::string tag, std::shared_ptr<Node> node);
static void findTagNodeChild(std::string tag, std::shared_ptr<Node> node, std::vector< std::shared_ptr<Node> > &results);
virtual std::vector<std::string> getSourceList();
};

Loading…
Cancel
Save