record_conv: change construct prototype
[yaz-moved-to-github.git] / include / yaz / yaz-iconv.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2012 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 YAZ_EXPORT unsigned long yaz_read_UTF8_char(unsigned char *inp,
69                                             size_t inbytesleft,
70                                             size_t *no_read,
71                                             int *error);
72
73 /** \brief encodes UTF-8 sequence 
74     \param x the UNICODE value
75     \param outbuf output buffer pointer, updated if conversion is successful
76     \param outbytesleft length of buffer, updated if conversino is successful
77     \param error pointer to error code if error occurs
78     \retval 0 if successful
79     \retval -1 for error
80 */
81 YAZ_EXPORT size_t yaz_write_UTF8_char(unsigned long x,
82                                       char **outbuf, size_t *outbytesleft,
83                                       int *error);
84
85 /* ctype.h macros ASCII based. That do not depend on LANG, nor require
86    unsigned int as argument */
87 #define yaz_isdigit(x) ((x) >= '0' && (x) <= '9')
88 #define yaz_isspace(x) strchr(" \f\r\n\t\v", x)
89 #define yaz_toupper(x) ((x) + ('A' - 'a'))
90 #define yaz_isupper(x) ((x) >= 'A' && (x) <= 'Z')
91 #define yaz_tolower(x) ((x) + ('a' - 'A'))
92 #define yaz_islower(x) ((x) >= 'a' && (x) <= 'z')
93
94 /** \brief check whether string apppers to be UTF-8 encoded
95     \param cstr string to check
96     \retval 1 OK (appears to be UTF-8)
97     \retval 0 definitely not UTF-8
98 */
99 YAZ_EXPORT int yaz_utf8_check(const char *cstr);
100
101 YAZ_END_CDECL
102
103 #endif
104 /*
105  * Local variables:
106  * c-basic-offset: 4
107  * c-file-style: "Stroustrup"
108  * indent-tabs-mode: nil
109  * End:
110  * vim: shiftwidth=4 tabstop=8 expandtab
111  */
112