glib r7676 - in branches/glib-2-18: . glib glib/tests
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: glib r7676 - in branches/glib-2-18: . glib glib/tests
- Date: Sun, 23 Nov 2008 21:17:26 +0000 (UTC)
Author: chpe
Date: Sun Nov 23 21:17:26 2008
New Revision: 7676
URL: http://svn.gnome.org/viewvc/glib?rev=7676&view=rev
Log:
Bug 560569 â gkeyfile doesn't use the set list_separator in some cases
Modified:
branches/glib-2-18/ChangeLog
branches/glib-2-18/glib/gkeyfile.c
branches/glib-2-18/glib/tests/keyfile.c
Modified: branches/glib-2-18/glib/gkeyfile.c
==============================================================================
--- branches/glib-2-18/glib/gkeyfile.c (original)
+++ branches/glib-2-18/glib/gkeyfile.c Sun Nov 23 21:17:26 2008
@@ -1752,6 +1752,8 @@
{
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 @@
return NULL;
}
- if (value[strlen (value) - 1] == ';')
- value[strlen (value) - 1] = '\0';
-
- values = g_strsplit (value, ";", 0);
+ len = strlen (value);
+ if (value[len - 1] == key_file->list_separator)
+ value[len - 1] = '\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 @@
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 @@
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_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);
Modified: branches/glib-2-18/glib/tests/keyfile.c
==============================================================================
--- branches/glib-2-18/glib/tests/keyfile.c (original)
+++ branches/glib-2-18/glib/tests/keyfile.c Sun Nov 23 21:17:26 2008
@@ -100,6 +100,39 @@
}
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,
const gchar *key,
@@ -697,7 +730,43 @@
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;
@@ -1180,6 +1249,7 @@
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]