Add enum completion
Change-Id: I5ee7d6359812535d0eef9f70e1b66e205d93cf39
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 522e58a..8b870fc 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -112,8 +112,15 @@
bool YangSchema::leafEnumHasValue(const schemaPath_& location, const ModuleNodePair& node, const std::string& value) const
{
+ auto enums = enumValues(location, node);
+
+ return std::any_of(enums.begin(), enums.end(), [=](const auto& x) { return x == value; });
+}
+
+const std::set<std::string> YangSchema::enumValues(const schemaPath_& location, const ModuleNodePair& node) const
+{
if (!isLeaf(location, node) || leafType(location, node) != yang::LeafDataTypes::Enum)
- return false;
+ return {};
libyang::Schema_Node_Leaf leaf(getSchemaNode(location, node));
auto type = leaf.type();
@@ -126,7 +133,9 @@
enm = type->info()->enums()->enm();
}
- return std::any_of(enm.begin(), enm.end(), [=](const auto& x) { return x->name() == value; });
+ std::set<std::string> enumSet;
+ std::transform(enm.begin(), enm.end(), std::inserter(enumSet, enumSet.end()), [](auto it) { return it->name(); });
+ return enumSet;
}
bool YangSchema::listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const