COMMON: Add a way to specify default section name for simple sectionless .ini files

This commit is contained in:
Vladimir Menshakov 2017-11-28 22:04:46 +00:00
parent 148cd5f28d
commit fb05242d36
2 changed files with 7 additions and 0 deletions

View File

@ -72,6 +72,7 @@ bool INIFile::loadFromStream(SeekableReadStream &stream) {
KeyValue kv;
String comment;
int lineno = 0;
section.name = _defaultSectionName;
// TODO: Detect if a section occurs multiple times (or likewise, if
// a key occurs multiple times inside one section).
@ -297,6 +298,9 @@ void INIFile::renameSection(const String &oldName, const String &newName) {
// - merge the two sections "oldName" and "newName"
}
void INIFile::setDefaultSectionName(const String &name) {
_defaultSectionName = name;
}
bool INIFile::hasKey(const String &key, const String &section) const {
if (!isValidName(key)) {

View File

@ -105,6 +105,8 @@ public:
void removeSection(const String &section);
void renameSection(const String &oldName, const String &newName);
void setDefaultSectionName(const String &name); ///< sets initial section name for section-less ini files
bool hasKey(const String &key, const String &section) const;
bool getKey(const String &key, const String &section, String &value) const;
void setKey(const String &key, const String &section, const String &value);
@ -118,6 +120,7 @@ public:
void allowNonEnglishCharacters();
private:
String _defaultSectionName;
SectionList _sections;
bool _allowNonEnglishCharacters;