Add fix_empty_font_ids() to replace empty Font ids with a dummy string.
[libdcp.git] / src / util.cc
index d5b6cb9f4eaeed6ccc33a493ea6766eac9389446..bce28f074844035bdafe92703081e4efa08d7a58 100644 (file)
@@ -376,3 +376,20 @@ dcp::indent (xmlpp::Element* element, int initial)
                element->add_child_text (last, "\n" + spaces(initial));
        }
 }
+
+/** Try quite hard to find a string which starts with \ref base and is
+ *  not in \ref existing.
+ */
+string
+dcp::unique_string (list<string> existing, string base)
+{
+       int const max_tries = existing.size() + 1;
+       for (int i = 0; i < max_tries; ++i) {
+               string trial = String::compose("%1%2", base, i);
+               if (find(existing.begin(), existing.end(), trial) == existing.end()) {
+                       return trial;
+               }
+       }
+
+       DCP_ASSERT (false);
+}