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
Paul Sokolovsky 2014-06-14 03:16:17 +03:00
rodzic ded0fc77f7
commit 46d31e9ca9
1 zmienionych plików z 11 dodań i 0 usunięć

Wyświetl plik

@ -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;