boost::filesystem::path
subtitle_file (shared_ptr<Film> film)
{
- for (auto i: boost::filesystem::directory_iterator(film->directory().get() / film->dcp_name (false))) {
- if (boost::filesystem::is_directory(i.path())) {
- for (auto j: boost::filesystem::directory_iterator(i.path())) {
- if (boost::algorithm::starts_with(j.path().leaf().string(), "sub_")) {
- return j.path();
- }
- }
+ for (auto i: boost::filesystem::recursive_directory_iterator(film->directory().get() / film->dcp_name(false))) {
+ if (boost::algorithm::starts_with(i.path().leaf().string(), "sub_")) {
+ return i.path();
}
}
BOOST_REQUIRE (found);
return *found;
}
+
+
+Editor::Editor(boost::filesystem::path path)
+ : _path(path)
+ , _content(dcp::file_to_string(path))
+{
+
+}
+
+Editor::~Editor()
+{
+ auto f = fopen(_path.string().c_str(), "w");
+ BOOST_REQUIRE(f);
+ fwrite(_content.c_str(), _content.length(), 1, f);
+ fclose(f);
+}
+
+void
+Editor::replace(string a, string b)
+{
+ auto old_content = _content;
+ boost::algorithm::replace_all(_content, a, b);
+ BOOST_REQUIRE(_content != old_content);
+}