Skip to content
Snippets Groups Projects
Commit 10f3b3a0 authored by Tom Fischer's avatar Tom Fischer
Browse files

[BL] Implement getUniqueName.

parent 9411d690
No related branches found
No related tags found
No related merge requests found
......@@ -119,4 +119,19 @@ std::string randomString(std::size_t const length)
return s;
}
std::string getUniqueName(std::vector<std::string> const& existing_names,
std::string const& input_name)
{
std::string result_name = input_name;
std::size_t count = 1;
while (std::find(existing_names.cbegin(),
existing_names.cend(),
result_name) != existing_names.end())
{
count++;
result_name = input_name + "-" + std::to_string(count);
}
return result_name;
}
} // end namespace BaseLib
......@@ -75,4 +75,7 @@ void simplify(std::string &str);
//! Returns a random string of the given length containing just a-z,A-Z,0-9
std::string randomString(std::size_t length);
//! Append '-' and a number such that the name is unique.
std::string getUniqueName(std::vector<std::string> const& existing_names,
std::string const& input_name);
} // end namespace BaseLib
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment