[Bf-blender-cvs] [e0303d0297] master: Cleanup/refactor: move BKE_deform_flip_side_name & co to BLI_string_utils

Bastien Montagne noreply at git.blender.org
Mon Jan 16 20:49:31 CET 2017


Commit: e0303d02974c914d4633e37d789e33b21689b5eb
Author: Bastien Montagne
Date:   Mon Jan 16 20:34:13 2017 +0100
Branches: master
https://developer.blender.org/rBe0303d02974c914d4633e37d789e33b21689b5eb

Cleanup/refactor: move BKE_deform_flip_side_name & co to BLI_string_utils

Functions like that do not have anything to do in BKE really, even less
when actually more used for bones than vgroups!

===================================================================

M	source/blender/blenkernel/BKE_deform.h
M	source/blender/blenkernel/intern/action.c
M	source/blender/blenkernel/intern/deform.c
M	source/blender/blenkernel/intern/object_deform.c
M	source/blender/blenlib/BLI_string_utils.h
M	source/blender/blenlib/intern/string_utils.c
M	source/blender/editors/animation/keyframes_general.c
M	source/blender/editors/armature/armature_add.c
M	source/blender/editors/armature/armature_naming.c
M	source/blender/editors/armature/armature_select.c
M	source/blender/editors/armature/armature_skinning.c
M	source/blender/editors/armature/armature_utils.c
M	source/blender/editors/armature/pose_transform.c
M	source/blender/editors/object/object_select.c
M	source/blender/editors/sculpt_paint/paint_vertex.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h
index a6d1139648..3ce08a1417 100644
--- a/source/blender/blenkernel/BKE_deform.h
+++ b/source/blender/blenkernel/BKE_deform.h
@@ -116,12 +116,4 @@ void BKE_defvert_extract_vgroup_to_polyweights(
         struct MDeformVert *dvert, const int defgroup, const int num_verts, struct MLoop *loops, const int num_loops,
         struct MPoly *polys, const int num_polys, float *r_weights, const bool invert_vgroup);
 
