BLI_string: add BLI_str_utf8_as_unicode_safe
Similar to BLI_str_utf8_size_safe, matches logic from other safe UTF8 decoding functions.
This commit is contained in:
@@ -55,6 +55,7 @@ int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
|
||||
*/
|
||||
unsigned int BLI_str_utf8_as_unicode_or_error(const char *p) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
unsigned int BLI_str_utf8_as_unicode_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
||||
/**
|
||||
* UTF8 decoding that steps over the index (unless an error is encountered).
|
||||
*
|
||||
|
||||
@@ -747,6 +747,15 @@ uint BLI_str_utf8_as_unicode_or_error(const char *p)
|
||||
return utf8_char_decode(p, mask, len, BLI_UTF8_ERR);
|
||||
}
|
||||
|
||||
unsigned int BLI_str_utf8_as_unicode_safe(const char *p)
|
||||
{
|
||||
const uint result = BLI_str_utf8_as_unicode_or_error(p);
|
||||
if (UNLIKELY(result == BLI_UTF8_ERR)) {
|
||||
return *p;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint BLI_str_utf8_as_unicode_step_or_error(const char *__restrict p,
|
||||
const size_t p_len,
|
||||
size_t *__restrict index)
|
||||
|
||||
Reference in New Issue
Block a user