From be906f44c6bb51eb492ecb90dbc1e8e0bc01d1ec Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Aug 2021 15:18:57 +1000 Subject: BLI_string_utf8: simplify utf8 stepping logic There were multiple utf8 functions which treated errors slightly differently. Split BLI_str_utf8_as_unicode_step into two functions. - BLI_str_utf8_as_unicode_step_or_error returns error value when decoding fails and doesn't step. - BLI_str_utf8_as_unicode_step always steps forward at least one returning the byte value without decoding (needed to display some latin1 file-paths). Font drawing uses BLI_str_utf8_as_unicode_step and no longer check for error values. --- source/blender/blenfont/intern/blf_font.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 5ad48aa08d4..426008c9395 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -309,15 +309,13 @@ BLI_INLINE GlyphBLF *blf_utf8_next_fast( } (*i_p)++; } - else if ((*r_c = BLI_str_utf8_as_unicode_step(str, str_len, i_p)) != BLI_UTF8_ERR) { + else { + *r_c = BLI_str_utf8_as_unicode_step(str, str_len, i_p); g = blf_glyph_search(gc, *r_c); if (UNLIKELY(g == NULL)) { g = blf_glyph_add(font, gc, FT_Get_Char_Index(font->face, *r_c), *r_c); } } - else { - g = NULL; - } return g; } @@ -1202,7 +1200,8 @@ int blf_font_count_missing_chars(FontBLF *font, if ((c = str[i]) < GLYPH_ASCII_TABLE_SIZE) { i++; } - else if ((c = BLI_str_utf8_as_unicode_step(str, str_len, &i)) != BLI_UTF8_ERR) { + else { + c = BLI_str_utf8_as_unicode_step(str, str_len, &i); if (FT_Get_Char_Index((font)->face, c) == 0) { missing++; } -- cgit v1.2.3