[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45497] trunk/blender/source/blender/ blenkernel/intern/unit.c: fix for unit system incorrectly replacint 'um' ( unicode 'u').

Campbell Barton ideasman42 at gmail.com
Tue Apr 10 04:51:25 CEST 2012


Revision: 45497
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45497
Author:   campbellbarton
Date:     2012-04-10 02:51:24 +0000 (Tue, 10 Apr 2012)
Log Message:
-----------
fix for unit system incorrectly replacint 'um' (unicode 'u'). with meters.

result was editing number buttons with um would give a python error.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/unit.c

Modified: trunk/blender/source/blender/blenkernel/intern/unit.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/unit.c	2012-04-10 01:45:22 UTC (rev 45496)
+++ trunk/blender/source/blender/blenkernel/intern/unit.c	2012-04-10 02:51:24 UTC (rev 45497)
@@ -33,6 +33,7 @@
 
 #include "BLI_math.h"
 #include "BLI_string.h"
+#include "BLI_string_utf8.h"
 #include "BLI_winstuff.h"
 
 #define TEMP_STR_SIZE 256
@@ -418,6 +419,11 @@
 	unit_as_string(str, len_max, value, prec, usys, NULL, pad ? ' ' : '\0');
 }
 
+BLI_INLINE int isalpha_or_utf8(const int ch)
+{
+	return (ch >= 128 || isalpha(ch));
+}
+
 static const char *unit_find_str(const char *str, const char *substr)
 {
 	const char *str_found;
@@ -426,11 +432,15 @@
 		str_found = strstr(str, substr);
 		if (str_found) {
 			/* previous char cannot be a letter */
-			if (str_found == str || isalpha(*(str_found-1)) == 0) {
+			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(*(str_found+len_name))) {
+				if (!isalpha_or_utf8(*(str_found + len_name))) {
 					return str_found;
 				}
 			}




More information about the Bf-blender-cvs mailing list