[libgxps] More flexible parsing in gxps_points_parse()



commit 82c15dc45d4cd322c36e27fb2e882cd0043ff334
Author: Jason Crain <jason aquaticape us>
Date:   Sun Jul 31 13:23:08 2011 -0500

    More flexible parsing in gxps_points_parse()
    
    Allows points to be separated by more than one space.

 libgxps/gxps-page.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/libgxps/gxps-page.c b/libgxps/gxps-page.c
index 3dc9920..5fe5dd2 100644
--- a/libgxps/gxps-page.c
+++ b/libgxps/gxps-page.c
@@ -970,32 +970,38 @@ gxps_points_parse (const gchar *points,
 		   guint       *n_points)
 {
 	gchar  **items;
-	guint    i, j;
+	guint    i, j = 0;
 	gboolean retval = TRUE;
 
+	*n_points = 0;
 	items = g_strsplit (points, " ", -1);
-	if (!items) {
-		*n_points = 0;
+	if (!items)
 		return FALSE;
+
+	for (i = 0; items[i] != NULL; i++) {
+		if (*items[i] != '\0') /* don't count empty string */
+			(*n_points)++;
 	}
 
-	*n_points = g_strv_length (items);
 	if (*n_points == 0)
 		return FALSE;
 
 	*coords = g_malloc (*n_points * 2 * sizeof (gdouble));
 
-	for (i = 0, j = 0; i < *n_points; i++, j += 2) {
+	for (i = 0; items[i] != NULL; i++) {
 		gdouble x, y;
 
+		if (*items[i] == '\0')
+			continue;
+
 		if (!gxps_point_parse (items[i], &x, &y)) {
 			g_free (*coords);
 			retval = FALSE;
 			break;
 		}
 
-		coords[0][j] = x;
-		coords[0][j + 1] = y;
+		coords[0][j++] = x;
+		coords[0][j++] = y;
 	}
 
 	g_strfreev (items);



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