diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-30 12:24:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-30 12:24:44 +0400 |
commit | 60c9addf79fdd68ceda48e451260a74f403f9e15 (patch) | |
tree | 1c90761d07c2012efbd19fe1be7e19b68ae8bd99 /source/blender/blenkernel/intern/deform.c | |
parent | 238af29b39f7a059c5bfd4124d8976cf34534a78 (diff) |
- improve select grouped prefix/suffix from recent patch
- added select similar direction (Y axis)
Diffstat (limited to 'source/blender/blenkernel/intern/deform.c')
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index a14456845b9..ebf5735c1cd 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -437,11 +437,51 @@ void defgroup_unique_name(bDeformGroup *dg, Object *ob) BLI_uniquename_cb(defgroup_unique_check, &data, "Group", '.', dg->name, sizeof(dg->name)); } -int BKE_deform_is_char_sep(const char c) +static int is_char_sep(const char c) { return ELEM4(c, '.', ' ', '-', '_'); } +/* based on BLI_split_dirfile() / os.path.splitext(), "a.b.c" -> ("a.b", ".c") */ + +void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME], char suf[MAX_VGROUP_NAME]) +{ + size_t len = BLI_strnlen(string, MAX_VGROUP_NAME); + size_t i; + + body[0] = suf[0] = '\0'; + + for (i = len - 1; i > 1; i--) { + if (is_char_sep(string[i])) { + BLI_strncpy(body, string, i + 1); + BLI_strncpy(suf, string + i, (len + 1) - i); + return; + } + } + + BLI_strncpy(body, string, len); +} + +/* "a.b.c" -> ("a.", "b.c") */ +void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char pre[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME]) +{ + size_t len = BLI_strnlen(string, MAX_VGROUP_NAME); + size_t i; + + body[0] = pre[0] = '\0'; + + for (i = 1; i < len; i++) { + if (is_char_sep(string[i])) { + i++; + BLI_strncpy(pre, string, i + 1); + BLI_strncpy(body, string + i, (len + 1) - i); + return; + } + } + + BLI_strncpy(body, string, len); +} + /* finds the best possible flipped name. For renaming; check for unique names afterwards */ /* if strip_number: removes number extensions * note: don't use sizeof() for 'name' or 'from_name' */ @@ -478,7 +518,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ BLI_strncpy(prefix, name, sizeof(prefix)); /* first case; separator . - _ with extensions r R l L */ - if (BKE_deform_is_char_sep(name[len - 2])) { + if (is_char_sep(name[len - 2])) { switch (name[len - 1]) { case 'l': prefix[len - 1] = 0; @@ -499,7 +539,7 @@ void flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_ } } /* case; beginning with r R l L , with separator after it */ - else if (BKE_deform_is_char_sep(name[1])) { + else if (is_char_sep(name[1])) { switch (name[0]) { case 'l': strcpy(replace, "r"); |