diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-07 11:49:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-07 11:49:07 +0300 |
commit | 20b16e4074eb0b015a94bd5738c76dafaca250db (patch) | |
tree | 2b348e906db0a01b2d0b033d0780cfeb05e4f445 /source/blender/blenkernel/intern/nla.c | |
parent | fbcaa502ca8e71390e3f43ee9cc18b1ccfe840a2 (diff) |
de-duplicate unique naming logic, was used in 7 different places, convert into a function call.
Diffstat (limited to 'source/blender/blenkernel/intern/nla.c')
-rw-r--r-- | source/blender/blenkernel/intern/nla.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 423ccb00e8e..910de5c6763 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1204,6 +1204,11 @@ void BKE_nlastrip_validate_fcurves (NlaStrip *strip) } } +static int nla_editbone_name_check(void *arg, const char *name) +{ + return BLI_ghash_haskey((GHash *)arg, (void *)name); +} + /* Sanity Validation ------------------------------------ */ /* Find (and set) a unique name for a strip from the whole AnimData block @@ -1259,21 +1264,7 @@ void BKE_nlastrip_validate_name (AnimData *adt, NlaStrip *strip) /* if the hash-table has a match for this name, try other names... * - in an extreme case, it might not be able to find a name, but then everything else in Blender would fail too :) */ - if (BLI_ghash_haskey(gh, strip->name)) { - /* note: this block is used in other places, when changing logic apply to all others, search this message */ - char tempname[sizeof(strip->name)]; - char left[sizeof(strip->name)]; - int number; - int len= BLI_split_name_num(left, &number, strip->name); - do { /* nested while loop looks bad but likely it wont run most times */ - while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) { - if(len > 0) left[--len]= '\0'; /* word too long */ - else number= 0; /* reset, must be a massive number */ - } - } while(number++, BLI_ghash_haskey(gh, tempname)); - - BLI_strncpy(strip->name, tempname, sizeof(strip->name)); - } + BLI_uniquename_cb(nla_editbone_name_check, (void *)gh, "NlaStrip", '.', strip->name, sizeof(strip->name)); /* free the hash... */ BLI_ghash_free(gh, NULL, NULL); |