Towards 2.1.44. Bump copyright year.
[yaz-moved-to-github.git] / include / yaz / yaz-iconv.h
1 /*
2  * Copyright (c) 1995-2007, Index Data
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 /* $Id: yaz-iconv.h,v 1.14 2007-01-03 08:42:14 adam Exp $ */
28
29 /**
30  * \file yaz-iconv.h
31  * \brief Header for YAZ iconv interface
32  */
33
34 #ifndef YAZ_ICONV_H
35 #define YAZ_ICONV_H
36
37 #include <stddef.h>
38 #include <yaz/yconfig.h>
39
40 YAZ_BEGIN_CDECL
41
42 /** \brief yaz_iconv handle (similar to iconv_t) */
43 typedef struct yaz_iconv_struct *yaz_iconv_t;
44
45 /** \brief error code: unknown */
46 #define YAZ_ICONV_UNKNOWN 1
47 /** \brief error code: Not sufficient room for output buffer */
48 #define YAZ_ICONV_E2BIG 2
49 /** \brief error code: Invalid sequence */
50 #define YAZ_ICONV_EILSEQ 3
51 /** \brief error code: An incomplete multibyte sequence is in input buffer */
52 #define YAZ_ICONV_EINVAL 4
53
54 /** \brief just like iconv_open(3) */
55 YAZ_EXPORT yaz_iconv_t yaz_iconv_open (const char *tocode,
56                                        const char *fromcode);
57 /** \brief just like iconv(3) */
58 YAZ_EXPORT size_t yaz_iconv (yaz_iconv_t cd, char **inbuf, size_t *inbytesleft,
59                              char **outbuf, size_t *outbytesleft);
60 /** \brief returns last error - like errno for iconv(3) */
61 YAZ_EXPORT int yaz_iconv_error (yaz_iconv_t cd);
62
63 /** \brief just like iconv_close(3) */
64 YAZ_EXPORT int yaz_iconv_close (yaz_iconv_t cd);
65
66 /** \brief tests whether conversion is handled by YAZ' iconv or system iconv */
67 YAZ_EXPORT int yaz_iconv_isbuiltin(yaz_iconv_t cd);
68
69 /** \brief match strings - independent of case and '-'
70     \param s1 first string
71     \param s2 second string
72     \retval 0 strings are similar
73     \retval !=0 strings are different
74 */
75 YAZ_EXPORT int yaz_matchstr(const char *s1, const char *s2);
76
77 YAZ_EXPORT int yaz_strcmp_del(const char *a, const char *b, const char *b_del);
78
79 /** \brief decodes UTF-8 sequence
80     \param inp input buffer with UTF-8 bytes
81     \param inbytesleft length of input buffer
82     \param no_read holds number of bytes read if conversion is successful
83     \param error pointer to error code if error occurs
84     \retval 0 if error
85     \retval >0 if conversion is successful
86 */
87 YAZ_EXPORT unsigned long yaz_read_UTF8_char(unsigned char *inp,
88                                             size_t inbytesleft,
89                                             size_t *no_read,
90                                             int *error);
91
92 /** \brief encodes UTF-8 sequence 
93     \param x the UNICODE value
94     \param outbuf output buffer pointer, updated if conversion is successful
95     \param outbytesleft length of buffer, updated if conversino is successful
96     \param error pointer to error code if error occurs
97     \retval 0 if successful
98     \retval -1 for error
99 */
100 YAZ_EXPORT size_t yaz_write_UTF8_char(unsigned long x,
101                                       char **outbuf, size_t *outbytesleft,
102                                       int *error);
103
104 YAZ_END_CDECL
105
106 #endif
107 /*
108  * Local variables:
109  * c-basic-offset: 4
110  * indent-tabs-mode: nil
111  * End:
112  * vim: shiftwidth=4 tabstop=8 expandtab
113  */
114