aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-04-27 21:31:46 -0400
committerShadowNinja <shadowninja@minetest.net>2014-05-07 17:05:44 -0400
commite17f140be00e9bf4674aa7e8b2338cefc1a6375b (patch)
treef68f8c021d2f8fee0da1ef9ba62cda0f0e90eeb1 /src
parentd3ee617f37984b380ebe32cd37ef1cda66d96c48 (diff)
downloadminetest-e17f140be00e9bf4674aa7e8b2338cefc1a6375b.tar.gz
minetest-e17f140be00e9bf4674aa7e8b2338cefc1a6375b.tar.bz2
minetest-e17f140be00e9bf4674aa7e8b2338cefc1a6375b.zip
Add a limit to node meta data resolving recursion
Diffstat (limited to 'src')
-rw-r--r--src/nodemetadata.cpp31
-rw-r--r--src/nodemetadata.h26
2 files changed, 35 insertions, 22 deletions
diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp
index 911d86d22..4cdd61767 100644
--- a/src/nodemetadata.cpp
+++ b/src/nodemetadata.cpp
@@ -191,3 +191,34 @@ void NodeMetadataList::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;
+}
+
diff --git a/src/nodemetadata.h b/src/nodemetadata.h
index 710270502..6baf3b3d3 100644
--- a/src/nodemetadata.h
+++ b/src/nodemetadata.h
@@ -49,28 +49,10 @@ public:
void clear();
// Generic key/value store
- std::string getString(const std::string &name) const
- {
- std::map<std::string, std::string>::const_iterator i;
- i = m_stringvars.find(name);
- 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::string getString(const std::string &name, unsigned short recursion = 0) const;
+ void setString(const std::string &name, const std::string &var);
+ // Support variable names in values
+ std::string resolveString(const std::string &str, unsigned short recursion = 0) const;
std::map<std::string, std::string> getStrings() const
{
return m_stringvars;