mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-22 15:47:30 +02:00
b2/util.c: new function unique_n for strings limited by length and not NUL
This commit is contained in:
parent
9445f2c85b
commit
b9066c6331
18
b2/util.c
18
b2/util.c
@ -38,3 +38,21 @@ const char *unique(const char *s)
|
|||||||
}
|
}
|
||||||
return u;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user