From: Adam Dickmeiss Date: Thu, 24 Aug 2006 10:01:03 +0000 (+0000) Subject: Make a public function, yaz_write_UTF8_char, to encode a UTF-8 sequence. X-Git-Tag: YAZ.2.1.28~31 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=2e40cc0b39b9e96695e70316c677f035f7bfd52e;p=yaz-moved-to-github.git Make a public function, yaz_write_UTF8_char, to encode a UTF-8 sequence. --- diff --git a/include/yaz/yaz-iconv.h b/include/yaz/yaz-iconv.h index 599f8ad..83ccfff 100644 --- a/include/yaz/yaz-iconv.h +++ b/include/yaz/yaz-iconv.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: yaz-iconv.h,v 1.10 2006-08-04 14:35:39 adam Exp $ + * $Id: yaz-iconv.h,v 1.11 2006-08-24 10:01:03 adam Exp $ */ /** * \file yaz-iconv.h @@ -69,11 +69,31 @@ YAZ_EXPORT int yaz_matchstr(const char *s1, const char *s2); YAZ_EXPORT int yaz_strcmp_del(const char *a, const char *b, const char *b_del); +/** \brief decodes UTF-8 sequence + \param inp input buffer with UTF-8 bytes + \param inbytesleft length of input buffer + \param no_read holds number of bytes read if conversion is successful + \param error pointer to error code if error occurs + \retval 0 if error + \retval >0 if conversion is successful +*/ YAZ_EXPORT unsigned long yaz_read_UTF8_char(unsigned char *inp, size_t inbytesleft, size_t *no_read, int *error); +/** \brief encodes UTF-8 sequence + \param x the UNICODE value + \param outbuf output buffer pointer, updated if conversion is successful + \param outbytesleft length of buffer, updated if conversino is successful + \param error pointer to error code if error occurs + \retval 0 if successful + \retval -1 for error +*/ +YAZ_EXPORT size_t yaz_write_UTF8_char(unsigned long x, + char **outbuf, size_t *outbytesleft, + int *error); + YAZ_END_CDECL #endif diff --git a/src/siconv.c b/src/siconv.c index ba54b16..0034006 100644 --- a/src/siconv.c +++ b/src/siconv.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: siconv.c,v 1.24 2006-08-04 14:35:40 adam Exp $ + * $Id: siconv.c,v 1.25 2006-08-24 10:01:03 adam Exp $ */ /** * \file siconv.c @@ -492,9 +492,16 @@ static unsigned long yaz_read_marc8_comb(yaz_iconv_t cd, unsigned char *inp, } } -static size_t yaz_write_UTF8 (yaz_iconv_t cd, unsigned long x, - char **outbuf, size_t *outbytesleft, - int last) +static size_t yaz_write_UTF8(yaz_iconv_t cd, unsigned long x, + char **outbuf, size_t *outbytesleft, + int last) +{ + return yaz_write_UTF8_char(x, outbuf, outbytesleft, &cd->my_errno); +} + +size_t yaz_write_UTF8_char(unsigned long x, + char **outbuf, size_t *outbytesleft, + int *error) { unsigned char *outp = (unsigned char *) *outbuf; @@ -545,7 +552,7 @@ static size_t yaz_write_UTF8 (yaz_iconv_t cd, unsigned long x, } else { - cd->my_errno = YAZ_ICONV_E2BIG; /* not room for output */ + *error = YAZ_ICONV_E2BIG; /* not room for output */ return (size_t)(-1); } *outbuf = (char *) outp;