mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 23:22:24 +01:00
Add a limit to node meta data resolving recursion
This commit is contained in:
parent
d3ee617f37
commit
e17f140be0
@ -191,3 +191,34 @@ void NodeMetadataList::clear()
|
|||||||
}
|
}
|
||||||
m_data.clear();
|
m_data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string NodeMetadata::getString(const std::string &name, unsigned short recursion) const
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string>::const_iterator it;
|
||||||
|
it = m_stringvars.find(name);
|
||||||
|
if (it == m_stringvars.end()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return resolveString(it->second, recursion);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeMetadata::setString(const std::string &name, const std::string &var)
|
||||||
|
{
|
||||||
|
if (var.empty()) {
|
||||||
|
m_stringvars.erase(name);
|
||||||
|
} else {
|
||||||
|
m_stringvars[name] = var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NodeMetadata::resolveString(const std::string &str, unsigned short recursion) const
|
||||||
|
{
|
||||||
|
if (recursion > 1) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
if (str.substr(0, 2) == "${" && str[str.length() - 1] == '}') {
|
||||||
|
return getString(str.substr(2, str.length() - 3), recursion + 1);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -49,28 +49,10 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// Generic key/value store
|
// Generic key/value store
|
||||||
std::string getString(const std::string &name) const
|
std::string getString(const std::string &name, unsigned short recursion = 0) const;
|
||||||
{
|
void setString(const std::string &name, const std::string &var);
|
||||||
std::map<std::string, std::string>::const_iterator i;
|
// Support variable names in values
|
||||||
i = m_stringvars.find(name);
|
std::string resolveString(const std::string &str, unsigned short recursion = 0) const;
|
||||||
if(i == m_stringvars.end())
|
|
||||||
return "";
|
|
||||||
return i->second;
|
|
||||||
}
|
|
||||||
void setString(const std::string &name, const std::string &var)
|
|
||||||
{
|
|
||||||
if(var.empty())
|
|
||||||
m_stringvars.erase(name);
|
|
||||||
else
|
|
||||||
m_stringvars[name] = var;
|
|
||||||
}
|
|
||||||
// support variable names in values
|
|
||||||
std::string resolveString(const std::string &str) const
|
|
||||||
{
|
|
||||||
if(str.substr(0,2) == "${" && str[str.length()-1] == '}')
|
|
||||||
return getString(str.substr(2,str.length()-3));
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
std::map<std::string, std::string> getStrings() const
|
std::map<std::string, std::string> getStrings() const
|
||||||
{
|
{
|
||||||
return m_stringvars;
|
return m_stringvars;
|
||||||
|
Loading…
Reference in New Issue
Block a user