X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=utf8%2Futf8.c;h=6c5f5be81745c05b93e73e0b7b6023c069de57d0;hb=ea81accae13a4617cc46f5256dad50e2732cc206;hp=e3809b99dc7cc0f917d7980828de0c1337d39dfe;hpb=18ff02c2f0dff12904dbd2dc4d6c40ef3ad4a6d2;p=gedcom-parse.git diff --git a/utf8/utf8.c b/utf8/utf8.c index e3809b9..6c5f5be 100644 --- a/utf8/utf8.c +++ b/utf8/utf8.c @@ -21,6 +21,7 @@ /* $Name$ */ #include "utf8tools.h" +#include int is_utf8_string(const char* str) { @@ -78,11 +79,37 @@ int utf8_strlen(const char* str) if (!str) return 0; while (*str) { - if ((*str & 0x80) == 0 || (*str & 0xC0) == 0xC0) - num_char++; + if ((*str & 0xC0) != 0xC0) num_char++; str++; } return num_char; } +char* next_utf8_char(char* str) +{ + if (!str) return NULL; + + if (*str) { + str++; + while (*str && (*str & 0xC0) == 0x80) + str++; + } + return str; +} + +char* nth_utf8_char(char* str, int n) +{ + int num_char = 0; + if (!str) return NULL; + + if (*str) { + str++; + while (*str) { + if ((*str & 0xC0) != 0x80) num_char++; + if (num_char == n) break; + str++; + } + } + return str; +}