Utilities
Used across glitter2.
- glitter2.utils.fix_name(name, *names, ignore_case=True)
Fixes the name so that it is unique among the names in
names
.- Params
- name: str
A name of something
- *names: iterables of strings
Positional argument, where each is a iterable of strings among which we ensure that the returned name is unique.
- Returns
A string that is unique among all the
names
, but is similar toname
. We append a integer to make it unique.
E.g.:
>>> fix_name('troll', ['toll', 'foll'], ['bole', 'cole']) 'troll' >>> fix_name('troll', ['troll', 'toll', 'foll'], ['bole', 'cole']) 'troll-2' >>> fix_name('troll', ['troll-2', 'toll', 'foll'], ['bole', 'cole']) 'troll' >>> fix_name('troll', ['troll', 'troll-2', 'toll', 'foll'], ['bole', 'cole']) 'troll-3'