#include <ini-file.h>
Classes | |
struct | KeyValue |
struct | Section |
Public Types | |
typedef List< KeyValue > | SectionKeyList |
typedef List< Section > | SectionList |
Public Member Functions | |
bool | isValidName (const String &name) const |
void | clear () |
bool | loadFromFile (const Path &filename) |
bool | loadFromFileOrDataFork (const Path &filename) |
bool | loadFromSaveFile (const String &filename) |
bool | loadFromStream (SeekableReadStream &stream) |
bool | saveToFile (const Path &filename) |
bool | saveToSaveFile (const String &filename) |
bool | saveToStream (WriteStream &stream) |
bool | hasSection (const String §ion) const |
void | addSection (const String §ion) |
void | removeSection (const String §ion) |
void | renameSection (const String &oldName, const String &newName) |
void | setDefaultSectionName (const String &name) |
bool | hasKey (const String &key, const String §ion) const |
bool | getKey (const String &key, const String §ion, String &value) const |
void | setKey (const String &key, const String §ion, const String &value) |
void | removeKey (const String &key, const String §ion) |
const SectionList | getSections () const |
const SectionKeyList | getKeys (const String §ion) const |
void | listKeyValues (StringMap &kv) |
void | allowNonEnglishCharacters () |
void | suppressValuelessLineWarning () |
void | requireKeyValueDelimiter () |
This class allows for reading and writing INI-style config files.
Lines starting with a '#' are ignored (i.e. treated as comments). Some effort is made to preserve comments, though.
This class makes no attempts to provide fast access to key/value pairs. In particular, it stores all sections and key/value pairs in lists, not in dictionaries/maps. This makes it very easy to read/write the data from/to files, but of course is not appropriate for fast access. The main reason is that this class is indeed geared toward doing precisely that.
typedef List<KeyValue> Common::INIFile::SectionKeyList |
A list of all key/value pairs in this section.
typedef List<Section> Common::INIFile::SectionList |
A list of all sections in this INI file.
bool Common::INIFile::isValidName | ( | const String & | name | ) | const |
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, whitespace and "#", "=", "[", "]" are not valid.
void Common::INIFile::clear | ( | ) |
Reset everything stored in this INI file.
bool Common::INIFile::loadFromFile | ( | const Path & | filename | ) |
Load configuration from a file.
bool Common::INIFile::loadFromFileOrDataFork | ( | const Path & | filename | ) |
Load configuration from a file in MacBinary format.
bool Common::INIFile::loadFromSaveFile | ( | const String & | filename | ) |
Load configuration from a save file.
bool Common::INIFile::loadFromStream | ( | SeekableReadStream & | stream | ) |
Load configuration from a SeekableReadStream.
bool Common::INIFile::saveToFile | ( | const Path & | filename | ) |
Save the current configuration to a file.
bool Common::INIFile::saveToSaveFile | ( | const String & | filename | ) |
Save the current configuration to a save file.
bool Common::INIFile::saveToStream | ( | WriteStream & | stream | ) |
Save the current configuration to a WriteStream.
bool Common::INIFile::hasSection | ( | const String & | section | ) | const |
Check whether the INI file has a section with the specified name.
void Common::INIFile::addSection | ( | const String & | section | ) |
Add a section with the specified name to the INI file.
void Common::INIFile::removeSection | ( | const String & | section | ) |
Remove the section
from the INI file.
Rename the INI file from oldName
to newName
.
void Common::INIFile::setDefaultSectionName | ( | const String & | name | ) |
Set initial section name for section-less INI files.
Check whether the section
has a key
.
Get the value
of a key
in a section
.
Assign a value
to a key
in a section
.
Remove a key
from this section
.
|
inline |
Get a list of sections in this INI file.
const SectionKeyList Common::INIFile::getKeys | ( | const String & | section | ) | const |
Get a list of keys in a section
.
void Common::INIFile::listKeyValues | ( | StringMap & | kv | ) |
Get a list of all key/value pairs in this INI file.
void Common::INIFile::allowNonEnglishCharacters | ( | ) |
Allow non-English characters in this INI file.
void Common::INIFile::suppressValuelessLineWarning | ( | ) |
Disable warnings for lines that contain only keys.
void Common::INIFile::requireKeyValueDelimiter | ( | ) |
Requires that every key/value line have a delimiter character. Otherwise, lines that don't contain a delimiter are interpreted as if the entire line is a key with an empty value. This can cause unexpected junk lines to reach engines. (bug #13920)
It may be better if instead this were the default behavior for clients to disable if needed, but first we would need to identify everything that depends on the current behavior.