diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-02-19 19:56:49 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-02-19 19:56:49 +0400 |
commit | cd3b98c4faf7e4f7e54138bfbc2616aeeadc86af (patch) | |
tree | f9755f0307ab11bd3021411f716d4b38330fac52 /source/blender/blenlib | |
parent | de26f5922022abb341b1a66b1d700ded259b9265 (diff) |
step over unicode characters with autocomplete (correctly this time).
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_string_utf8.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_utf8.c | 16 |
2 files changed, 17 insertions, 0 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) |