diff options
-rw-r--r-- | common/config-file.cpp | 45 | ||||
-rw-r--r-- | common/config-file.h | 2 |
2 files changed, 38 insertions, 9 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp index f96a4dd2ce..f8d31b783b 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -276,14 +276,7 @@ void ConfigFile::setKey(const String &key, const String §ion, const String & _sections.push_back(newSection); } else { - KeyValue *kv = s->getKey(key); - if (!kv) { - KeyValue newKV; - newKV.key = key; - newKV.value = value; - s->keys.push_back(newKV); - } else - kv->value = value; + s->setKey(key, value); } } @@ -305,4 +298,40 @@ const ConfigFile::Section *ConfigFile::getSection(const String §ion) const { return 0; } +bool ConfigFile::Section::hasKey(const String &key) const { + return getKey(key) != 0; +} + +const ConfigFile::KeyValue* ConfigFile::Section::getKey(const String &key) const { + for (List<KeyValue>::const_iterator i = keys.begin(); i != keys.end(); ++i) { + if (scumm_stricmp(key.c_str(), i->key.c_str())) { + return &(*i); + } + } + return 0; +} + +void ConfigFile::Section::setKey(const String &key, const String &value) { + for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) { + if (scumm_stricmp(key.c_str(), i->key.c_str())) { + i->value = value; + return; + } + } + + KeyValue newKV; + newKV.key = key; + newKV.value = value; + keys.push_back(newKV); +} + +void ConfigFile::Section::removeKey(const String &key) { + for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) { + if (scumm_stricmp(key.c_str(), i->key.c_str())) { + keys.erase(i); + return; + } + } +} + } // End of namespace Common diff --git a/common/config-file.h b/common/config-file.h index efea9f2ace..000e8ea437 100644 --- a/common/config-file.h +++ b/common/config-file.h @@ -71,7 +71,7 @@ public: String comment; bool hasKey(const String &key) const; - KeyValue* getKey(const String &key) const; + const KeyValue* getKey(const String &key) const; void setKey(const String &key, const String &value); void removeKey(const String &key); }; |