diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/cinema_kdms.cc | 2 | ||||
| -rw-r--r-- | src/lib/screen_kdm.cc | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 29 |
3 files changed, 27 insertions, 6 deletions
diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc index 2e1d03b40..558aee504 100644 --- a/src/lib/cinema_kdms.cc +++ b/src/lib/cinema_kdms.cc @@ -67,7 +67,7 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat nam name_values['s'] = i.screen->name; name_values['i'] = i.kdm.id (); - string const name = name_format.get(name_values, ".xml"); + string const name = careful_string_filter(name_format.get(name_values, ".xml")); if (zip_add (zip, name.c_str(), source) == -1) { throw runtime_error ("failed to add KDM to ZIP archive"); } diff --git a/src/lib/screen_kdm.cc b/src/lib/screen_kdm.cc index df74cc7ef..5b7692469 100644 --- a/src/lib/screen_kdm.cc +++ b/src/lib/screen_kdm.cc @@ -65,7 +65,7 @@ ScreenKDM::write_files ( name_values['c'] = i.screen->cinema ? i.screen->cinema->name : ""; name_values['s'] = i.screen->name; name_values['i'] = i.kdm.id (); - boost::filesystem::path out = directory / (name_format.get(name_values, ".xml")); + boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml")); if (!boost::filesystem::exists (out) || confirm_overwrite (out)) { i.kdm.as_xml (out); ++written; diff --git a/src/lib/util.cc b/src/lib/util.cc index b52655194..c20891464 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -62,6 +62,7 @@ extern "C" { #include <boost/range/algorithm/replace_if.hpp> #include <boost/thread.hpp> #include <boost/filesystem.hpp> +#include <boost/locale.hpp> #ifdef DCPOMATIC_WINDOWS #include <boost/locale.hpp> #include <dbghelp.h> @@ -80,6 +81,7 @@ extern "C" { #include "i18n.h" using std::string; +using std::wstring; using std::setfill; using std::ostream; using std::endl; @@ -743,15 +745,34 @@ careful_string_filter (string s) Safety first and all that. */ + wstring ws = boost::locale::conv::utf_to_utf<wchar_t>(s); + string out; string const allowed = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_%.+"; - for (size_t i = 0; i < s.size(); ++i) { - if (allowed.find (s[i]) != string::npos) { - out += s[i]; + for (size_t i = 0; i < ws.size(); ++i) { + + wchar_t c = ws[i]; + + /* Remove some accents */ + if (wstring(L"áàâ").find(c) != string::npos) { + c = 'a'; + } + if (wstring(L"éèêë").find(c) != string::npos) { + c = 'e'; + } + if (wstring(L"ö").find(c) != string::npos) { + c = 'o'; + } + if (wstring(L"ü").find(c) != string::npos) { + c = 'u'; + } + + if (allowed.find(c) != string::npos) { + out += c; } } - return out; + return boost::locale::conv::utf_to_utf<char>(out); } /** @param mapped List of mapped audio channels from a Film. |
