X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Futf8.c;h=31e7e3b4e87999c3985845d166f75504bf437e9e;hp=42515caa6a0f8ada2689bb65441acf6000f6dfc9;hb=df84e4897abc4565fe11adead30b99d9634b41b1;hpb=ee6ab2ee3a9ee1a8c65d7272ec7fba1d886f5af0 diff --git a/src/utf8.c b/src/utf8.c index 42515ca..31e7e3b 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. */ /** @@ -18,10 +18,11 @@ #include "iconv-p.h" -size_t yaz_init_UTF8(yaz_iconv_t cd, unsigned char *inp, - size_t inbytesleft, size_t *no_read) +static size_t init_utf8(yaz_iconv_t cd, yaz_iconv_decoder_t d, + unsigned char *inp, + size_t inbytesleft, size_t *no_read) { - if (inp[0] != 0xef) + if (!inp || inp[0] != 0xef) { *no_read = 0; return 0; @@ -135,8 +136,9 @@ unsigned long yaz_read_UTF8_char(unsigned char *inp, return x; } -unsigned long yaz_read_UTF8(yaz_iconv_t cd, unsigned char *inp, - size_t inbytesleft, size_t *no_read) +static unsigned long read_utf8(yaz_iconv_t cd, yaz_iconv_decoder_t d, + unsigned char *inp, + size_t inbytesleft, size_t *no_read) { int err = 0; int r = yaz_read_UTF8_char(inp, inbytesleft, no_read, &err); @@ -227,11 +229,25 @@ yaz_iconv_encoder_t yaz_utf8_encoder(const char *tocode, return 0; } +yaz_iconv_decoder_t yaz_utf8_decoder(const char *fromcode, + yaz_iconv_decoder_t d) +{ + if (!yaz_matchstr(fromcode, "UTF8")) + { + d->init_handle = init_utf8; + d->read_handle = read_utf8; + return d; + } + return 0; +} + /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +