[nautilus-actions] na_boxed_string_list_from_string: accept both comma and semi-comma separated list of strings



commit bc7c4b86d6044c619dca93ab5983898ccc345beb
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jun 10 22:19:57 2011 +0200

    na_boxed_string_list_from_string: accept both comma and semi-comma separated list of strings

 ChangeLog                 |    7 +++++++
 src/core/na-boxed.c       |   33 +++++++++++++++++++++++++++------
 src/io-xml/naxml-reader.c |   11 ++++++-----
 3 files changed, 40 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9d497b2..e7b2429 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-06-10 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-boxed.c (string_to_array):
+	Accepts now both semi-comma-separated list of strings and
+	comma-separated between square brackets (Ã la GConf) from string lists.
+
+	* src/io-xml/naxml-reader.c (slist_to_string):
+	Formats string list as a semi-comma-separated list of strings for NABoxed.
+
 	* src/utils/na-gconf2key.sh.in: No more obsolete the GConf reading,
 	as it may sometimes be needed to re-migrate a newly inserted item.
 
diff --git a/src/core/na-boxed.c b/src/core/na-boxed.c
index 04f6771..d21a7b2 100644
--- a/src/core/na-boxed.c
+++ b/src/core/na-boxed.c
@@ -442,8 +442,11 @@ get_boxed_def( guint type )
 }
 
 /*
- * converts a string to an array of string
- * the last separator, if any, is not counted
+ * converts a string to an array of strings
+ * accepts both:
+ * - a semi-comma-separated list of strings (the last separator, if any, is not counted)
+ * - a comma-separated list of strings between square brackets (Ã la GConf)
+ *
  */
 static gchar **
 string_to_array( const gchar *string )
@@ -454,12 +457,25 @@ string_to_array( const gchar *string )
 	array = NULL;
 
 	if( string && strlen( string )){
-		sdup = g_strdup( string );
-		if( g_str_has_suffix( string, LIST_SEPARATOR )){
-			sdup[strlen(sdup)-1] = '\0';
+		sdup = g_strstrip( g_strdup( string ));
+
+		/* GConf-style string list [value,value]
+		 */
+		if( sdup[0] == '[' && sdup[strlen(sdup)-1] == ']' ){
+			sdup[0] = ' ';
+			sdup[strlen(sdup)-1] = ' ';
 			sdup = g_strstrip( sdup );
+			array = g_strsplit( sdup, ",", -1 );
+
+		/* semi-comma-separated list of strings
+		 */
+		} else {
+			if( g_str_has_suffix( string, LIST_SEPARATOR )){
+				sdup[strlen(sdup)-1] = ' ';
+				sdup = g_strstrip( sdup );
+			}
+			array = g_strsplit( sdup, LIST_SEPARATOR, -1 );
 		}
-		array = g_strsplit( sdup, LIST_SEPARATOR, -1 );
 		g_free( sdup );
 	}
 
@@ -1142,6 +1158,11 @@ string_list_free( NABoxed *boxed )
 	boxed->private->is_set = FALSE;
 }
 
+/*
+ * accept string list both:
+ * - as a semi-comma-separated list of strings
+ * - as a comma-separated list of string, between two square brackets (Ã la GConf)
+ */
 static void
 string_list_from_string( NABoxed *boxed, const gchar *string )
 {
diff --git a/src/io-xml/naxml-reader.c b/src/io-xml/naxml-reader.c
index 0ee1fe6..2dc5aa8 100644
--- a/src/io-xml/naxml-reader.c
+++ b/src/io-xml/naxml-reader.c
@@ -1184,7 +1184,7 @@ dump_check_for_type( NAXMLReader *reader, xmlNode *key_node )
 }
 
 /*
- * string list is converted to GSList, then to a GConf string
+ * string list is converted to GSList, then to a NABoxed string list 'value;value'
  */
 static gchar *
 dump_read_value( NAXMLReader *reader, xmlNode *node, const NADataDef *def )
@@ -1241,24 +1241,25 @@ dump_read_value( NAXMLReader *reader, xmlNode *node, const NADataDef *def )
 	return( string );
 }
 
+/*
+ * NABoxed accepts a string list as a semi-comma-separated list of strings
+ */
 static gchar *
 slist_to_string( GSList *slist )
 {
 	GSList *is;
-	GString *str = g_string_new( "[" );
+	GString *str = g_string_new( "" );
 	gboolean first;
 
 	first = TRUE;
 	for( is = slist ; is ; is = is->next ){
 		if( !first ){
-			str = g_string_append( str, "," );
+			str = g_string_append( str, ";" );
 		}
 		str = g_string_append( str, ( const gchar * ) is->data );
 		first = FALSE;
 	}
 
-	str = g_string_append( str, "]" );
-
 	return( g_string_free( str, FALSE ));
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]