diff options
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 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); +} |
