unicode: Add utf8_ptr_to_index().
Useful when we have pointer to char inside string, but need to return char index. (E.g. str.find()).
This commit is contained in:
parent
ded0fc77f7
commit
46d31e9ca9
11
py/unicode.c
11
py/unicode.c
@ -86,6 +86,17 @@ char *utf8_next_char(const char *s) {
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) {
|
||||
machine_uint_t i = 0;
|
||||
while (ptr > s) {
|
||||
if (!UTF8_IS_CONT(*--ptr)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
uint unichar_charlen(const char *str, uint len)
|
||||
{
|
||||
uint charlen = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user