Author: post
Date: 2010-12-30 01:14:24 +0100 (Thu, 30 Dec 2010)
New Revision: 3732
Modified:
trunk/librawstudio/rs-utils.c
trunk/librawstudio/rs-utils.h
Log:
Allow more than one delimiter to be given for splitting a string, and don't
return empty strings.
Modified: trunk/librawstudio/rs-utils.c
===================================================================
--- trunk/librawstudio/rs-utils.c 2010-12-30 00:04:06 UTC (rev 3731)
+++ trunk/librawstudio/rs-utils.c 2010-12-30 00:14:24 UTC (rev 3732)
@@ -654,18 +654,22 @@
/**
* Split a char * with a given delimiter
* @param str The gchar * to be splitted
- * @param delimiter The gchar * to be used as delimiter
+ * @param delimiters The gchar * to be used as delimiter (can be more than 1
char)
* @return A GList consisting of the different parts of the input string, must
be freed using g_free() and g_list_free().
*/
GList *
-rs_split_string(const gchar *str, const gchar *delimiter) {
- gchar **temp = g_strsplit(str, delimiter, 0);
+rs_split_string(const gchar *str, const gchar *delimiters) {
+ gchar **temp = g_strsplit_set(str, delimiters, 0);
int i = 0;
GList *glist = NULL;
while (temp[i])
{
- glist = g_list_append(glist, (gchar *) temp[i]);
+ gchar* text = (gchar *) temp[i];
+ if (text[0] != 0)
+ glist = g_list_append(glist, text);
+ else
+ g_free(text);
i++;
}
g_free(temp);
Modified: trunk/librawstudio/rs-utils.h
===================================================================
--- trunk/librawstudio/rs-utils.h 2010-12-30 00:04:06 UTC (rev 3731)
+++ trunk/librawstudio/rs-utils.h 2010-12-30 00:14:24 UTC (rev 3732)
@@ -152,13 +152,13 @@
CanonEv(gint val);
/**
- * Split a char * with a given delimiter
+ * Split a char * with any of the given delimiters
* @param str The gchar * to be splitted
- * @param delimiter The gchar * to be used as delimiter
+ * @param delimiters The gchar * to be used as delimiter (can be more than 1
char)
* @return A GList consisting of the different parts of the input string, must
be freed using g_free() and g_list_free().
*/
GList *
-rs_split_string(const gchar *str, const gchar *delimiter);
+rs_split_string(const gchar *str, const gchar *delimiters);
gchar * rs_file_checksum(const gchar *photo);
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit