mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
Bug 560569 – gkeyfile doesn't use the set list_separator in some cases
svn path=/trunk/; revision=7673
This commit is contained in:
parent
ff4a7678e6
commit
47d6d6a451
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
2008-11-23 Christian Persch <chpe@gnome.org>
|
||||
|
||||
Bug 560569 – gkeyfile doesn't use the set list_separator in some cases
|
||||
|
||||
* glib/gkeyfile.c: (g_key_file_get_locale_string_list),
|
||||
(g_key_file_set_locale_string_list), (g_key_file_set_integer_list),
|
||||
(g_key_file_set_double_list): Use the key file's list separator character,
|
||||
not the default one.
|
||||
|
||||
* glib/tests/keyfile.c: (test_lists), (test_reload_idempotency): Test
|
||||
this.
|
||||
|
||||
2008-11-21 Christophe Fergeau <teuf@gnome.org>
|
||||
|
||||
Bug 561212 – GFileReadMoreCallback API doc refers to non-existant function
|
||||
|
@ -1752,6 +1752,8 @@ g_key_file_get_locale_string_list (GKeyFile *key_file,
|
||||
{
|
||||
GError *key_file_error;
|
||||
gchar **values, *value;
|
||||
char list_separator[2];
|
||||
gsize len;
|
||||
|
||||
g_return_val_if_fail (key_file != NULL, NULL);
|
||||
g_return_val_if_fail (group_name != NULL, NULL);
|
||||
@ -1773,10 +1775,13 @@ g_key_file_get_locale_string_list (GKeyFile *key_file,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (value[strlen (value) - 1] == ';')
|
||||
value[strlen (value) - 1] = '\0';
|
||||
len = strlen (value);
|
||||
if (value[len - 1] == key_file->list_separator)
|
||||
value[len - 1] = '\0';
|
||||
|
||||
values = g_strsplit (value, ";", 0);
|
||||
list_separator[0] = key_file->list_separator;
|
||||
list_separator[1] = '\0';
|
||||
values = g_strsplit (value, list_separator, 0);
|
||||
|
||||
g_free (value);
|
||||
|
||||
@ -1824,9 +1829,8 @@ g_key_file_set_locale_string_list (GKeyFile *key_file,
|
||||
gchar *value;
|
||||
|
||||
value = g_key_file_parse_string_as_value (key_file, list[i], TRUE);
|
||||
|
||||
g_string_append (value_list, value);
|
||||
g_string_append_c (value_list, ';');
|
||||
g_string_append_c (value_list, key_file->list_separator);
|
||||
|
||||
g_free (value);
|
||||
}
|
||||
@ -2253,7 +2257,7 @@ g_key_file_set_integer_list (GKeyFile *key_file,
|
||||
value = g_key_file_parse_integer_as_value (key_file, list[i]);
|
||||
|
||||
g_string_append (values, value);
|
||||
g_string_append_c (values, ';');
|
||||
g_string_append_c (values, key_file->list_separator);
|
||||
|
||||
g_free (value);
|
||||
}
|
||||
@ -2464,7 +2468,7 @@ g_key_file_set_double_list (GKeyFile *key_file,
|
||||
g_ascii_dtostr( result, sizeof (result), list[i] );
|
||||
|
||||
g_string_append (values, result);
|
||||
g_string_append_c (values, ';');
|
||||
g_string_append_c (values, key_file->list_separator);
|
||||
}
|
||||
|
||||
g_key_file_set_value (key_file, group_name, key, values->str);
|
||||
|
@ -97,6 +97,39 @@ check_string_list_value (GKeyFile *keyfile,
|
||||
g_strfreev (value);
|
||||
}
|
||||
|
||||
static void
|
||||
check_locale_string_list_value (GKeyFile *keyfile,
|
||||
const gchar *group,
|
||||
const gchar *key,
|
||||
const gchar *locale,
|
||||
...)
|
||||
{
|
||||
gint i;
|
||||
gchar *v, **value;
|
||||
va_list args;
|
||||
gsize len;
|
||||
GError *error = NULL;
|
||||
|
||||
value = g_key_file_get_locale_string_list (keyfile, group, key, locale, &len, &error);
|
||||
check_no_error (&error);
|
||||
g_assert (value != NULL);
|
||||
|
||||
va_start (args, locale);
|
||||
i = 0;
|
||||
v = va_arg (args, gchar*);
|
||||
while (v)
|
||||
{
|
||||
g_assert (value[i] != NULL);
|
||||
g_assert_cmpstr (v, ==, value[i]);
|
||||
i++;
|
||||
v = va_arg (args, gchar*);
|
||||
}
|
||||
|
||||
va_end (args);
|
||||
|
||||
g_strfreev (value);
|
||||
}
|
||||
|
||||
static void
|
||||
check_integer_list_value (GKeyFile *keyfile,
|
||||
const gchar *group,
|
||||
@ -695,7 +728,43 @@ test_lists (void)
|
||||
g_key_file_free (keyfile);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
test_lists_set_get (void)
|
||||
{
|
||||
GKeyFile *keyfile;
|
||||
static const char * const strings[] = { "v1", "v2" };
|
||||
static const char * const locale_strings[] = { "v1-l", "v2-l" };
|
||||
static int integers[] = { 1, -1, 2 };
|
||||
static gdouble doubles[] = { 3.14, 2.71 };
|
||||
|
||||
keyfile = g_key_file_new ();
|
||||
g_key_file_set_string_list (keyfile, "group0", "key1", strings, G_N_ELEMENTS (strings));
|
||||
g_key_file_set_locale_string_list (keyfile, "group0", "key1", "de", locale_strings, G_N_ELEMENTS (locale_strings));
|
||||
g_key_file_set_integer_list (keyfile, "group0", "key2", integers, G_N_ELEMENTS (integers));
|
||||
g_key_file_set_double_list (keyfile, "group0", "key3", doubles, G_N_ELEMENTS (doubles));
|
||||
|
||||
check_string_list_value (keyfile, "group0", "key1", strings[0], strings[1], NULL);
|
||||
check_locale_string_list_value (keyfile, "group0", "key1", "de", locale_strings[0], locale_strings[1], NULL);
|
||||
check_integer_list_value (keyfile, "group0", "key2", integers[0], integers[1], -100);
|
||||
check_double_list_value (keyfile, "group0", "key3", doubles[0], doubles[1], -100.0);
|
||||
g_key_file_free (keyfile);
|
||||
|
||||
/* and again with a different list separator */
|
||||
keyfile = g_key_file_new ();
|
||||
g_key_file_set_list_separator (keyfile, ',');
|
||||
g_key_file_set_string_list (keyfile, "group0", "key1", strings, G_N_ELEMENTS (strings));
|
||||
g_key_file_set_locale_string_list (keyfile, "group0", "key1", "de", locale_strings, G_N_ELEMENTS (locale_strings));
|
||||
g_key_file_set_integer_list (keyfile, "group0", "key2", integers, G_N_ELEMENTS (integers));
|
||||
g_key_file_set_double_list (keyfile, "group0", "key3", doubles, G_N_ELEMENTS (doubles));
|
||||
|
||||
check_string_list_value (keyfile, "group0", "key1", strings[0], strings[1], NULL);
|
||||
check_locale_string_list_value (keyfile, "group0", "key1", "de", locale_strings[0], locale_strings[1], NULL);
|
||||
check_integer_list_value (keyfile, "group0", "key2", integers[0], integers[1], -100);
|
||||
check_double_list_value (keyfile, "group0", "key3", doubles[0], doubles[1], -100.0);
|
||||
g_key_file_free (keyfile);
|
||||
}
|
||||
|
||||
static void
|
||||
test_group_remove (void)
|
||||
{
|
||||
GKeyFile *keyfile;
|
||||
@ -1178,6 +1247,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/keyfile/number", test_number);
|
||||
g_test_add_func ("/keyfile/locale-string", test_locale_string);
|
||||
g_test_add_func ("/keyfile/lists", test_lists);
|
||||
g_test_add_func ("/keyfile/lists-set-get", test_lists_set_get);
|
||||
g_test_add_func ("/keyfile/group-remove", test_group_remove);
|
||||
g_test_add_func ("/keyfile/key-remove", test_key_remove);
|
||||
g_test_add_func ("/keyfile/groups", test_groups);
|
||||
|
Loading…
Reference in New Issue
Block a user