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/parser_context.cpp b/src/parser_context.cpp
index d1ebe06..17f6604 100644
--- a/src/parser_context.cpp
+++ b/src/parser_context.cpp
@@ -39,20 +39,10 @@
void ParserContext::pushPathFragment(const dataNode_& node)
{
- auto pushNode = [] (auto& where, const auto& what) {
- if (std::holds_alternative<nodeup_>(what.m_suffix)) {
- if (!where.m_nodes.empty()) { // Allow going up, when already at root
- where.m_nodes.pop_back();
- }
- } else {
- where.m_nodes.push_back(what);
- }
- };
-
if (m_curPath.type() == typeid(dataPath_)) {
- pushNode(boost::get<dataPath_>(m_curPath), node);
+ boost::get<dataPath_>(m_curPath).pushFragment(node);
} else {
- pushNode(boost::get<schemaPath_>(m_curPath), dataNodeToSchemaNode(node));
+ boost::get<schemaPath_>(m_curPath).pushFragment(dataNodeToSchemaNode(node));
}
}