From: Carl Hetherington Date: Mon, 23 Jun 2014 13:50:51 +0000 (+0100) Subject: Be more careful when mangling DCP names to fit ISDCF. X-Git-Tag: v2.0.48~551^2~58 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=fef348c69139de43a0603de7b1fe4295af4c5d47 Be more careful when mangling DCP names to fit ISDCF. Reported-by: Jonathan Jensen --- diff --git a/ChangeLog b/ChangeLog index 818daeec2..da705b387 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2014-06-23 Carl Hetherington + * Try harder to cope with DCP names specified + already in CamelCase. + * Add option to CC a KDM email, and add $SCREENS and $CINEMA_NAME as variables in the email. diff --git a/src/lib/film.cc b/src/lib/film.cc index 609003bba..940eba1eb 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -77,6 +77,7 @@ using boost::to_upper_copy; using boost::ends_with; using boost::starts_with; using boost::optional; +using boost::is_any_of; using libdcp::Size; using libdcp::Signer; using libdcp::raw_convert; @@ -495,16 +496,39 @@ Film::isdcf_name (bool if_created_now) const stringstream d; string raw_name = name (); + + /* Split the raw name up into words */ + vector words; + split (words, raw_name, is_any_of (" ")); + string fixed_name; - bool cap_next = true; - for (size_t i = 0; i < raw_name.length(); ++i) { - if (raw_name[i] == ' ') { - cap_next = true; - } else if (cap_next) { - fixed_name += toupper (raw_name[i]); - cap_next = false; - } else { - fixed_name += tolower (raw_name[i]); + + /* Add each word to fixed_name */ + for (vector::const_iterator i = words.begin(); i != words.end(); ++i) { + string w = *i; + + /* First letter is always capitalised */ + w[0] = toupper (w[0]); + + /* Count caps in w */ + size_t caps = 0; + for (size_t i = 0; i < w.size(); ++i) { + if (isupper (w[i])) { + ++caps; + } + } + + /* If w is all caps make the rest of it lower case, otherwise + leave it alone. + */ + if (caps == w.size ()) { + for (size_t i = 1; i < w.size(); ++i) { + w[i] = tolower (w[i]); + } + } + + for (size_t i = 0; i < w.size(); ++i) { + fixed_name += w[i]; } } diff --git a/test/isdcf_name_test.cc b/test/isdcf_name_test.cc index dd1b64162..c2ea833bd 100644 --- a/test/isdcf_name_test.cc +++ b/test/isdcf_name_test.cc @@ -101,5 +101,25 @@ BOOST_AUTO_TEST_CASE (isdcf_name_test) film->set_isdcf_metadata (m); film->set_video_frame_rate (48); BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2-Temp-Pre-RedBand-MyChain-2D-4fl-48_F-133_DE-FR_US-R_10_4K_DI_20140704_PP_SMPTE_VF"); + + /* Test a name which is already in camelCase */ + + film->set_three_d (false); + m.temp_version = false; + m.pre_release = false; + m.red_band = false; + m.chain = ""; + m.two_d_version_of_three_d = false; + m.mastered_luminance = ""; + film->set_isdcf_metadata (m); + film->set_video_frame_rate (24); + film->set_name ("IKnowCamels"); + BOOST_CHECK_EQUAL (film->isdcf_name(false), "IKnowCamels_XSN-2_F-133_DE-FR_US-R_10_4K_DI_20140704_PP_SMPTE_VF"); + + /* And one in capitals */ + + film->set_name ("LIKE SHOUTING"); + BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-FR_US-R_10_4K_DI_20140704_PP_SMPTE_VF"); } +