X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Futf8.c;h=7e294d4c0ba1f0f54fc684edd7dae683ba3efcde;hp=b895dd9bd19aef6dac33d2fdb8db5c56513e7e1c;hb=896b145fa7a02199bfc3e8aa824c018b9d7cbf98;hpb=2788a4851b551e1a3efb320a2878b809f2d8a9d7 diff --git a/src/utf8.c b/src/utf8.c index b895dd9..7e294d4 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-2011 Index Data * See the file LICENSE for details. */ /** @@ -14,7 +14,6 @@ #include #include #include -#include #include "iconv-p.h" @@ -240,12 +239,32 @@ 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: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +