[Bf-blender-cvs] [9c0de00] master: Fix T47661: cm (centimeter) unit breaks m (meter) unit in Metric.

Bastien Montagne noreply at git.blender.org
Wed Mar 2 18:02:40 CET 2016


Commit: 9c0de0084bfed50a78798c1f0df51fef0ce9e2bd
Author: Bastien Montagne
Date:   Wed Mar 2 17:57:03 2016 +0100
Branches: master
https://developer.blender.org/rB9c0de0084bfed50a78798c1f0df51fef0ce9e2bd

Fix T47661: cm (centimeter) unit breaks m (meter) unit in Metric.

`m` unit when used after `cm`/`mm`/etc. ones would get ignored, and the alt version of miles
would be used instead.

The root of the issue is that, in `unit_find_str`, once we get a 'hit' for a unit, we check
it's actual unit (since 'm' would also hit on 'cm', 'mm', etc.). In case that hit is not a
valid unit one, we would just return NULL, breaking the cycle of checks over that unit, and
hence missing all later usages of it.

So now, in case we have an 'invalid unit hit', we immediately retry to find it within remaining string.

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

M	source/blender/blenkernel/intern/unit.c

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

diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index e0f2120..e3ea5b9 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -460,29 +460,33 @@ BLI_INLINE bool isalpha_or_utf8(const int ch)
 
 static const char *unit_find_str(const char *str, const char *substr)
 {
-	const char *str_found;
-
 	if (substr && substr[0] != '\0') {
-		str_found = strstr(str, substr);
-		if (str_found) {
-			/* previous char cannot be a letter */
-			if (str_found == str ||
-			    /* weak unicode support!, so "µm" won't match up be replaced by "m"
-			     * since non ascii utf8 values will NEVER return true */
-			    isalpha_or_utf8(*BLI_str_prev_char_utf8(str_found)) == 0)
-			{
-				/* next char cannot be alphanum */
-				int len_name = strlen(substr);
-
-				if (!isalpha_or_utf8(*(str_found + len_name))) {
-					return str_found;
+		while (true) {
+			const char *str_found = strstr(str, substr);
+
+			if (str_found) {
+				/* Previous char cannot be a letter. */
+				if (str_found == str ||
+					/* weak unicode support!, so "µm" won't match up be replaced by "m"
+					 * since non ascii utf8 values will NEVER return true */
+					isalpha_or_utf8(*BLI_str_prev_char_utf8(str_found)) == 0)
+				{
+					/* next char cannot be alphanum */
+					int len_name = strlen(substr);
+
+					if (!isalpha_or_utf8(*(str_found + len_name))) {
+						return str_found;
+					}
 				}
+				/* If str_found is not a valid unit, we have to check further in the string... */
+				str = str_found + 1;
+			}
+			else {
+				break;
 			}
 		}
-
 	}
 	return NULL;
-
 }
 
 /* Note that numbers are added within brackets




More information about the Bf-blender-cvs mailing list