1 /* Conversions between Unicode and legacy encodings.
2 Copyright (C) 2002, 2005, 2007 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 Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 /* Get enum iconv_ilseq_handler. */
28 #include "striconveh.h"
30 /* Get iconv_register_autodetect(), mem_iconveha() declaration. */
31 #include "striconveha.h"
33 /* Get locale_charset() declaration. */
34 #include "localcharset.h"
42 /* Converts an entire string, possibly including NUL bytes, from one encoding
43 to a Unicode encoding.
44 Converts a memory region given in encoding FROMCODE. FROMCODE is as for
46 The input is in the memory region between SRC (inclusive) and SRC + SRCLEN
48 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
49 array is filled with offsets into the result, i.e. the character starting
50 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
51 and other offsets are set to (size_t)(-1).
52 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
53 or *RESULTP can initially be NULL.
54 May erase the contents of the memory at *RESULTP.
55 Return value: 0 if successful, otherwise -1 and errno set.
56 If successful: The resulting string is stored in *RESULTP and its length
57 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
58 unchanged if no dynamic memory allocation was necessary.
59 Particular errno 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 **resultp, 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 **resultp, 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 **resultp, 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 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
90 or *RESULTP can initially be NULL.
91 May erase the contents of the memory at *RESULTP.
92 Return value: 0 if successful, otherwise -1 and errno set.
93 If successful: The resulting string is stored in *RESULTP and its length
94 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
95 unchanged if no dynamic memory allocation was necessary.
96 Particular errno 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 **resultp, 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 **resultp, 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 **resultp, 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 */