diff --git a/common/ini-file.cpp b/common/ini-file.cpp index 1bf0a0eec6cc..987a200bd4a9 100644 --- a/common/ini-file.cpp +++ b/common/ini-file.cpp @@ -28,7 +28,9 @@ namespace Common { -bool INIFile::isValidName(const String &name) { +bool INIFile::isValidName(const String &name, bool allowNonEnglishCharacters) { + if (allowNonEnglishCharacters) + return true; const char *p = name.c_str(); while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.' || *p == ' ')) p++; @@ -36,6 +38,7 @@ bool INIFile::isValidName(const String &name) { } INIFile::INIFile() { + _allowNonEnglishCharacters = false; } INIFile::~INIFile() { @@ -108,7 +111,7 @@ bool INIFile::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 == '.' || *p == ' ')) + while (*p && ((_allowNonEnglishCharacters && *p != ']') || isAlnum(*p) || *p == '-' || *p == '_' || *p == '.' || *p == ' ')) p++; if (*p == '\0') @@ -125,7 +128,7 @@ bool INIFile::loadFromStream(SeekableReadStream &stream) { section.comment = comment; comment.clear(); - assert(isValidName(section.name)); + assert(isValidName(section.name, _allowNonEnglishCharacters)); } else { // This line should be a line with a 'key=value' pair, or an empty one. @@ -160,7 +163,7 @@ bool INIFile::loadFromStream(SeekableReadStream &stream) { kv.comment = comment; comment.clear(); - assert(isValidName(kv.key)); + assert(isValidName(kv.key, _allowNonEnglishCharacters)); section.keys.push_back(kv); } @@ -237,7 +240,7 @@ void INIFile::addSection(const String §ion) { } void INIFile::removeSection(const String §ion) { - assert(isValidName(section)); + assert(isValidName(section, _allowNonEnglishCharacters)); for (List
::iterator i = _sections.begin(); i != _sections.end(); ++i) { if (section.equalsIgnoreCase(i->name)) { _sections.erase(i); @@ -247,14 +250,14 @@ void INIFile::removeSection(const String §ion) { } bool INIFile::hasSection(const String §ion) const { - assert(isValidName(section)); + assert(isValidName(section, _allowNonEnglishCharacters)); const Section *s = getSection(section); return s != nullptr; } void INIFile::renameSection(const String &oldName, const String &newName) { - assert(isValidName(oldName)); - assert(isValidName(newName)); + assert(isValidName(oldName, _allowNonEnglishCharacters)); + assert(isValidName(newName, _allowNonEnglishCharacters)); Section *os = getSection(oldName); const Section *ns = getSection(newName); @@ -275,8 +278,8 @@ void INIFile::renameSection(const String &oldName, const String &newName) { bool INIFile::hasKey(const String &key, const String §ion) const { - assert(isValidName(key)); - assert(isValidName(section)); + assert(isValidName(key, _allowNonEnglishCharacters)); + assert(isValidName(section, _allowNonEnglishCharacters)); const Section *s = getSection(section); if (!s) @@ -285,8 +288,8 @@ bool INIFile::hasKey(const String &key, const String §ion) const { } void INIFile::removeKey(const String &key, const String §ion) { - assert(isValidName(key)); - assert(isValidName(section)); + assert(isValidName(key, _allowNonEnglishCharacters)); + assert(isValidName(section, _allowNonEnglishCharacters)); Section *s = getSection(section); if (s) @@ -294,8 +297,8 @@ void INIFile::removeKey(const String &key, const String §ion) { } bool INIFile::getKey(const String &key, const String §ion, String &value) const { - assert(isValidName(key)); - assert(isValidName(section)); + assert(isValidName(key, _allowNonEnglishCharacters)); + assert(isValidName(section, _allowNonEnglishCharacters)); const Section *s = getSection(section); if (!s) @@ -308,8 +311,8 @@ bool INIFile::getKey(const String &key, const String §ion, String &value) co } void INIFile::setKey(const String &key, const String §ion, const String &value) { - assert(isValidName(key)); - assert(isValidName(section)); + assert(isValidName(key, _allowNonEnglishCharacters)); + assert(isValidName(section, _allowNonEnglishCharacters)); // TODO: Verify that value is valid, too. In particular, it shouldn't // contain CR or LF... @@ -389,4 +392,8 @@ void INIFile::Section::removeKey(const String &key) { } } +void INIFile::allowNonEnglishCharacters() { + _allowNonEnglishCharacters = true; +} + } // End of namespace Common diff --git a/common/ini-file.h b/common/ini-file.h index f27a8b94256c..23ecd863d44d 100644 --- a/common/ini-file.h +++ b/common/ini-file.h @@ -88,7 +88,7 @@ class INIFile { * underscores. In particular, white space and "#", "=", "[", "]" * are not valid! */ - static bool isValidName(const String &name); + static bool isValidName(const String &name, bool allowNonEnglishCharacters); /** Reset everything stored in this ini file. */ void clear(); @@ -115,8 +115,11 @@ class INIFile { void listKeyValues(StringMap &kv); + void allowNonEnglishCharacters(); + private: SectionList _sections; + bool _allowNonEnglishCharacters; Section *getSection(const String §ion); const Section *getSection(const String §ion) const;