Factorize the test of the start of an UTF8 code point
in a separate function
This commit is contained in:
1 parent
abec9c37fa
commit
aefbc5b2f5
1 file changed
+8
-1
+8
-1
@@ -1646,6 +1646,13 @@ m_str1ng_utf8_valid_str_p(const char str[])
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Test if the given character is the start of an UTF8 code point */
|
||||
static inline bool
|
||||
m_str1ng_utf8_start_p(unsigned char val)
|
||||
{
|
||||
return ((val & 0xC0u) != 0x80u);
|
||||
}
|
||||
|
||||
/* Computer the number of unicode characters are represented in the UTF8 stream
|
||||
*/
|
||||
static inline size_t
|
||||
@@ -1654,7 +1661,7 @@ m_str1ng_utf8_length(const char str[])
|
||||
size_t size = 0;
|
||||
while (*str) {
|
||||
unsigned char val = (unsigned char) *str++;
|
||||
size += ((val & 0xC0u) != 0x80u);
|
||||
size += m_str1ng_utf8_start_p(val);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user