Put empty path checking to a function
Instead of checking for .empty() everywhere I'm pushing path fragments,
do it once in a new function called pushFragment, which resolves nodeup_
fragments.
Change-Id: I2528f814991eed5218d8272ea386bd732a7448a5
diff --git a/src/ast_path.cpp b/src/ast_path.cpp
index 0079962..318aada 100644
--- a/src/ast_path.cpp
+++ b/src/ast_path.cpp
@@ -258,3 +258,27 @@
return res;
}
+
+namespace {
+template <typename NodeType>
+void impl_pushFragment(std::vector<NodeType>& where, const NodeType& what)
+{
+ if (std::holds_alternative<nodeup_>(what.m_suffix)) {
+ if (!where.empty()) { // Allow going up, when already at root
+ where.pop_back();
+ }
+ } else {
+ where.push_back(what);
+ }
+}
+}
+
+void schemaPath_::pushFragment(const schemaNode_& fragment)
+{
+ impl_pushFragment(m_nodes, fragment);
+}
+
+void dataPath_::pushFragment(const dataNode_& fragment)
+{
+ impl_pushFragment(m_nodes, fragment);
+}