Refactor getValueAsString and add getSubtree

Will use it elsewhere.

Change-Id: I4bb6ed0418d044d489405bb158b513a05ca70c74
diff --git a/src/utils/libyang.cpp b/src/utils/libyang.cpp
new file mode 100644
index 0000000..0fcce7d
--- /dev/null
+++ b/src/utils/libyang.cpp
@@ -0,0 +1,21 @@
+#include <libyang/Tree_Data.hpp>
+#include "utils/libyang.h"
+
+const char* getValueAsString(const libyang::S_Data_Node& node)
+{
+    if (!node || node->schema()->nodetype() != LYS_LEAF) {
+        throw std::logic_error("retrieveString: invalid node");
+    }
+
+    return libyang::Data_Node_Leaf_List(node).value_str();
+}
+
+libyang::S_Data_Node getSubtree(const libyang::S_Data_Node& start, const char* path)
+{
+    auto set = start->find_path(path);
+    if (set->number() != 1) {
+        throw std::runtime_error("getSubtree: didn't get exactly one match (got " + std::to_string(set->number()) + ")");
+    }
+
+    return set->data().front();
+}