First RPN to CQL conversion using actual attribute matching.
[yaz-moved-to-github.git] / include / yaz / yaz-iconv.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 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
28 /**
29  * \file yaz-iconv.h
30  * \brief Header for YAZ iconv interface
31  */
32
33 #ifndef YAZ_ICONV_H
34 #define YAZ_ICONV_H
35
36 #include <stddef.h>
37 #include <yaz/yconfig.h>
38
39 YAZ_BEGIN_CDECL
40
41 /** \brief yaz_iconv handle (similar to iconv_t) */
42 typedef struct yaz_iconv_struct *yaz_iconv_t;
43
44 /** \brief error code: unknown */
45 #define YAZ_ICONV_UNKNOWN 1
46 /** \brief error code: Not sufficient room for output buffer */
47 #define YAZ_ICONV_E2BIG 2
48 /** \brief error code: Invalid sequence */
49 #define YAZ_ICONV_EILSEQ 3
50 /** \brief error code: An incomplete multibyte sequence is in input buffer */
51 #define YAZ_ICONV_EINVAL 4
52
53 /** \brief just like iconv_open(3) */
54 YAZ_EXPORT yaz_iconv_t yaz_iconv_open (const char *tocode,
55                                        const char *fromcode);
56 /** \brief just like iconv(3) */
57 YAZ_EXPORT size_t yaz_iconv (yaz_iconv_t cd, char **inbuf, size_t *inbytesleft,
58                              char **outbuf, size_t *outbytesleft);
59 /** \brief returns last error - like errno for iconv(3) */
60 YAZ_EXPORT int yaz_iconv_error (yaz_iconv_t cd);
61
62 /** \brief just like iconv_close(3) */
63 YAZ_EXPORT int yaz_iconv_close (yaz_iconv_t cd);
64
65 /** \brief tests whether conversion is handled by YAZ' iconv or system iconv */
66 YAZ_EXPORT int yaz_iconv_isbuiltin(yaz_iconv_t cd);
67
68 /** \brief match strings - independent of case and '-'
69     \param s1 first string
70     \param s2 second string (May include wildcard ? and .)
71     \retval 0 strings are similar
72     \retval !=0 strings are different
73 */
74 YAZ_EXPORT int yaz_matchstr(const char *s1, const char *s2);
75
76 /** \brief match a and b with some delimitor for b
77     \param a first second
78     \param b second string
79     \param b_del delimitor for b
80     \retval 0 strings are similar
81     \retval !=0 strings are different
82 */
83 YAZ_EXPORT int yaz_strcmp_del(const char *a, const char *b, const char *b_del);
84
85
86 /** \brief compares two buffers of different size
87     \param a first buffer
88     \param b second buffer
89     \param len_a length of first buffer
90     \retval len_b length of second buffer
91     \retval 0 buffers are equal
92     \retval >0 a > b
93     \retval <0 a < b
94 */
95 int yaz_memcmp(const void *a, const void *b, size_t len_a, size_t len_b);
96
97
98 /** \brief decodes UTF-8 sequence
99     \param inp input buffer with UTF-8 bytes
100     \param inbytesleft length of input buffer
101     \param no_read holds number of bytes read if conversion is successful
102     \param error pointer to error code if error occurs
103     \retval 0 if error
104     \retval >0 if conversion is successful
105 */
106 YAZ_EXPORT unsigned long yaz_read_UTF8_char(unsigned char *inp,
107                                             size_t inbytesleft,
108                                             size_t *no_read,
109                                             int *error);
110
111 /** \brief encodes UTF-8 sequence 
112     \param x the UNICODE value
113     \param outbuf output buffer pointer, updated if conversion is successful
114     \param outbytesleft length of buffer, updated if conversino is successful
115     \param error pointer to error code if error occurs
116     \retval 0 if successful
117     \retval -1 for error
118 */
119 YAZ_EXPORT size_t yaz_write_UTF8_char(unsigned long x,
120                                       char **outbuf, size_t *outbytesleft,
121                                       int *error);
122
123 YAZ_END_CDECL
124
125 #endif
126 /*
127  * Local variables:
128  * c-basic-offset: 4
129  * indent-tabs-mode: nil
130  * End:
131  * vim: shiftwidth=4 tabstop=8 expandtab
132  */
133