From a6b59c0be1514fd1a9c716f9f6995b80cef7eeb2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 23 Apr 2005 22:28:37 +0000 Subject: Implement some missing methods svn-id: r17780 --- common/config-file.cpp | 45 +++++++++++++++++++++++++++++++++++++-------- common/config-file.h | 2 +- 2 files changed, 38 insertions(+), 9 deletions(-) (limited to 'common') 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::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::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::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); }; -- cgit v1.2.3