kopia lustrzana https://github.com/micropython/micropython
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()).pull/695/head
rodzic
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;
|
||||
|
|
Ładowanie…
Reference in New Issue