diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-12-15 22:58:21 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-12-22 01:21:00 +0100 |
| commit | dd0db15b82a0b40b1271bad122c874d458c0fef4 (patch) | |
| tree | 201b4efac6915353e9635f230b3a08297be87dd7 /src/util.cc | |
| parent | 82c72bf1a25891d5053b7b4fb1f7d2bab9d7fd13 (diff) | |
Add fix_empty_font_ids() to replace empty Font ids with a dummy string.
Diffstat (limited to 'src/util.cc')
| -rw-r--r-- | src/util.cc | 17 |
1 files changed, 17 insertions, 0 deletions
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<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); +} |
