1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 parses <filename>.ini</filename>-like config files
7 <!-- ##### SECTION Long_Description ##### -->
9 #GKeyFile lets you parse, edit or create files containing groups of
10 key-value pairs, which we call <firstterm>key files</firstterm> for
11 lack of a better name. Several freedesktop.org specifications use
12 key files now, e.g the
13 <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">Desktop
14 Entry Specification</ulink> and the
15 <ulink url="http://freedesktop.org/Standards/icon-theme-spec">Icon
16 Theme Specification</ulink>.
20 The syntax of key files is described in detail in the
21 <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">Desktop
22 Entry Specification</ulink>, here is a quick summary: Key files
23 consists of groups of key-value pairs, interspersed with comments.
26 <informalexample><programlisting>
27 # this is just an example
28 # there can be comments before the first group
32 Name=Key File Example\tthis value shows\nescaping
34 # localized strings are stored in multiple key-value pairs
44 Booleans=true;false;true;true
46 </programlisting></informalexample>
49 Lines beginning with a '#' and blank lines are considered comments.
53 Groups are started by a header line containing the group name enclosed
54 in '[' and ']', and ended implicitly by the start of the next group or
55 the end of the file. Each key-value pair must be contained in a group.
59 Key-value pairs generally have the form <literal>key=value</literal>,
60 with the exception of localized strings, which have the form
61 <literal>key[locale]=value</literal>. Space before and after the
62 '=' character are ignored. Newline, tab, carriage return and backslash
63 characters are escaped as \n, \t, \r, and \\, respectively. To preserve
64 initial and final spaces, these can also be escaped as \s.
68 Key files can store strings (possibly with localized variants), integers,
69 booleans and lists of these. Lists are separated by a separator character,
70 typically ';' or ','. To use the list separator character in a value in
71 a list, it has to be escaped by prefixing it with a backslash.
75 This syntax is obviously inspired by the <filename>.ini</filename>
76 files commonly met on Windows, but there are some important differences:
79 <filename>.ini</filename> files use the ';' character to begin comments,
80 key files use the '#' character.
83 Key files allow only comments before the first group.
86 Key files are always encoded in UTF-8.
89 Key and Group names are case-sensitive, for example a group called
90 <literal>[GROUP]</literal> is a different group from <literal>[group]</literal>.
95 <!-- ##### SECTION See_Also ##### -->
100 <!-- ##### SECTION Stability_Level ##### -->
103 <!-- ##### STRUCT GKeyFile ##### -->
105 The <structname>GKeyFile</structname> struct contains only private fields
106 and should not be used directly.
110 <!-- ##### MACRO G_KEY_FILE_ERROR ##### -->
112 Error domain for key file parsing. Errors in this domain will
113 be from the #GKeyFileError enumeration. See #GError for information on
119 <!-- ##### ENUM GKeyFileError ##### -->
121 Error codes returned by key file parsing.
124 @G_KEY_FILE_ERROR_UNKNOWN_ENCODING: the text being parsed was in an unknown encoding
125 @G_KEY_FILE_ERROR_PARSE: document was ill-formed
126 @G_KEY_FILE_ERROR_NOT_FOUND: the file was not found
127 @G_KEY_FILE_ERROR_KEY_NOT_FOUND: a requested key was not found
128 @G_KEY_FILE_ERROR_GROUP_NOT_FOUND: a requested group was not found
129 @G_KEY_FILE_ERROR_INVALID_VALUE: a value could not be parsed
131 <!-- ##### ENUM GKeyFileFlags ##### -->
133 Flags which influence the parsing.
136 @G_KEY_FILE_NONE: No flags, default behaviour
137 @G_KEY_FILE_KEEP_COMMENTS: Use this flag if you plan to write the (possibly modified)
138 contents of the key file back to a file; otherwise all comments will be lost when
139 the key file is written back.
140 @G_KEY_FILE_KEEP_TRANSLATIONS: Use this flag if you plan to write the (possibly modified)
141 contents of the key file back to a file; otherwise only the translations for the current
142 language will be written back.
144 <!-- ##### FUNCTION g_key_file_new ##### -->
152 <!-- ##### FUNCTION g_key_file_free ##### -->
160 <!-- ##### FUNCTION g_key_file_set_list_separator ##### -->
169 <!-- ##### FUNCTION g_key_file_load_from_file ##### -->
181 <!-- ##### FUNCTION g_key_file_load_from_data ##### -->
194 <!-- ##### FUNCTION g_key_file_load_from_data_dirs ##### -->
207 <!-- ##### FUNCTION g_key_file_to_data ##### -->
218 <!-- ##### FUNCTION g_key_file_get_start_group ##### -->
227 <!-- ##### FUNCTION g_key_file_get_groups ##### -->
237 <!-- ##### FUNCTION g_key_file_get_keys ##### -->
249 <!-- ##### FUNCTION g_key_file_has_group ##### -->
259 <!-- ##### FUNCTION g_key_file_has_key ##### -->
271 <!-- ##### FUNCTION g_key_file_get_value ##### -->
283 <!-- ##### FUNCTION g_key_file_get_string ##### -->
295 <!-- ##### FUNCTION g_key_file_get_locale_string ##### -->
308 <!-- ##### FUNCTION g_key_file_get_boolean ##### -->
320 <!-- ##### FUNCTION g_key_file_get_integer ##### -->
332 <!-- ##### FUNCTION g_key_file_get_string_list ##### -->
345 <!-- ##### FUNCTION g_key_file_get_locale_string_list ##### -->
359 <!-- ##### FUNCTION g_key_file_get_boolean_list ##### -->
372 <!-- ##### FUNCTION g_key_file_get_integer_list ##### -->
385 <!-- ##### FUNCTION g_key_file_get_comment ##### -->
397 <!-- ##### FUNCTION g_key_file_set_value ##### -->
408 <!-- ##### FUNCTION g_key_file_set_string ##### -->
419 <!-- ##### FUNCTION g_key_file_set_locale_string ##### -->
431 <!-- ##### FUNCTION g_key_file_set_boolean ##### -->
440 <!-- # Unused Parameters # -->
444 <!-- ##### FUNCTION g_key_file_set_integer ##### -->
453 <!-- # Unused Parameters # -->
457 <!-- ##### FUNCTION g_key_file_set_string_list ##### -->
469 <!-- ##### FUNCTION g_key_file_set_locale_string_list ##### -->
482 <!-- ##### FUNCTION g_key_file_set_boolean_list ##### -->
494 <!-- ##### FUNCTION g_key_file_set_integer_list ##### -->
506 <!-- ##### FUNCTION g_key_file_set_comment ##### -->
518 <!-- ##### FUNCTION g_key_file_remove_group ##### -->
528 <!-- ##### FUNCTION g_key_file_remove_key ##### -->
539 <!-- ##### FUNCTION g_key_file_remove_comment ##### -->