From a002558d5e096d91c3c4294e30405ad3bce3e5d6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 Jun 2015 18:55:52 +0100 Subject: Skip Unicode BOM at the start of subrip files. --- src/subrip_reader.cc | 11 +++++++++++ test/subrip_reader_test.cc | 1 + 2 files changed, 12 insertions(+) diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 5e9e010..3f1c23d 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -54,6 +54,17 @@ SubripReader::SubripReader (FILE* f) line = string (buffer); trim_right_if (line, boost::is_any_of ("\n\r")); + if ( + line.length() >= 3 && + static_cast (line[0]) == 0xef && + static_cast (line[1]) == 0xbb && + static_cast (line[2]) == 0xbf + ) { + + /* Skip Unicode byte order mark */ + line = line.substr (3); + } + switch (state) { case COUNTER: { diff --git a/test/subrip_reader_test.cc b/test/subrip_reader_test.cc index 1779517..91437f2 100644 --- a/test/subrip_reader_test.cc +++ b/test/subrip_reader_test.cc @@ -303,5 +303,6 @@ test (boost::filesystem::path p) BOOST_AUTO_TEST_CASE (subrip_read_test) { test ("sintel_en.srt"); + test ("sintel_fr.srt"); test ("Fight.Club.1999.720p.BRRip.x264-x0r.srt"); } -- cgit v1.2.3