X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=utf8%2Futf8.c;h=6c5f5be81745c05b93e73e0b7b6023c069de57d0;hb=96dfbdbed170533839ea6848d6c03d36bf3f1947;hp=ae7cc4a5b66ab321c267cbc8bfbeab80d4374e01;hpb=37664554e3b02ffcc14d648844fe2ec95c0cf753;p=gedcom-parse.git diff --git a/utf8/utf8.c b/utf8/utf8.c index ae7cc4a..6c5f5be 100644 --- a/utf8/utf8.c +++ b/utf8/utf8.c @@ -1,15 +1,27 @@ /* Utility functions for UTF-8 Copyright (C) 2001, 2002 Peter Verthez - Permission granted to do anything with this file that you want, as long - as the above copyright is retained in all copies. - THERE IS NO WARRANTY - USE AT YOUR OWN RISK + The UTF8 tools library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The Gedcom parser library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Gedcom parser library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ /* $Id$ */ /* $Name$ */ #include "utf8tools.h" +#include int is_utf8_string(const char* str) { @@ -67,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; +}