1 /* Conversions between Unicode and legacy encodings.
2 Copyright (C) 2002, 2005, 2007, 2009 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. */
28 /* Get uniconv_register_autodetect() declaration. */
29 #include "striconveha.h"
31 /* Get locale_charset() declaration. */
32 #include "localcharset.h"
40 /* Converts an entire string, possibly including NUL bytes, from one encoding
41 to a Unicode encoding.
42 Converts a memory region given in encoding FROMCODE. FROMCODE is as for
44 The input is in the memory region between SRC (inclusive) and SRC + SRCLEN
46 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
47 array is filled with offsets into the result, i.e. the character starting
48 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
49 and other offsets are set to (size_t)(-1).
50 *RESULTP and *LENGTHP should initially be a scratch buffer and its size,
51 or *RESULTP can initially be NULL.
52 May erase the contents of the memory at *RESULTP.
53 Return value: 0 if successful, otherwise -1 and errno set.
54 If successful: The resulting Unicode string (non-NULL) is returned and its
55 length stored in *LENGTHP. The resulting string is RESULTBUF if no dynamic
56 memory allocation was necessary, or a freshly allocated memory block
58 In case of error: NULL is returned and errno is set. Particular errno
59 values: EINVAL, EILSEQ, ENOMEM. */
61 u8_conv_from_encoding (const char *fromcode,
62 enum iconv_ilseq_handler handler,
63 const char *src, size_t srclen,
65 uint8_t *resultbuf, size_t *lengthp);
67 u16_conv_from_encoding (const char *fromcode,
68 enum iconv_ilseq_handler handler,
69 const char *src, size_t srclen,
71 uint16_t *resultbuf, size_t *lengthp);
73 u32_conv_from_encoding (const char *fromcode,
74 enum iconv_ilseq_handler handler,
75 const char *src, size_t srclen,
77 uint32_t *resultbuf, size_t *lengthp);
79 /* Converts an entire Unicode string, possibly including NUL units, from a
80 Unicode encoding to a given encoding.
81 Converts a memory region to encoding TOCODE. TOCODE is as for
83 The input is in the memory region between SRC (inclusive) and SRC + SRCLEN
85 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
86 array is filled with offsets into the result, i.e. the character starting
87 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
88 and other offsets are set to (size_t)(-1).
89 RESULTBUF and *LENGTHP should initially be a scratch buffer and its size,
90 or RESULTBUF can be NULL.
91 May erase the contents of the memory at *RESULTP.
92 If successful: The resulting string (non-NULL) is returned and its length
93 stored in *LENGTHP. The resulting string is RESULTBUF if no dynamic memory
94 allocation was necessary, or a freshly allocated memory block otherwise.
95 In case of error: NULL is returned and errno is set. Particular errno
96 values: EINVAL, EILSEQ, ENOMEM. */
98 u8_conv_to_encoding (const char *tocode,
99 enum iconv_ilseq_handler handler,
100 const uint8_t *src, size_t srclen,
102 char *resultbuf, size_t *lengthp);
104 u16_conv_to_encoding (const char *tocode,
105 enum iconv_ilseq_handler handler,
106 const uint16_t *src, size_t srclen,
108 char *resultbuf, size_t *lengthp);
110 u32_conv_to_encoding (const char *tocode,
111 enum iconv_ilseq_handler handler,
112 const uint32_t *src, size_t srclen,
114 char *resultbuf, size_t *lengthp);
116 /* Converts a NUL terminated string from a given encoding.
117 The result is malloc allocated, or NULL (with errno set) in case of error.
118 Particular errno values: EILSEQ, ENOMEM. */
120 u8_strconv_from_encoding (const char *string,
121 const char *fromcode,
122 enum iconv_ilseq_handler handler);
124 u16_strconv_from_encoding (const char *string,
125 const char *fromcode,
126 enum iconv_ilseq_handler handler);
128 u32_strconv_from_encoding (const char *string,
129 const char *fromcode,
130 enum iconv_ilseq_handler handler);
132 /* Converts a NUL terminated string to a given encoding.
133 The result is malloc allocated, or NULL (with errno set) in case of error.
134 Particular errno values: EILSEQ, ENOMEM. */
136 u8_strconv_to_encoding (const uint8_t *string,
138 enum iconv_ilseq_handler handler);
140 u16_strconv_to_encoding (const uint16_t *string,
142 enum iconv_ilseq_handler handler);
144 u32_strconv_to_encoding (const uint32_t *string,
146 enum iconv_ilseq_handler handler);
148 /* Converts a NUL terminated string from the locale encoding.
149 The result is malloc allocated, or NULL (with errno set) in case of error.
150 Particular errno values: ENOMEM. */
152 u8_strconv_from_locale (const char *string);
154 u16_strconv_from_locale (const char *string);
156 u32_strconv_from_locale (const char *string);
158 /* Converts a NUL terminated string to the locale encoding.
159 The result is malloc allocated, or NULL (with errno set) in case of error.
160 Particular errno values: ENOMEM. */
162 u8_strconv_to_locale (const uint8_t *string);
164 u16_strconv_to_locale (const uint16_t *string);
166 u32_strconv_to_locale (const uint32_t *string);
173 #endif /* _UNICONV_H */