Skip to content

Commit 8c2d3b6

Browse files
Merge pull request #60 from Neko-Box-Coder/UniqueKey
Enforcing unique key in yaml
2 parents 85d91ed + 0abc8d8 commit 8c2d3b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Src/runcpp2/ParseUtil.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "runcpp2/Data/ParseCommon.hpp"
33
#include "runcpp2/StringUtil.hpp"
44

5+
#include <unordered_set>
6+
57
runcpp2::NodeRequirement::NodeRequirement() : Name(""),
68
NodeType(),
79
Required(false),
@@ -109,6 +111,22 @@ bool runcpp2::CheckNodeRequirements(ryml::ConstNodeRef node,
109111
return false;
110112
}
111113

114+
//All keys must be unique
115+
{
116+
std::unordered_set<std::string> childKeys;
117+
for(int i = 0; i < node.num_children(); ++i)
118+
{
119+
std::string currentKey = GetKey(node[i]);
120+
if(childKeys.count(currentKey) != 0)
121+
{
122+
ssLOG_ERROR("Duplicate key found for: " << currentKey);
123+
return false;
124+
}
125+
else
126+
childKeys.insert(GetKey(node[i]));
127+
}
128+
}
129+
112130
for(int i = 0; i < requirements.size(); ++i)
113131
{
114132
if(!CheckNodeRequirement( node,

0 commit comments

Comments
 (0)