mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Using new basetoolkit function for unique naming
applied to source and snapshot names
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
#include <locale>
|
||||
#include <unicode/ustream.h>
|
||||
@@ -18,6 +19,33 @@ uint64_t BaseToolkit::uniqueId()
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string BaseToolkit::uniqueName(const std::string &basename, std::list<std::string> existingnames)
|
||||
{
|
||||
std::string tentativename = basename;
|
||||
int count = 1;
|
||||
int max = 100;
|
||||
|
||||
// while tentativename can be found in the list of existingnames
|
||||
while ( std::find( existingnames.begin(), existingnames.end(), tentativename ) != existingnames.end() )
|
||||
{
|
||||
for( auto it = existingnames.cbegin(); it != existingnames.cend(); ++it) {
|
||||
if ( it->find(tentativename) != std::string::npos)
|
||||
++count;
|
||||
}
|
||||
|
||||
if (count > 1)
|
||||
tentativename = basename + "_" + std::to_string( count );
|
||||
else
|
||||
tentativename += "_";
|
||||
|
||||
if ( --max < 0 ) // for safety only, should never be needed
|
||||
break;
|
||||
}
|
||||
|
||||
return tentativename;
|
||||
}
|
||||
|
||||
// Using ICU transliteration :
|
||||
// https://unicode-org.github.io/icu/userguide/transforms/general/#icu-transliterators
|
||||
|
||||
|
||||
Reference in New Issue
Block a user