From b651392d70d7e37ce5a8a20da81d86e5d19aadd8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 15 Dec 2019 22:58:21 +0100 Subject: Add fix_empty_font_ids() to replace empty Font ids with a dummy string. Back-ported from abf4f7577877254ecd7a1dc7955e0d7ca49ad07c in master. --- src/util.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/util.cc') 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 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); +} -- cgit v1.2.3