summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-12-15 22:58:21 +0100
committerCarl Hetherington <cth@carlh.net>2019-12-15 23:05:32 +0100
commitb651392d70d7e37ce5a8a20da81d86e5d19aadd8 (patch)
tree6bd8a29af4ac175b088e166d0bd10966f921263f /src/util.cc
parentfb0dfadb60cffe811b89e6ad9d2d5b510a47c62b (diff)
Add fix_empty_font_ids() to replace empty Font ids with a dummy string.v1.6.14
Back-ported from abf4f7577877254ecd7a1dc7955e0d7ca49ad07c in master.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index d5b6cb9f..bce28f07 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -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);
+}