I have a config.ini where section names can contain "]", which leads to parse
errors. While proper support for quoting would be best (issue #32) simply
matching the last "]" rather than the first helps in this case.
The alignment length calculation did not take into account that
keys may be added to if they contained "\"", "=", ":", or "`".
This gave an under calculation and resulted in index out of
bounds when this happened to be the longest key.
A common practice in applications development is to allow the user
to customise/extend program's settings by overriding global defaults
set in system-wide config files (typically installed under /etc)
with site-specific copies (e.g. /usr/local/etc) and user-specific
files generally stored in the user's home directory. It must be
noticed that this cascade approach allows the user to specify only
those options that he wishes to override, whilst the other values
will keep their value already set in the other configuration
files. In general, when a program couldn't find any configuration
file rather than crashing it falls back to hardcoded default values.
These changes introduce a new function LooseLoad that allows the
caller to pass a slice of filenames without worrying about their
existence or not. LooseLoad will attempt to load them in order.
If a file doesn't just, it will just be ignored and the function
won't return any error. In case no files existed, an empty
configuration will be returned to the caller.
This functionality is inspired by the Python's standard library
configparser.RawConfigParser.read() function:
https://docs.python.org/2/library/configparser.html#ConfigParser.RawConfigParser.read
`y`/`n` are also used as boolean values sometimes, extending
the library to infer these values for parseBool as well.
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This adds support for comments on the end of section headers, e.g.
[a_section] ; A comment
It also fixes a couple of places where only `#` comments were supports - not `;` comments.
Test cases are included (they pass).