COMMON: added support for ini files with non english characters
This commit is contained in:
parent
1dd915ccdf
commit
c2054682f0
2 changed files with 15 additions and 2 deletions
|
@ -29,12 +29,18 @@
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
bool INIFile::isValidName(const String &name) const {
|
bool INIFile::isValidName(const String &name) const {
|
||||||
|
if (_allowNonEnglishCharacters)
|
||||||
|
return true;
|
||||||
const char *p = name.c_str();
|
const char *p = name.c_str();
|
||||||
while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.' || *p == ' '))
|
while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.' || *p == ' '))
|
||||||
p++;
|
p++;
|
||||||
return *p == 0;
|
return *p == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INIFile::INIFile() {
|
||||||
|
_allowNonEnglishCharacters = false;
|
||||||
|
}
|
||||||
|
|
||||||
void INIFile::clear() {
|
void INIFile::clear() {
|
||||||
_sections.clear();
|
_sections.clear();
|
||||||
}
|
}
|
||||||
|
@ -102,7 +108,7 @@ bool INIFile::loadFromStream(SeekableReadStream &stream) {
|
||||||
// is, verify that it only consists of alphanumerics,
|
// is, verify that it only consists of alphanumerics,
|
||||||
// periods, dashes and underscores). Mohawk Living Books games
|
// periods, dashes and underscores). Mohawk Living Books games
|
||||||
// can have periods in their section names.
|
// 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++;
|
p++;
|
||||||
|
|
||||||
if (*p == '\0')
|
if (*p == '\0')
|
||||||
|
@ -435,4 +441,8 @@ void INIFile::Section::removeKey(const String &key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INIFile::allowNonEnglishCharacters() {
|
||||||
|
_allowNonEnglishCharacters = true;
|
||||||
|
}
|
||||||
|
|
||||||
} // End of namespace Common
|
} // End of namespace Common
|
||||||
|
|
|
@ -77,7 +77,7 @@ public:
|
||||||
typedef List<Section> SectionList;
|
typedef List<Section> SectionList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
INIFile() {}
|
INIFile();
|
||||||
~INIFile() {}
|
~INIFile() {}
|
||||||
|
|
||||||
// TODO: Maybe add a copy constructor etc.?
|
// TODO: Maybe add a copy constructor etc.?
|
||||||
|
@ -115,8 +115,11 @@ public:
|
||||||
|
|
||||||
void listKeyValues(StringMap &kv);
|
void listKeyValues(StringMap &kv);
|
||||||
|
|
||||||
|
void allowNonEnglishCharacters();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SectionList _sections;
|
SectionList _sections;
|
||||||
|
bool _allowNonEnglishCharacters;
|
||||||
|
|
||||||
Section *getSection(const String §ion);
|
Section *getSection(const String §ion);
|
||||||
const Section *getSection(const String §ion) const;
|
const Section *getSection(const String §ion) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue