[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54672] trunk/blender/source/blender: step over unicode characters with autocomplete (correctly this time).

Campbell Barton ideasman42 at gmail.com
Tue Feb 19 16:56:50 CET 2013


Revision: 54672
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54672
Author:   campbellbarton
Date:     2013-02-19 15:56:49 +0000 (Tue, 19 Feb 2013)
Log Message:
-----------
step over unicode characters with autocomplete (correctly this time).

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_string_utf8.h
    trunk/blender/source/blender/blenlib/intern/string_utf8.c
    trunk/blender/source/blender/editors/space_text/text_autocomplete.c

Modified: trunk/blender/source/blender/blenlib/BLI_string_utf8.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string_utf8.h	2013-02-19 15:47:30 UTC (rev 54671)
+++ trunk/blender/source/blender/blenlib/BLI_string_utf8.h	2013-02-19 15:56:49 UTC (rev 54672)
@@ -41,6 +41,7 @@
 /* copied from glib */
 unsigned int BLI_str_utf8_as_unicode(const char *p);
 unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index);
+unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index);
 unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index);
 size_t       BLI_str_utf8_from_unicode(unsigned int c, char *outbuf);
 

Modified: trunk/blender/source/blender/blenlib/intern/string_utf8.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string_utf8.c	2013-02-19 15:47:30 UTC (rev 54671)
+++ trunk/blender/source/blender/blenlib/intern/string_utf8.c	2013-02-19 15:56:49 UTC (rev 54672)
@@ -433,6 +433,22 @@
 	return result;
 }
 
+unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index)
+{
+	int i, mask = 0, len;
+	unsigned int result;
+	const unsigned char c = (unsigned char) *p;
+
+	UTF8_COMPUTE (c, mask, len, -1);
+	if (len == -1) {
+		*index += 1;
+		return c;
+	}
+	UTF8_GET (result, p, i, mask, len, BLI_UTF8_ERR);
+	*index += len;
+	return result;
+}
+
 /* another variant that steps over the index,
  * note, currently this also falls back to latin1 for text drawing. */
 unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index)

Modified: trunk/blender/source/blender/editors/space_text/text_autocomplete.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_autocomplete.c	2013-02-19 15:47:30 UTC (rev 54671)
+++ trunk/blender/source/blender/editors/space_text/text_autocomplete.c	2013-02-19 15:56:49 UTC (rev 54672)
@@ -162,23 +162,29 @@
 		gh = BLI_ghash_str_new(__func__);
 
 		for (linep = text->lines.first; linep; linep = linep->next) {
-			int i_start = 0;
-			int i_end = 0;
+			size_t i_start = 0;
+			size_t i_end = 0;
+			size_t i_pos = 0;
 
 			while (i_start < linep->len) {
 				/* seek identifier beginning */
-				while (i_start < linep->len && !text_check_identifier_nodigit(linep->line[i_start])) {
-					i_start++;
+				i_pos = i_start;
+				while ((i_start < linep->len) &&
+				       (!text_check_identifier_nodigit(BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_start], &i_pos))))
+				{
+					i_start = i_pos;
 				}
-				i_end = i_start;
-				while (i_end < linep->len && text_check_identifier(linep->line[i_end])) {
-					i_end++;
+				i_pos = i_end = i_start;
+				while ((i_end < linep->len) &&
+				       (text_check_identifier(BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_end], &i_pos))))
+				{
+					i_end = i_pos;
 				}
 
 				if ((i_start != i_end) &&
 				    /* check we're at the beginning of a line or that the previous char is not an identifier
-					 * this prevents digits from being added */
-				    ((i_start < 1) || !text_check_identifier(linep->line[i_start - 1])))
+				     * this prevents digits from being added */
+				    ((i_start < 1) || !text_check_identifier(BLI_str_utf8_as_unicode(&linep->line[i_start - 1]))))
 				{
 					char *str_sub = &linep->line[i_start];
 					const int choice_len = i_end - i_start;
@@ -197,7 +203,13 @@
 						str_sub[choice_len] = str_sub_last;
 					}
 				}
-				i_start = i_end;
+				if (i_end != i_start) {
+					i_start = i_end;
+				}
+				else {
+					/* highly unlikely, but prevent eternal loop */
+					i_start++;
+				}
 			}
 		}
 




More information about the Bf-blender-cvs mailing list