The configuration format consists of four elements:
- Groups, they allow you to group similar settings into one group and it also
allows you to have multiple settings with the same name but in different
groups. This means that you don't have to prefix your settings with the group
name.
- Settings, the name of the setting which identifies the setting. A setting
contains a value.
- Values, a value can be of the following types: boolean, integers, floats,
arrays and strings.
- Comments, comments belongs to either a group or a setting and can be added to
describe what the group contains or what a setting controls.
Group and setting identifiers can only contain the characters a to z, A to Z, 0
to 9, underscore (_), dash (-) and dot (.). The case of settings are preserved
but accessing them can be done with any case, this means you cannot have two
settings with the same identifier only differing in case.
The following are legal names:
ASimpleName
asimplename
a_simple_name
a.simple.name
a-simple_and.longName
and these are illegal:
A simple name
-=A simple name=-
In addition the group names may contain forward slashes (/), for instance:
a/simple/groupname
This is the format that is written by the ezcConfigurationIniWriter class and
read by the ezcConfigurationIniReader class. The parser itself is located in
the ezcConfigurationIniParser class.
The parser will remove leading and trailing whitespace from group names,
settings and setting values. If you wish to keep whitespace in a string it will
have to be quoted.
Comments are written using a # (hash) and must be placed at the start of the
line. The whitespace block before the comment text on all the lines will be
trimmed away while whitespace after this block is kept. Trailing whitespace is
also trimmed. For instance the follow comments:
# A simple comment
# A simple comment
# A simple comment
will become:
#A simple comment
# A simple comment
# A simple comment
Multiple comment lines will be read as one comment with multiple lines, if
there are empty lines in between comments they will be read as empty lines in
the comment itself:
# A single line comment
Setting = value
# Multiple lines
# for this
# comment
Setting = value
# Multiple lines
# with empty lines
# for this comment
Setting = value
# Multiple lines
#
# with empty lines
# for this comment
# Actually same as above
Setting = value
Comments are always placed in front of the group or setting. A line
that only contains whitespace will be ignored.
The files are always encoded in UTF-8 format, this means it can contain Unicode
characters if needed or plain ASCII without specific encoding.
Groups are defined by placing an identifier inside square brackets alone on the
string. Any setting that is read after this will be placed as part of this
group. Settings without groups are not allowed and will cause an error to be
issued. The group name will have its leading and trailing whitespace trimmed
away:
[Group1]
[Another group]
[ Yet another group ]
Settings are defined by placing an identifier with an equal sign (=) after it,
the value follows after the equal sign. The setting and the value must be on
one line, it cannot span multiple lines:
Setting1 = Some example string
Setting2 = 42
The values of settings are generally seen as strings with the exception of:
Booleans which can be written as true or false, if you need these
strings as text they must be quoted:
SystemEnabled = true
LogErrors = false
Numbers are written using English locale and can be in the following format:
decimal:
[1-9][0-9]* | [0]
MaxSize = 400
MinSize = 0
hexadecimal:
0[xX][0-9a-fA-F]+
BackgroundColor = 0xaabbcc
TextColor = 0x0102FE
octal:
0[0-7]+
Permission = 0666
float:
LNUM [0-9]+
DNUM ([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*)
EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? {LNUM})
Price = 10.4
Seed = 10e5
- An explicit string which is enclosed in double quotes ("), all whitespace is
kept inside the quotes and characters are read literally with the exception
of escaped characters. The escaped characters are:
\" which will be replaced with the quote character ("):
"This contains \"quote\" characters"
\\ which will be replaced with the backslash character ():
"This contains a backslash \\"
In addition it is possible to define arrays in a second way by using square
brackets ([]) after the setting name and before the equal (=) character. This
will make the setting an array and the value is parsed as explained above.
In addition the square brackets may be enclosed around a string which turns the
array into a hash (or associative array) with the text being used as the key.
List[] = First string
List[] = Second string
List[] = 5
Hash[abc] = 4
Hash["def"] = 5