Merge pathToAbsoluteSchemaString and pathToSchemaString

These functions did almost the same thing, the only difference was that
the former inserted module prefixes everyhwere and the other didn't.
The new function takes an argument specifying whether to insert prefixes
everyhwere.

pathToSchemaString also checks whether a path is absolute or relative
and prepends a slash. This means, that it's no longer possible to
convert and absolute path to a string with no leading slash. The
StaticSchema class had to be changed accordingly, because it stored
absolute paths in strings without a leading slash (because it was
designed before absolute paths existed).

The fact that this was split into two functions helped find an error in
a later patch.

Change-Id: I6112cb5982919b51b61152f355771a52dd467c6e
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index ad2025c..47e0884 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -14,7 +14,7 @@
 
 StaticSchema::StaticSchema()
 {
-    m_nodes.emplace("", std::unordered_map<std::string, NodeType>());
+    m_nodes.emplace("/", std::unordered_map<std::string, NodeType>());
 }
 
 const std::unordered_map<std::string, NodeType>& StaticSchema::children(const std::string& name) const
@@ -38,7 +38,7 @@
 
 bool StaticSchema::isContainer(const schemaPath_& location, const ModuleNodePair& node) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     auto fullName = fullNodeName(location, node);
     if (!nodeExists(locationString, fullName))
         return false;
@@ -57,7 +57,7 @@
 
 bool StaticSchema::listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     assert(isList(location, node));
 
     const auto& child = children(locationString).at(fullNodeName(location, node));
@@ -67,7 +67,7 @@
 
 const std::set<std::string> StaticSchema::listKeys(const schemaPath_& location, const ModuleNodePair& node) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     assert(isList(location, node));
 
     const auto& child = children(locationString).at(fullNodeName(location, node));
@@ -77,7 +77,7 @@
 
 bool StaticSchema::isList(const schemaPath_& location, const ModuleNodePair& node) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     auto fullName = fullNodeName(location, node);
     if (!nodeExists(locationString, fullName))
         return false;
@@ -100,7 +100,7 @@
 {
     if (!isContainer(location, node))
         return false;
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     return boost::get<yang::container>(children(locationString).at(fullNodeName(location, node))).m_presence == yang::ContainerTraits::Presence;
 }
 
@@ -172,7 +172,7 @@
 
 const std::set<std::string> StaticSchema::validIdentities(const schemaPath_& location, const ModuleNodePair& node, const Prefixes prefixes) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     assert(isLeaf(location, node));
 
     const auto& child = children(locationString).at(fullNodeName(location, node));
@@ -207,7 +207,7 @@
 
 bool StaticSchema::isLeaf(const schemaPath_& location, const ModuleNodePair& node) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     auto fullName = fullNodeName(location, node);
     if (!nodeExists(locationString, fullName))
         return false;
@@ -219,14 +219,22 @@
 {
     std::string res = path;
     auto pos = res.find_last_of('/');
-    if (pos != res.npos)
+    if (pos == 0) { // path had only one path fragment - "/something:something"
+        res.erase(0, 1);
+        return res;
+    }
+    if (pos != res.npos) { // path had more fragments
         res.erase(0, pos);
+        return res;
+    }
+
+    // path was empty
     return res;
 }
 
 yang::LeafDataTypes StaticSchema::leafrefBase(const schemaPath_& location, const ModuleNodePair& node) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     auto leaf{boost::get<yang::leaf>(children(locationString).at(fullNodeName(location, node)))};
     auto locationOfSource = stripLastNodeFromPath(leaf.m_leafRefSource);
     auto nameOfSource = lastNodeOfSchemaPath(leaf.m_leafRefSource);
@@ -235,13 +243,13 @@
 
 yang::LeafDataTypes StaticSchema::leafType(const schemaPath_& location, const ModuleNodePair& node) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     return boost::get<yang::leaf>(children(locationString).at(fullNodeName(location, node))).m_type;
 }
 
 const std::set<std::string> StaticSchema::enumValues(const schemaPath_& location, const ModuleNodePair& node) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(location);
+    std::string locationString = pathToSchemaString(location, Prefixes::Always);
     assert(isLeaf(location, node));
 
     const auto& child = children(locationString).at(fullNodeName(location, node));
@@ -253,7 +261,7 @@
 // for this class.
 std::set<std::string> StaticSchema::childNodes(const schemaPath_& path, const Recursion) const
 {
-    std::string locationString = pathToAbsoluteSchemaString(path);
+    std::string locationString = pathToSchemaString(path, Prefixes::Always);
     std::set<std::string> res;
 
     auto childrenRef = children(locationString);