nsub: add utf-8 BOM support
authorNiki Roo <niki@nikiroo.be>
Thu, 26 May 2022 11:50:47 +0000 (13:50 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 26 May 2022 11:50:47 +0000 (13:50 +0200)
src/nsub/nsub.c

index 3df4da0c34c9f9f51e9fd1113c59c4dfd496d5ae..0ea748f52978574ae96629dc1f5fe8a53c809da8 100644 (file)
@@ -128,6 +128,13 @@ song_t *nsub_read(FILE *in, NSUB_FORMAT fmt) {
        line = new_cstring();
        size_t i = 0;
        while (cstring_readline(line, in)) {
+               // UTF-8 BOM detection if any
+               if (!i && cstring_starts_with(line->string, "\xEF\xBB\xBF", 0)) {
+                       cstring_t *tmp = cstring_substring(line->string, 3, 0);
+                       free_cstring(line);
+                       line = tmp;
+               }
+
                i++;
 
                if (!read_a_line(song, line->string)) {