srctree

Robin Linden parent 159409e5 15c1d6ea
dom: Move xpath-helper only used in tests into the test file

inlinesplit
dom/dom.cpp added: 12, removed: 13, total 0
@@ -42,15 +42,6 @@ std::string to_string(Document const &document) {
return std::move(ss).str();
}
 
std::vector<Element const *> nodes_by_xpath(std::reference_wrapper<Node const> root, std::string_view xpath) {
if (!std::holds_alternative<Element>(root.get())) {
return {};
}
 
auto const &element = std::get<Element>(root.get());
return nodes_by_xpath(element, xpath);
}
 
// https://developer.mozilla.org/en-US/docs/Web/XPath
// https://en.wikipedia.org/wiki/XPath
std::vector<Element const *> nodes_by_xpath(std::reference_wrapper<Element const> root, std::string_view xpath) {
 
dom/dom.h added: 12, removed: 13, total 0
@@ -41,7 +41,6 @@ struct Document {
};
 
// reference_wrapper to ensure that the argument isn't a temporary since we return pointers into it.
std::vector<Element const *> nodes_by_xpath(std::reference_wrapper<Node const>, std::string_view);
std::vector<Element const *> nodes_by_xpath(std::reference_wrapper<Element const>, std::string_view);
 
std::string to_string(Document const &node);
 
dom/dom_test.cpp added: 12, removed: 13, total 0
@@ -20,6 +20,15 @@ namespace {
dom::Node create_element_node(std::string_view name, dom::AttrMap attrs, std::vector<dom::Node> children) {
return dom::Element{std::string{name}, std::move(attrs), std::move(children)};
}
 
std::vector<dom::Element const *> nodes_by_xpath(std::reference_wrapper<dom::Node const> root, std::string_view xpath) {
if (!std::holds_alternative<dom::Element>(root.get())) {
return {};
}
 
auto const &element = std::get<dom::Element>(root.get());
return nodes_by_xpath(element, xpath);
}
} // namespace
 
int main() {