step over unicode characters with autocomplete (correctly this time).
This commit is contained in:
@@ -41,6 +41,7 @@ int BLI_str_utf8_size_safe(const char *p);
|
|||||||
/* copied from glib */
|
/* copied from glib */
|
||||||
unsigned int BLI_str_utf8_as_unicode(const char *p);
|
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(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);
|
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);
|
size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf);
|
||||||
|
|
||||||
|
@@ -433,6 +433,22 @@ unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *
|
|||||||
return result;
|
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,
|
/* another variant that steps over the index,
|
||||||
* note, currently this also falls back to latin1 for text drawing. */
|
* 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)
|
unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index)
|
||||||
|
@@ -162,23 +162,29 @@ static GHash *text_autocomplete_build(Text *text)
|
|||||||
gh = BLI_ghash_str_new(__func__);
|
gh = BLI_ghash_str_new(__func__);
|
||||||
|
|
||||||
for (linep = text->lines.first; linep; linep = linep->next) {
|
for (linep = text->lines.first; linep; linep = linep->next) {
|
||||||
int i_start = 0;
|
size_t i_start = 0;
|
||||||
int i_end = 0;
|
size_t i_end = 0;
|
||||||
|
size_t i_pos = 0;
|
||||||
|
|
||||||
while (i_start < linep->len) {
|
while (i_start < linep->len) {
|
||||||
/* seek identifier beginning */
|
/* seek identifier beginning */
|
||||||
while (i_start < linep->len && !text_check_identifier_nodigit(linep->line[i_start])) {
|
i_pos = i_start;
|
||||||
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;
|
i_pos = i_end = i_start;
|
||||||
while (i_end < linep->len && text_check_identifier(linep->line[i_end])) {
|
while ((i_end < linep->len) &&
|
||||||
i_end++;
|
(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) &&
|
if ((i_start != i_end) &&
|
||||||
/* check we're at the beginning of a line or that the previous char is not an identifier
|
/* check we're at the beginning of a line or that the previous char is not an identifier
|
||||||
* this prevents digits from being added */
|
* this prevents digits from being added */
|
||||||
((i_start < 1) || !text_check_identifier(linep->line[i_start - 1])))
|
((i_start < 1) || !text_check_identifier(BLI_str_utf8_as_unicode(&linep->line[i_start - 1]))))
|
||||||
{
|
{
|
||||||
char *str_sub = &linep->line[i_start];
|
char *str_sub = &linep->line[i_start];
|
||||||
const int choice_len = i_end - 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;
|
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++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user