X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Futf8.c;h=038b744a8b092fa8baf08f3da71c7394b8a7825b;hp=d6d63f900ff74612d5df863c2a74ddd5490d11c1;hb=77c5a4fca8b516fd39b8ba213daed17a465a6b2a;hpb=379504a233e3e2cc85bca1e7b6d864f1395aec7c diff --git a/src/utf8.c b/src/utf8.c index d6d63f9..038b744 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2009 Index Data + * Copyright (C) 1995-2012 Index Data * See the file LICENSE for details. */ /** @@ -14,7 +14,6 @@ #include #include #include -#include #include "iconv-p.h" @@ -240,7 +239,25 @@ yaz_iconv_decoder_t yaz_utf8_decoder(const char *fromcode, } return 0; } - + +int yaz_utf8_check(const char *str) +{ + /* cast OK: yaz_read_UTF8_char is read-only */ + unsigned char *inp = (unsigned char *) str; + size_t inbytesleft = strlen(str); + + while (inbytesleft) + { + int error = 0; + size_t no_read; + yaz_read_UTF8_char(inp, inbytesleft, &no_read, &error); + if (error) + return 0; + inp += no_read; + inbytesleft -= no_read; + } + return 1; +} /* * Local variables: