diff options
Diffstat (limited to 'common/config-file.cpp')
-rw-r--r-- | common/config-file.cpp | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp index 55941131ac..81e0ae6b45 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -26,19 +26,11 @@ #include "common/system.h" #include "common/textconsole.h" -#define MAXLINELEN 256 - namespace Common { -/** - * Check whether the given string is a valid section or key name. - * For that, it must only consist of letters, numbers, dashes and - * underscores. In particular, white space and "#", "=", "[", "]" - * are not valid! - */ -bool ConfigFile::isValidName(const Common::String &name) { +bool ConfigFile::isValidName(const String &name) { const char *p = name.c_str(); - while (*p && (isalnum(*p) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; return *p == 0; } @@ -116,7 +108,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // is, verify that it only consists of alphanumerics, // periods, dashes and underscores). Mohawk Living Books games // can have periods in their section names. - while (*p && (isalnum(*p) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; if (*p == '\0') @@ -139,7 +131,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // Skip leading whitespaces const char *t = line.c_str(); - while (isspace(*t)) + while (isspace(static_cast<unsigned char>(*t))) t++; // Skip empty lines / lines with only whitespace @@ -255,10 +247,15 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) { assert(isValidName(oldName)); assert(isValidName(newName)); - //Section *os = getSection(oldName); - Section *ns = getSection(newName); - if (ns) { - ns->name = newName; + Section *os = getSection(oldName); + const Section *ns = getSection(newName); + if (os) { + // HACK: For now we just print a warning, for more info see the TODO + // below. + if (ns) + warning("ConfigFile::renameSection: Section name \"%s\" already used", newName.c_str()); + else + os->name = newName; } // TODO: Check here whether there already is a section with the // new name. Not sure how to cope with that case, we could: |