Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-02-19 19:56:49 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-02-19 19:56:49 +0400
commitcd3b98c4faf7e4f7e54138bfbc2616aeeadc86af (patch)
treef9755f0307ab11bd3021411f716d4b38330fac52 /source
parentde26f5922022abb341b1a66b1d700ded259b9265 (diff)
step over unicode characters with autocomplete (correctly this time).
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_string_utf8.h1
-rw-r--r--source/blender/blenlib/intern/string_utf8.c16
-rw-r--r--source/blender/editors/space_text/text_autocomplete.c32
3 files changed, 39 insertions, 10 deletions
diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h
index ecbc4cb1cd4..30d5c28bf98 100644
--- a/source/blender/blenlib/BLI_string_utf8.h
+++ b/source/blender/blenlib/BLI_string_utf8.h
@@ -41,6 +41,7 @@ int BLI_str_utf8_size_safe(const char *p);
/* 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);
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index 9e0f9197ca3..d802ad53e6a 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -433,6 +433,22 @@ unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *
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)
diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c
index 94977fc5f0f..0c16208c2a7 100644
--- a/source/blender/editors/space_text/text_autocomplete.c
+++ b/source/blender/editors/space_text/text_autocomplete.c
@@ -162,23 +162,29 @@ static GHash *text_autocomplete_build(Text *text)
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 @@ static GHash *text_autocomplete_build(Text *text)
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++;
+ }
}
}