mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2025-04-21 12:27:27 +03:00
b2/util.c: new function unique_n for strings limited by length and not NUL
This commit is contained in:
18
b2/util.c
18
b2/util.c
@@ -38,3 +38,21 @@ const char *unique(const char *s)
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
|
||||
const char *unique_n(const char *s, int n)
|
||||
{
|
||||
char *tmp, *u;
|
||||
|
||||
if (!tree)
|
||||
tree = g_tree_new(comp);
|
||||
tmp = stralloc_n(s, n);
|
||||
u = g_tree_lookup(tree, tmp);
|
||||
if (u) {
|
||||
free(tmp);
|
||||
return u;
|
||||
} else {
|
||||
g_tree_insert(tree, tmp, tmp);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user