Be more careful when mangling DCP names to fit ISDCF.
authorCarl Hetherington <cth@carlh.net>
Mon, 23 Jun 2014 13:50:51 +0000 (14:50 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 23 Jun 2014 13:50:51 +0000 (14:50 +0100)
Reported-by: Jonathan Jensen
ChangeLog
src/lib/film.cc
test/isdcf_name_test.cc

index 818daeec2a92997e9a1c0ca8ccb20bdaab6be210..da705b387382314e81ae8b392fb08bf7e918feaa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2014-06-23  Carl Hetherington  <cth@carlh.net>
 
+       * 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.
index 609003bbae7f2f632c1d190da567b70ce6133e18..940eba1eb10e1a0fe34f6aa68f4a0e80c002225d 100644 (file)
@@ -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<string> 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<string>::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];
                }
        }
 
index dd1b64162a7051f564513a17f362e39e2398b7f9..c2ea833bd859c13e7f6cf7136d1f89f1f12de314 100644 (file)
@@ -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");
 }
 
+