summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-06-23 14:50:51 +0100
committerCarl Hetherington <cth@carlh.net>2014-06-23 14:50:51 +0100
commitfef348c69139de43a0603de7b1fe4295af4c5d47 (patch)
tree9fab57f304f10a72700c6a2284ddd61a2a3239ca /src/lib
parent33755d92926f6e9bf7403f3bde8b1d0645e6a618 (diff)
Be more careful when mangling DCP names to fit ISDCF.
Reported-by: Jonathan Jensen
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/film.cc42
1 files changed, 33 insertions, 9 deletions
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<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];
}
}