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");
text->add_child_text ((*i)->text());
}
- doc.write_to_stream_formatted (s, "UTF-8");
+ return doc.write_to_string_formatted ("UTF-8");
}
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;
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
+}
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);
}
libdcp::SubtitleAsset s ("foo", "bar", "baz");
s.read_xml (argv[1]);
- s.write_xml (cout);
+ cout << s.xml_as_string ();
return 0;
}