From dd0db15b82a0b40b1271bad122c874d458c0fef4 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. --- 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 c6313b4c..533ee466 100644 --- a/src/util.cc +++ b/src/util.cc @@ -410,3 +410,20 @@ dcp::day_greater_than_or_equal (struct tm a, LocalTime b) return a.tm_mday >= b.day(); } + +/** 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