totem-pl-parser r229 - in branches/gnome-2-24: . plparse



Author: hadess
Date: Sat Sep 27 03:28:56 2008
New Revision: 229
URL: http://svn.gnome.org/viewvc/totem-pl-parser?rev=229&view=rev

Log:
2008-09-27  Bastien Nocera  <hadess hadess net>

	* plparse/totem-pl-parser-lines.c (totem_pl_parser_add_m3u):
	Fix parsing of DOS M3U files where the last line finishes with
	a carriage return but no line feed (Closes: #553130)



Modified:
   branches/gnome-2-24/ChangeLog
   branches/gnome-2-24/plparse/totem-pl-parser-lines.c

Modified: branches/gnome-2-24/plparse/totem-pl-parser-lines.c
==============================================================================
--- branches/gnome-2-24/plparse/totem-pl-parser-lines.c	(original)
+++ branches/gnome-2-24/plparse/totem-pl-parser-lines.c	Sat Sep 27 03:28:56 2008
@@ -347,7 +347,8 @@
 	TotemPlParserResult retval = TOTEM_PL_PARSER_RESULT_UNHANDLED;
 	char *contents, **lines;
 	gsize size;
-	int i;
+	guint i, num_lines;
+	gboolean dos;
 	const char *split_char, *extinfo;
 
 	if (g_file_load_contents (file, NULL, &contents, &size, NULL, NULL) == FALSE)
@@ -366,13 +367,19 @@
 	extinfo = NULL;
 
 	/* figure out whether we're a unix m3u or dos m3u */
-	if (strstr(contents,"\x0d") == NULL)
+	if (strstr(contents,"\x0d") == NULL) {
 		split_char = "\n";
-	else
+		dos = FALSE;
+	} else {
 		split_char = "\x0d\n";
+		dos = TRUE;
+	}
 
 	lines = g_strsplit (contents, split_char, 0);
 	g_free (contents);
+	num_lines = g_strv_length (lines);
+	/* We don't count the terminating NULL */
+	num_lines--;
 
 	for (i = 0; lines[i] != NULL; i++) {
 		if (lines[i][0] == '\0')
@@ -387,6 +394,11 @@
 			continue;
 		}
 
+		/* If we're on the last line, and we're a DOS M3U,
+		 * remove the terminating \n if it's there */
+		if (dos != FALSE && i == num_lines)
+			g_strchomp (lines[i]);
+
 		/* Either it's a URI, or it has a proper path ... */
 		if (strstr(lines[i], "://") != NULL
 				|| lines[i][0] == G_DIR_SEPARATOR) {



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