plibsys 0.0.5
|
INI file parser. More...
Go to the source code of this file.
Typedefs | |
typedef struct PIniFile_ | PIniFile |
INI file opaque data structure. | |
Functions | |
P_LIB_API PIniFile * | p_ini_file_new (const pchar *path) |
Creates a new PIniFile for parsing. | |
P_LIB_API void | p_ini_file_free (PIniFile *file) |
Frees memory and allocated resources of PIniFile. | |
P_LIB_API pboolean | p_ini_file_parse (PIniFile *file, PError **error) |
Parses given PIniFile. | |
P_LIB_API pboolean | p_ini_file_is_parsed (const PIniFile *file) |
Checks whether PIniFile was already parsed or not. | |
P_LIB_API PList * | p_ini_file_sections (const PIniFile *file) |
Gets all the sections from a given file. | |
P_LIB_API PList * | p_ini_file_keys (const PIniFile *file, const pchar *section) |
Gets all the keys from a given section. | |
P_LIB_API pboolean | p_ini_file_is_key_exists (const PIniFile *file, const pchar *section, const pchar *key) |
Checks whether a key exists. | |
P_LIB_API pchar * | p_ini_file_parameter_string (const PIniFile *file, const pchar *section, const pchar *key, const pchar *default_val) |
Gets specified parameter's value as a string. | |
P_LIB_API pint | p_ini_file_parameter_int (const PIniFile *file, const pchar *section, const pchar *key, pint default_val) |
Gets specified parameter's value as an integer. | |
P_LIB_API double | p_ini_file_parameter_double (const PIniFile *file, const pchar *section, const pchar *key, double default_val) |
Gets specified parameter's value as a floating point. | |
P_LIB_API pboolean | p_ini_file_parameter_boolean (const PIniFile *file, const pchar *section, const pchar *key, pboolean default_val) |
Gets specified parameter's value as a boolean. | |
P_LIB_API PList * | p_ini_file_parameter_list (const PIniFile *file, const pchar *section, const pchar *key) |
Gets specified parameter's value as a list of strings separated with the spaces or tabs. | |
INI file parser.
An INI file is usually used for storing configuration information. It consists of sections: every section starts with a line containing the name in square brackets (i.e. [section_name]). After that line all the following parameters will belong to that section until another section begins.
Each section has a list of key-value pairs. Empty sections are not permitted (they will be skipped). Every key-value pair is represented with a line in the key = value
format. If a section has several values with the same key the last one will be used. A value is parsed by the first in-order '=' symbol. All the following '=' occurrences belong to the value.
All symbols after '#' and ';' (even at the line ending) are the comments and wouldn't be read. If you want to use them in values take the value inside the "" or '' symbols. A section name line is not allowed to use the comment symbols after the section name in the square brackets itself.
Integer values can be written in the usual form.
Floating point values can be written in any commonly used notation (i.e. with the decimal point, in the exponential form using the 'e' character). The only valid decimal point symbol is the '.'. There is no locale dependency on the decimal point.
Boolean values can be written in the form of 'true/false' or 'TRUE/FALSE', or simply '0/1'.
Any value can be interpreted as a string at any moment. Actually all the values are stored internally as strings.
A list of values can be stored between the '{}' symbols separated with spaces. The list only supports string values, so you should convert them to numbers manually. The list doesn't support strings with spaces - such strings will be splitted.
To parse a file, create PIniFile with p_ini_file_new() and then parse it with the p_ini_file_parse() routine.
PIniFile handles (skips) UTF-8/16/32 BOM characters (marks).
Example of the INI file contents:
Definition in file pinifile.h.
typedef struct PIniFile_ PIniFile |
INI file opaque data structure.
Definition at line 109 of file pinifile.h.
P_LIB_API pboolean p_ini_file_is_key_exists | ( | const PIniFile * | file, |
const pchar * | section, | ||
const pchar * | key ) |
Checks whether a key exists.
file | PIniFile to check in. The file should be parsed before. |
section | Section to check the key in. |
key | Key to check. |
Gets all the keys from a given section.
file | PIniFile to get the keys from. The file should be parsed before. |
section | Section name to get the keys from. |
P_LIB_API pboolean p_ini_file_parameter_boolean | ( | const PIniFile * | file, |
const pchar * | section, | ||
const pchar * | key, | ||
pboolean | default_val ) |
Gets specified parameter's value as a boolean.
file | PIniFile to get the value from. The file should be parsed before. |
section | Section to get the value from. |
key | Key to get the value from. |
default_val | Default value to return if no specified key exists. |
P_LIB_API double p_ini_file_parameter_double | ( | const PIniFile * | file, |
const pchar * | section, | ||
const pchar * | key, | ||
double | default_val ) |
Gets specified parameter's value as a floating point.
file | PIniFile to get the value from. The file should be parsed before. |
section | Section to get the value from. |
key | Key to get the value from. |
default_val | Default value to return if no specified key exists. |
P_LIB_API pint p_ini_file_parameter_int | ( | const PIniFile * | file, |
const pchar * | section, | ||
const pchar * | key, | ||
pint | default_val ) |
Gets specified parameter's value as an integer.
file | PIniFile to get the value from. The file should be parsed before. |
section | Section to get the value from. |
key | Key to get the value from. |
default_val | Default value to return if no specified key exists. |
P_LIB_API PList * p_ini_file_parameter_list | ( | const PIniFile * | file, |
const pchar * | section, | ||
const pchar * | key ) |
Gets specified parameter's value as a list of strings separated with the spaces or tabs.
file | PIniFile to get the value from. The file should be parsed before. |
section | Section to get the value from. |
key | Key to get the value from. |
P_LIB_API pchar * p_ini_file_parameter_string | ( | const PIniFile * | file, |
const pchar * | section, | ||
const pchar * | key, | ||
const pchar * | default_val ) |
Gets specified parameter's value as a string.
file | PIniFile to get the value from. The file should be parsed before. |
section | Section to get the value from. |
key | Key to get the value from. |
default_val | Default value to return if no specified key exists. |
Gets all the sections from a given file.
file | PIniFile to get the sections from. The file should be parsed before. |