summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-11-25 11:23:07 +0000
committerCarl Hetherington <cth@carlh.net>2013-11-25 11:23:07 +0000
commit6b8fdf76aa221f037140bbf0ee1aa835df60778f (patch)
tree7798c30001a4fea8af5ba9e19c9ad5fd62d6ce17 /src
parent331045156161a30ee74e734c7c14dd602ebbbbc9 (diff)
Remove a possibly dodgy use of fstream.
Diffstat (limited to 'src')
-rw-r--r--src/subtitle_asset.cc12
-rw-r--r--src/subtitle_asset.h2
-rw-r--r--src/util.cc17
-rw-r--r--src/util.h1
4 files changed, 26 insertions, 6 deletions
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc
index d48d4ac0..97c48978 100644
--- a/src/subtitle_asset.cc
+++ b/src/subtitle_asset.cc
@@ -302,12 +302,14 @@ struct SubtitleSorter {
void
SubtitleAsset::write_xml () const
{
- ofstream s (path().string().c_str());
- write_xml (s);
+ FILE* f = fopen_boost (path (), "r");
+ Glib::ustring const s = xml_as_string ();
+ fwrite (s.c_str(), 1, s.length(), f);
+ fclose (f);
}
-void
-SubtitleAsset::write_xml (ostream& s) const
+Glib::ustring
+SubtitleAsset::xml_as_string () const
{
xmlpp::Document doc;
xmlpp::Element* root = doc.create_root_node ("DCSubtitle");
@@ -415,6 +417,6 @@ SubtitleAsset::write_xml (ostream& s) const
text->add_child_text ((*i)->text());
}
- doc.write_to_stream_formatted (s, "UTF-8");
+ return doc.write_to_string_formatted ("UTF-8");
}
diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h
index 6d6186a0..7a00e036 100644
--- a/src/subtitle_asset.h
+++ b/src/subtitle_asset.h
@@ -159,7 +159,7 @@ public:
void read_xml (std::string);
void write_xml () const;
- void write_xml (std::ostream &) const;
+ Glib::ustring xml_as_string () const;
private:
std::string font_id_to_name (std::string id) const;
diff --git a/src/util.cc b/src/util.cc
index 59078511..8624ae51 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -343,3 +343,20 @@ libdcp::ptime_to_string (boost::posix_time::ptime t)
struct tm t_tm = boost::posix_time::to_tm (t);
return tm_to_string (&t_tm);
}
+
+
+/* Apparently there is no way to create an ofstream using a UTF-8
+ filename under Windows. We are hence reduced to using fopen
+ with this wrapper.
+*/
+FILE *
+libdcp::fopen_boost (boost::filesystem::path p, string t)
+{
+#ifdef LIBDCP_WINDOWS
+ wstring w (t.begin(), t.end());
+ /* c_str() here should give a UTF-16 string */
+ return _wfopen (p.c_str(), w.c_str ());
+#else
+ return fopen (p.c_str(), t.c_str ());
+#endif
+}
diff --git a/src/util.h b/src/util.h
index 2f661d77..2a6aae1b 100644
--- a/src/util.h
+++ b/src/util.h
@@ -84,6 +84,7 @@ extern int base64_decode (std::string const & in, unsigned char* out, int out_le
extern std::string tm_to_string (struct tm *);
extern std::string utc_offset_to_string (int);
extern std::string ptime_to_string (boost::posix_time::ptime);
+extern FILE * fopen_boost (boost::filesystem::path, std::string);
}