1 /* Character set conversion with error handling.
2 Copyright (C) 2001-2007 Free Software Foundation, Inc.
3 Written by Bruno Haible and Simon Josefsson.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
33 /* Handling of unconvertible characters. */
34 enum iconv_ilseq_handler
36 iconveh_error, /* return and set errno = EILSEQ */
37 iconveh_question_mark, /* use one '?' per unconvertible character */
38 iconveh_escape_sequence /* use escape sequence \uxxxx or \Uxxxxxxxx */
43 /* Convert an entire string from one encoding to another, using iconv.
44 The original string is at [SRC,...,SRC+SRCLEN-1].
45 The conversion descriptor from FROMCODE to TOCODE is passed as CD.
46 CD1 is the conversion descriptor from FROM_CODESET to UTF-8 (or
47 (iconv_t)(-1) if FROM_CODESET is UTF-8).
48 CD2 is the conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1)
49 if TO_CODESET is UTF-8).
50 *RESULTP and *LENGTH 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 string is stored in *RESULTP and its length
55 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
56 unchanged if no dynamic memory allocation was necessary. */
58 mem_cd_iconveh (const char *src, size_t srclen,
59 iconv_t cd, iconv_t cd1, iconv_t cd2,
60 enum iconv_ilseq_handler handler,
61 char **resultp, size_t *lengthp);
63 /* Convert an entire string from one encoding to another, using iconv.
64 The original string is the NUL-terminated string starting at SRC.
65 The conversion descriptor is passed as CD. Both the "from" and the "to"
66 encoding must use a single NUL byte at the end of the string (i.e. not
67 UCS-2, UCS-4, UTF-16, UTF-32).
68 CD1 is the conversion descriptor from FROM_CODESET to UTF-8 (or
69 (iconv_t)(-1) if FROM_CODESET is UTF-8).
70 CD2 is the conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1)
71 if TO_CODESET is UTF-8).
72 Allocate a malloced memory block for the result.
73 Return value: the freshly allocated resulting NUL-terminated string if
74 successful, otherwise NULL and errno set. */
76 str_cd_iconveh (const char *src,
77 iconv_t cd, iconv_t cd1, iconv_t cd2,
78 enum iconv_ilseq_handler handler);
82 /* Convert an entire string from one encoding to another, using iconv.
83 The original string is at [SRC,...,SRC+SRCLEN-1].
84 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
85 or *RESULTP can initially be NULL.
86 May erase the contents of the memory at *RESULTP.
87 Return value: 0 if successful, otherwise -1 and errno set.
88 If successful: The resulting string is stored in *RESULTP and its length
89 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
90 unchanged if no dynamic memory allocation was necessary. */
92 mem_iconveh (const char *src, size_t srclen,
93 const char *from_codeset, const char *to_codeset,
94 enum iconv_ilseq_handler handler,
95 char **resultp, size_t *lengthp);
97 /* Convert an entire string from one encoding to another, using iconv.
98 The original string is the NUL-terminated string starting at SRC.
99 Both the "from" and the "to" encoding must use a single NUL byte at the
100 end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
101 Allocate a malloced memory block for the result.
102 Return value: the freshly allocated resulting NUL-terminated string if
103 successful, otherwise NULL and errno set. */
105 str_iconveh (const char *src,
106 const char *from_codeset, const char *to_codeset,
107 enum iconv_ilseq_handler handler);
115 #endif /* _STRICONVEH_H */