changeset 26270:75a108423c11

Skip BOM at the beginning of text in ASS parser.
author eugeni
date Sun, 30 Mar 2008 17:42:17 +0000
parents 65ad20416dd7
children fa145ef5ac13
files libass/ass.c
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass.c	Sun Mar 30 16:55:46 2008 +0000
+++ b/libass/ass.c	Sun Mar 30 17:42:17 2008 +0000
@@ -647,7 +647,7 @@
 */ 
 static int process_line(ass_track_t* track, char *str)
 {
-	if (strstr(str, "[Script Info]")) { // FIXME: strstr to skip possible BOM at the beginning of the script
+	if (!strncmp(str, "[Script Info]", 13)) {
 		track->parser_priv->state = PST_INFO;
 	} else if (!strncmp(str, "[V4 Styles]", 11)) {
 		track->parser_priv->state = PST_STYLES;
@@ -690,7 +690,11 @@
 	char* p = str;
 	while(1) {
 		char* q;
-		for (;((*p=='\r')||(*p=='\n'));++p) {}
+		while (1) {
+			if ((*p=='\r')||(*p=='\n')) ++p;
+			else if (p[0]=='\xef' && p[1]=='\xbb' && p[2]=='\xbf') p+=3; // U+FFFE (BOM)
+			else break;
+		}
 		for (q=p; ((*q!='\0')&&(*q!='\r')&&(*q!='\n')); ++q) {};
 		if (q==p)
 			break;