-/* utility function, note that MAX_VGROUP_NAME chars is the maximum string length since its only
- * used with defgroups currently */
-
-void BKE_deform_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len);
-void BKE_deform_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len);
-
-void BKE_deform_flip_side_name(char *r_name, const char *from_name, const bool strip_number, const size_t name_len);
-
 #endif  /* __BKE_DEFORM_H__ */
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index d1b0306c27..1e33fe4ab4 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -495,7 +495,7 @@ bPoseChannel *BKE_pose_channel_get_mirrored(const bPose *pose, const char *name)
 {
 	char name_flip[MAXBONENAME];
 
-	BKE_deform_flip_side_name(name_flip, name, false, sizeof(name_flip));
+	BLI_string_flip_side_name(name_flip, name, false, sizeof(name_flip));
 
 	if (!STREQ(name_flip, name)) {
 		return BKE_pose_channel_find_name(pose, name_flip);
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 783455ef6f..13b1aab5e1 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -509,7 +509,7 @@ int *defgroup_flip_map(Object *ob, int *flip_map_len, const bool use_default)
 				if (use_default)
 					map[i] = i;
 
-				BKE_deform_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
+				BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
 
 				if (!STREQ(name_flip, dg->name)) {
 					flip_num = defgroup_name_index(ob, name_flip);
@@ -545,7 +545,7 @@ int *defgroup_flip_map_single(Object *ob, int *flip_map_len, const bool use_defa
 
 		dg = BLI_findlink(&ob->defbase, defgroup);
 
-		BKE_deform_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
+		BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
 		if (!STREQ(name_flip, dg->name)) {
 			flip_num = defgroup_name_index(ob, name_flip);
 
@@ -566,7 +566,7 @@ int defgroup_flip_index(Object *ob, int index, const bool use_default)
 
 	if (dg) {
 		char name_flip[sizeof(dg->name)];
-		BKE_deform_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
+		BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
 
 		if (!STREQ(name_flip, dg->name)) {
 			flip_index = defgroup_name_index(ob, name_flip);
@@ -606,184 +606,6 @@ void defgroup_unique_name(bDeformGroup *dg, Object *ob)
 	BLI_uniquename_cb(defgroup_unique_check, &data, DATA_("Group"), '.', dg->name, sizeof(dg->name));
 }
 
-static bool is_char_sep(const char c)
-{
-	return ELEM(c, '.', ' ', '-', '_');
-}
-
-/**
- * based on `BLI_split_dirfile()` / `os.path.splitext()`,
- * `"a.b.c"` -> (`"a.b"`, `".c"`).
- */
-void BKE_deform_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len)
-{
-	size_t len = BLI_strnlen(string, str_len);
-	size_t i;
-
-	r_body[0] = r_suf[0] = '\0';
-
-	for (i = len; i > 0; i--) {
-		if (is_char_sep(string[i])) {
-			BLI_strncpy(r_body, string, i + 1);
-			BLI_strncpy(r_suf, string + i,  (len + 1) - i);
-			return;
-		}
-	}
-
-	memcpy(r_body, string, len + 1);
-}
-
-/**
- * `"a.b.c"` -> (`"a."`, `"b.c"`)
- */
-void BKE_deform_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len)
-{
-	size_t len = BLI_strnlen(string, str_len);
-	size_t i;
-
-	r_body[0] = r_pre[0] = '\0';
-
-	for (i = 1; i < len; i++) {
-		if (is_char_sep(string[i])) {
-			i++;
-			BLI_strncpy(r_pre, string, i + 1);
-			BLI_strncpy(r_body, string + i, (len + 1) - i);
-			return;
-		}
-	}
-
-	BLI_strncpy(r_body, string, len);
-}
-
-/**
- * Finds the best possible flipped (left/right) name. For renaming; check for unique names afterwards.
- *
- * \param r_name flipped name, assumed to be a pointer to a string of at least \a name_len size.
- * \param from_name original name, assumed to be a pointer to a string of at least \a name_len size.
- * \param strip_number If set, remove number extensions.
- */
-void BKE_deform_flip_side_name(char *r_name, const char *from_name, const bool strip_number, const size_t name_len)
-{
-	size_t len;
-	char *prefix  = alloca(name_len);   /* The part before the facing */
-	char *suffix  = alloca(name_len);   /* The part after the facing */
-	char *replace = alloca(name_len);   /* The replacement string */
-	char *number  = alloca(name_len);   /* The number extension string */
-	char *index = NULL;
-	bool is_set = false;
-
-	*prefix = *suffix = *replace = *number = '\0';
-
-	/* always copy the name, since this can be called with an uninitialized string */
-	BLI_strncpy(r_name, from_name, name_len);
-
-	len = BLI_strnlen(from_name, name_len);
-	if (len < 3) {
-		/* we don't do names like .R or .L */
-		return;
-	}
-
-	/* We first check the case with a .### extension, let's find the last period */
-	if (isdigit(r_name[len - 1])) {
-		index = strrchr(r_name, '.'); // last occurrence
-		if (index && isdigit(index[1])) { // doesnt handle case bone.1abc2 correct..., whatever!
-			if (strip_number == false) {
-				BLI_strncpy(number, index, name_len);
-			}
-			*index = 0;
-			len = BLI_strnlen(r_name, name_len);
-		}
-	}
-
-	BLI_strncpy(prefix, r_name, name_len);
-
-	/* first case; separator . - _ with extensions r R l L  */
-	if ((len > 1) && is_char_sep(r_name[len - 2])) {
-		is_set = true;
-		switch (r_name[len - 1]) {
-			case 'l':
-				prefix[len - 1] = 0;
-				strcpy(replace, "r");
-				break;
-			case 'r':
-				prefix[len - 1] = 0;
-				strcpy(replace, "l");
-				break;
-			case 'L':
-				prefix[len - 1] = 0;
-				strcpy(replace, "R");
-				break;
-			case 'R':
-				prefix[len - 1] = 0;
-				strcpy(replace, "L");
-				break;
-			default:
-				is_set = false;
-		}
-	}
-
-	/* case; beginning with r R l L, with separator after it */
-	if (!is_set && is_char_sep(r_name[1])) {
-		is_set = true;
-		switch (r_name[0]) {
-			case 'l':
-				strcpy(replace, "r");
-				BLI_strncpy(suffix, r_name + 1, name_len);
-				prefix[0] = 0;
-				break;
-			case 'r':
-				strcpy(replace, "l");
-				BLI_strncpy(suffix, r_name + 1, name_len);
-				prefix[0] = 0;
-				break;
-			case 'L':
-				strcpy(replace, "R");
-				BLI_strncpy(suffix, r_name + 1, name_len);
-				prefix[0] = 0;
-				break;
-			case 'R':
-				strcpy(replace, "L");
-				BLI_strncpy(suffix, r_name + 1, name_len);
-				prefix[0] = 0;
-				break;
-			default:
-				is_set = false;
-		}
-	}
-
-	if (!is_set && len > 5) {
-		/* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
-		if (((index = BLI_strcasestr(prefix, "right")) == prefix) ||
-		    (index == prefix + len - 5))
-		{
-			is_set = true;
-			if (index[0] == 'r') {
-				strcpy(replace, "left");
-			}
-			else {
-				strcpy(replace, (index[1] == 'I') ? "LEFT" : "Left");
-			}
-			*index = 0;
-			BLI_strncpy(suffix, index + 5, name_len);
-		}
-		else if (((index = BLI_strcasestr(prefix, "left")) == prefix) ||
-		         (index == prefix + len - 4))
-		{
-			is_set = true;
-			if (index[0] == 'l') {
-				strcpy(replace, "right");
-			}
-			else {
-				strcpy(replace, (index[1] == 'E') ? "RIGHT" : "Right");
-			}
-			*index = 0;
-			BLI_strncpy(suffix, index + 4, name_len);
-		}
-	}
-
-	BLI_snprintf(r_name, name_len, "%s%s%s%s", prefix, replace, suffix, number);
-}
-
 float defvert_find_weight(const struct MDeformVert *dvert, const int defgroup)
 {
 	MDeformWeight *dw = defvert_find_index(dvert, defgroup);
diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c
index ce8c7919a2..ccf2aec5c7 100644
--- a/source/blender/blenkernel/intern/object_deform.c
+++ b/source/blender/blenkernel/intern/object_deform.c
@@ -32,6 +32,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
+#include "BLI_string_utils.h"
 
 #include "DNA_armature_types.h"
 #include "DNA_cloth_types.h"
@@ -623,7 +624,7 @@ void BKE_object_defgroup_mirror_selection(
 		if (dg_selection[i]) {
 			char name_flip[MAXBONENAME];
 
-			BKE_deform_flip_side_name(name_flip, defgroup->name, false, sizeof(name_flip));
+			BLI_string_flip_side_name(name_flip, defgroup->name, false, sizeof(name_flip));
 			i_mirr = STREQ(name_flip, defgroup->name) ? i : defgroup_name_index(ob, name_flip);
 
 			if ((i_mirr >= 0 && i_mirr < defbase_tot) && (dg_flags_sel[i_mirr] == false)) {
diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h
index 81c06fbc20..719d6e3c57 100644
--- a/source/blender/blenlib/BLI_string_utils.h
+++ b/source/blender/blenlib/BLI_string_utils.h
@@ -46,6 +46,11 @@ typedef bool (*UniquenameCheckCallback)(void *arg, const char *name);
 
 int BLI_split_name_num(char *left, int *nr, const char *name, const char delim);
 
+void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len);
+void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len);
+
+void BLI_string_flip_side_name(char *r_name, const char *from_name, const bool strip_number, const size_t name_len);
+
 bool BLI_uniquename_cb(
         UniquenameCheckCallback unique_check, void *arg, const char *defname, char delim, char *name, size_t name_len);
 bool BLI_uniquename(
diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c
index a7427b6848..435a88d6e2 100644
--- a/source/blender/blenlib/intern/string_utils.c
+++ b/source/blender/blenlib/intern/string_utils.c
@@ -90,6 +90,184 @@ int BLI_split_name_num(char *left, int *nr, const char *name, const char delim)
 	return name_len;
 }
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list