summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-06-02 17:08:11 +0100
committerCarl Hetherington <cth@carlh.net>2016-06-02 17:08:11 +0100
commitc24798d1ab4bb75c8ee0c8b8663b11e599df1c25 (patch)
treee7bf4102100af9685aa28f79ae5581e38296c18c /src
parent7910e19cf145cbdc99fbf1015add6f8eb792e160 (diff)
Remove unicode BOM from SSA files.
Diffstat (limited to 'src')
-rw-r--r--src/ssa_reader.cc1
-rw-r--r--src/subrip_reader.cc12
-rw-r--r--src/util.cc15
-rw-r--r--src/util.h3
4 files changed, 18 insertions, 13 deletions
diff --git a/src/ssa_reader.cc b/src/ssa_reader.cc
index bac893b..859a00e 100644
--- a/src/ssa_reader.cc
+++ b/src/ssa_reader.cc
@@ -227,6 +227,7 @@ SSAReader::read (function<optional<string> ()> get_line)
}
trim (*line);
+ remove_unicode_bom (line);
if (starts_with (*line, ";") || line->empty ()) {
continue;
diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc
index a82862c..f71843e 100644
--- a/src/subrip_reader.cc
+++ b/src/subrip_reader.cc
@@ -81,17 +81,7 @@ SubripReader::read (function<optional<string> ()> get_line)
}
trim_right_if (*line, boost::is_any_of ("\n\r"));
-
- if (
- line->length() >= 3 &&
- static_cast<unsigned char> (line.get()[0]) == 0xef &&
- static_cast<unsigned char> (line.get()[1]) == 0xbb &&
- static_cast<unsigned char> (line.get()[2]) == 0xbf
- ) {
-
- /* Skip Unicode byte order mark */
- line = line->substr (3);
- }
+ remove_unicode_bom (line);
switch (state) {
case COUNTER:
diff --git a/src/util.cc b/src/util.cc
index 5510d8e..a736a91 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -65,3 +65,18 @@ sub::get_line_file (FILE* f)
return string (buffer);
}
+
+void
+sub::remove_unicode_bom (optional<string>& line)
+{
+ if (
+ line->length() >= 3 &&
+ static_cast<unsigned char> (line.get()[0]) == 0xef &&
+ static_cast<unsigned char> (line.get()[1]) == 0xbb &&
+ static_cast<unsigned char> (line.get()[2]) == 0xbf
+ ) {
+
+ /* Skip Unicode byte order mark */
+ line = line->substr (3);
+ }
+}
diff --git a/src/util.h b/src/util.h
index 9d3edc2..dea8023 100644
--- a/src/util.h
+++ b/src/util.h
@@ -23,9 +23,8 @@
namespace sub {
extern bool empty_or_white_space (std::string s);
+extern void remove_unicode_bom (boost::optional<std::string>& line);
extern boost::optional<std::string> get_line_stringstream (std::stringstream* str);
extern boost::optional<std::string> get_line_file (FILE* f);
}
-
-