Imported Upstream version 0.9.4
[platform/upstream/libunistring.git] / lib / uniconv.h
1 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2 /* Conversions between Unicode and legacy encodings.
3    Copyright (C) 2002, 2005, 2007, 2009-2014 Free Software Foundation, Inc.
4
5    This program is free software: you can redistribute it and/or modify it
6    under the terms of the GNU Lesser General Public License as published
7    by the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #ifndef _UNICONV_H
19 #define _UNICONV_H
20
21 /* Get size_t.  */
22 #include <stddef.h>
23
24 #include "unitypes.h"
25
26 /* Get enum iconv_ilseq_handler.  */
27 #include <unistring/iconveh.h>
28
29 /* Get locale_charset() declaration.  */
30 #include <unistring/localcharset.h>
31
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37
38 /* Converts an entire string, possibly including NUL bytes, from one encoding
39    to a Unicode encoding.
40    Converts a memory region given in encoding FROMCODE.  FROMCODE is as for
41    iconv_open(3).
42    The input is in the memory region between SRC (inclusive) and SRC + SRCLEN
43    (exclusive).
44    If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
45    array is filled with offsets into the result, i.e. the character starting
46    at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
47    and other offsets are set to (size_t)(-1).
48    RESULTBUF and *LENGTHP should initially be a scratch buffer and its size,
49    or *RESULTBUF can be NULL.
50    May erase the contents of the memory at RESULTBUF.
51    If successful: The resulting Unicode string (non-NULL) is returned and its
52    length stored in *LENGTHP.  The resulting string is RESULTBUF if no dynamic
53    memory allocation was necessary, or a freshly allocated memory block
54    otherwise.
55    In case of error: NULL is returned and errno is set.  Particular errno
56    values: EINVAL, EILSEQ, ENOMEM.  */
57 extern uint8_t *
58        u8_conv_from_encoding (const char *fromcode,
59                               enum iconv_ilseq_handler handler,
60                               const char *src, size_t srclen,
61                               size_t *offsets,
62                               uint8_t *resultbuf, size_t *lengthp);
63 extern uint16_t *
64        u16_conv_from_encoding (const char *fromcode,
65                                enum iconv_ilseq_handler handler,
66                                const char *src, size_t srclen,
67                                size_t *offsets,
68                                uint16_t *resultbuf, size_t *lengthp);
69 extern uint32_t *
70        u32_conv_from_encoding (const char *fromcode,
71                                enum iconv_ilseq_handler handler,
72                                const char *src, size_t srclen,
73                                size_t *offsets,
74                                uint32_t *resultbuf, size_t *lengthp);
75
76 /* Converts an entire Unicode string, possibly including NUL units, from a
77    Unicode encoding to a given encoding.
78    Converts a memory region to encoding TOCODE.  TOCODE is as for
79    iconv_open(3).
80    The input is in the memory region between SRC (inclusive) and SRC + SRCLEN
81    (exclusive).
82    If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
83    array is filled with offsets into the result, i.e. the character starting
84    at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
85    and other offsets are set to (size_t)(-1).
86    RESULTBUF and *LENGTHP should initially be a scratch buffer and its size,
87    or RESULTBUF can be NULL.
88    May erase the contents of the memory at RESULTBUF.
89    If successful: The resulting string (non-NULL) is returned and its length
90    stored in *LENGTHP.  The resulting string is RESULTBUF if no dynamic memory
91    allocation was necessary, or a freshly allocated memory block otherwise.
92    In case of error: NULL is returned and errno is set.  Particular errno
93    values: EINVAL, EILSEQ, ENOMEM.  */
94 extern char *
95        u8_conv_to_encoding (const char *tocode,
96                             enum iconv_ilseq_handler handler,
97                             const uint8_t *src, size_t srclen,
98                             size_t *offsets,
99                             char *resultbuf, size_t *lengthp);
100 extern char *
101        u16_conv_to_encoding (const char *tocode,
102                              enum iconv_ilseq_handler handler,
103                              const uint16_t *src, size_t srclen,
104                              size_t *offsets,
105                              char *resultbuf, size_t *lengthp);
106 extern char *
107        u32_conv_to_encoding (const char *tocode,
108                              enum iconv_ilseq_handler handler,
109                              const uint32_t *src, size_t srclen,
110                              size_t *offsets,
111                              char *resultbuf, size_t *lengthp);
112
113 /* Converts a NUL terminated string from a given encoding.
114    The result is malloc allocated, or NULL (with errno set) in case of error.
115    Particular errno values: EILSEQ, ENOMEM.  */
116 extern uint8_t *
117        u8_strconv_from_encoding (const char *string,
118                                  const char *fromcode,
119                                  enum iconv_ilseq_handler handler);
120 extern uint16_t *
121        u16_strconv_from_encoding (const char *string,
122                                   const char *fromcode,
123                                   enum iconv_ilseq_handler handler);
124 extern uint32_t *
125        u32_strconv_from_encoding (const char *string,
126                                   const char *fromcode,
127                                   enum iconv_ilseq_handler handler);
128
129 /* Converts a NUL terminated string to a given encoding.
130    The result is malloc allocated, or NULL (with errno set) in case of error.
131    Particular errno values: EILSEQ, ENOMEM.  */
132 extern char *
133        u8_strconv_to_encoding (const uint8_t *string,
134                                const char *tocode,
135                                enum iconv_ilseq_handler handler);
136 extern char *
137        u16_strconv_to_encoding (const uint16_t *string,
138                                 const char *tocode,
139                                 enum iconv_ilseq_handler handler);
140 extern char *
141        u32_strconv_to_encoding (const uint32_t *string,
142                                 const char *tocode,
143                                 enum iconv_ilseq_handler handler);
144
145 /* Converts a NUL terminated string from the locale encoding.
146    The result is malloc allocated, or NULL (with errno set) in case of error.
147    Particular errno values: ENOMEM.  */
148 extern uint8_t *
149        u8_strconv_from_locale (const char *string);
150 extern uint16_t *
151        u16_strconv_from_locale (const char *string);
152 extern uint32_t *
153        u32_strconv_from_locale (const char *string);
154
155 /* Converts a NUL terminated string to the locale encoding.
156    The result is malloc allocated, or NULL (with errno set) in case of error.
157    Particular errno values: ENOMEM.  */
158 extern char *
159        u8_strconv_to_locale (const uint8_t *string);
160 extern char *
161        u16_strconv_to_locale (const uint16_t *string);
162 extern char *
163        u32_strconv_to_locale (const uint32_t *string);
164
165
166 #ifdef __cplusplus
167 }
168 #endif
169
170 #endif /* _UNICONV_H */