1 /* Conversions between Unicode and legacy encodings.
2 Copyright (C) 2002, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 /* Get enum iconv_ilseq_handler. */
26 #include <unistring/iconveh.h>
28 /* Get locale_charset() declaration. */
29 #include <unistring/localcharset.h>
37 /* Converts an entire string, possibly including NUL bytes, from one encoding
38 to a Unicode encoding.
39 Converts a memory region given in encoding FROMCODE. FROMCODE is as for
41 The input is in the memory region between SRC (inclusive) and SRC + SRCLEN
43 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
44 array is filled with offsets into the result, i.e. the character starting
45 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
46 and other offsets are set to (size_t)(-1).
47 RESULTBUF and *LENGTHP should initially be a scratch buffer and its size,
48 or *RESULTBUF can be NULL.
49 May erase the contents of the memory at RESULTBUF.
50 If successful: The resulting Unicode string (non-NULL) is returned and its
51 length stored in *LENGTHP. The resulting string is RESULTBUF if no dynamic
52 memory allocation was necessary, or a freshly allocated memory block
54 In case of error: NULL is returned and errno is set. Particular errno
55 values: EINVAL, EILSEQ, ENOMEM. */
57 u8_conv_from_encoding (const char *fromcode,
58 enum iconv_ilseq_handler handler,
59 const char *src, size_t srclen,
61 uint8_t *resultbuf, size_t *lengthp);
63 u16_conv_from_encoding (const char *fromcode,
64 enum iconv_ilseq_handler handler,
65 const char *src, size_t srclen,
67 uint16_t *resultbuf, size_t *lengthp);
69 u32_conv_from_encoding (const char *fromcode,
70 enum iconv_ilseq_handler handler,
71 const char *src, size_t srclen,
73 uint32_t *resultbuf, size_t *lengthp);
75 /* Converts an entire Unicode string, possibly including NUL units, from a
76 Unicode encoding to a given encoding.
77 Converts a memory region to encoding TOCODE. TOCODE is as for
79 The input is in the memory region between SRC (inclusive) and SRC + SRCLEN
81 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
82 array is filled with offsets into the result, i.e. the character starting
83 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
84 and other offsets are set to (size_t)(-1).
85 RESULTBUF and *LENGTHP should initially be a scratch buffer and its size,
86 or RESULTBUF can be NULL.
87 May erase the contents of the memory at RESULTBUF.
88 If successful: The resulting string (non-NULL) is returned and its length
89 stored in *LENGTHP. The resulting string is RESULTBUF if no dynamic memory
90 allocation was necessary, or a freshly allocated memory block otherwise.
91 In case of error: NULL is returned and errno is set. Particular errno
92 values: EINVAL, EILSEQ, ENOMEM. */
94 u8_conv_to_encoding (const char *tocode,
95 enum iconv_ilseq_handler handler,
96 const uint8_t *src, size_t srclen,
98 char *resultbuf, size_t *lengthp);
100 u16_conv_to_encoding (const char *tocode,
101 enum iconv_ilseq_handler handler,
102 const uint16_t *src, size_t srclen,
104 char *resultbuf, size_t *lengthp);
106 u32_conv_to_encoding (const char *tocode,
107 enum iconv_ilseq_handler handler,
108 const uint32_t *src, size_t srclen,
110 char *resultbuf, size_t *lengthp);
112 /* Converts a NUL terminated string from a given encoding.
113 The result is malloc allocated, or NULL (with errno set) in case of error.
114 Particular errno values: EILSEQ, ENOMEM. */
116 u8_strconv_from_encoding (const char *string,
117 const char *fromcode,
118 enum iconv_ilseq_handler handler);
120 u16_strconv_from_encoding (const char *string,
121 const char *fromcode,
122 enum iconv_ilseq_handler handler);
124 u32_strconv_from_encoding (const char *string,
125 const char *fromcode,
126 enum iconv_ilseq_handler handler);
128 /* Converts a NUL terminated string to a given encoding.
129 The result is malloc allocated, or NULL (with errno set) in case of error.
130 Particular errno values: EILSEQ, ENOMEM. */
132 u8_strconv_to_encoding (const uint8_t *string,
134 enum iconv_ilseq_handler handler);
136 u16_strconv_to_encoding (const uint16_t *string,
138 enum iconv_ilseq_handler handler);
140 u32_strconv_to_encoding (const uint32_t *string,
142 enum iconv_ilseq_handler handler);
144 /* Converts a NUL terminated string from the locale encoding.
145 The result is malloc allocated, or NULL (with errno set) in case of error.
146 Particular errno values: ENOMEM. */
148 u8_strconv_from_locale (const char *string);
150 u16_strconv_from_locale (const char *string);
152 u32_strconv_from_locale (const char *string);
154 /* Converts a NUL terminated string to the locale encoding.
155 The result is malloc allocated, or NULL (with errno set) in case of error.
156 Particular errno values: ENOMEM. */
158 u8_strconv_to_locale (const uint8_t *string);
160 u16_strconv_to_locale (const uint16_t *string);
162 u32_strconv_to_locale (const uint32_t *string);
169 #endif /* _UNICONV_H */