Commit | Line | Data |
---|---|---|
24d56127 LC |
1 | /* Character set conversion with error handling. |
2 | Copyright (C) 2001-2007, 2009 Free Software Foundation, Inc. | |
3 | Written by Bruno Haible and Simon Josefsson. | |
4 | ||
5 | This program is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser General Public License as published by | |
7 | 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 | |
13 | GNU 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 _STRICONVEH_H | |
19 | #define _STRICONVEH_H | |
20 | ||
21 | #include <stddef.h> | |
22 | #if HAVE_ICONV | |
23 | #include <iconv.h> | |
24 | #endif | |
25 | ||
26 | #include "iconveh.h" | |
27 | ||
28 | ||
29 | #ifdef __cplusplus | |
30 | extern "C" { | |
31 | #endif | |
32 | ||
33 | ||
34 | #if HAVE_ICONV | |
35 | ||
36 | /* Convert an entire string from one encoding to another, using iconv. | |
37 | The original string is at [SRC,...,SRC+SRCLEN-1]. | |
38 | CD is the conversion descriptor from FROMCODE to TOCODE, or (iconv_t)(-1) if | |
39 | the system does not support a direct conversion from FROMCODE to TOCODE. | |
40 | CD1 is the conversion descriptor from FROM_CODESET to UTF-8 (or | |
41 | (iconv_t)(-1) if FROM_CODESET is UTF-8). | |
42 | CD2 is the conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1) | |
43 | if TO_CODESET is UTF-8). | |
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 | *RESULTP and *LENGTH should initially be a scratch buffer and its size, | |
49 | or *RESULTP can initially be NULL. | |
50 | May erase the contents of the memory at *RESULTP. | |
51 | Return value: 0 if successful, otherwise -1 and errno set. | |
52 | If successful: The resulting string is stored in *RESULTP and its length | |
53 | in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is | |
54 | unchanged if no dynamic memory allocation was necessary. */ | |
55 | extern int | |
56 | mem_cd_iconveh (const char *src, size_t srclen, | |
57 | iconv_t cd, iconv_t cd1, iconv_t cd2, | |
58 | enum iconv_ilseq_handler handler, | |
59 | size_t *offsets, | |
60 | char **resultp, size_t *lengthp); | |
61 | ||
62 | /* Convert an entire string from one encoding to another, using iconv. | |
63 | The original string is the NUL-terminated string starting at SRC. | |
64 | CD is the conversion descriptor from FROMCODE to TOCODE, or (iconv_t)(-1) if | |
65 | the system does not support a direct conversion from FROMCODE to TOCODE. | |
66 | Both the "from" and the "to" encoding must use a single NUL byte at the end | |
67 | of the string (i.e. not 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. */ | |
75 | extern char * | |
76 | str_cd_iconveh (const char *src, | |
77 | iconv_t cd, iconv_t cd1, iconv_t cd2, | |
78 | enum iconv_ilseq_handler handler); | |
79 | ||
80 | #endif | |
81 | ||
82 | /* Convert an entire string from one encoding to another, using iconv. | |
83 | The original string is at [SRC,...,SRC+SRCLEN-1]. | |
84 | If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this | |
85 | array is filled with offsets into the result, i.e. the character starting | |
86 | at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]], | |
87 | and other offsets are set to (size_t)(-1). | |
88 | *RESULTP and *LENGTH should initially be a scratch buffer and its size, | |
89 | or *RESULTP can initially be NULL. | |
90 | May erase the contents of the memory at *RESULTP. | |
91 | Return value: 0 if successful, otherwise -1 and errno set. | |
92 | If successful: The resulting string is stored in *RESULTP and its length | |
93 | in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is | |
94 | unchanged if no dynamic memory allocation was necessary. */ | |
95 | extern int | |
96 | mem_iconveh (const char *src, size_t srclen, | |
97 | const char *from_codeset, const char *to_codeset, | |
98 | enum iconv_ilseq_handler handler, | |
99 | size_t *offsets, | |
100 | char **resultp, size_t *lengthp); | |
101 | ||
102 | /* Convert an entire string from one encoding to another, using iconv. | |
103 | The original string is the NUL-terminated string starting at SRC. | |
104 | Both the "from" and the "to" encoding must use a single NUL byte at the | |
105 | end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32). | |
106 | Allocate a malloced memory block for the result. | |
107 | Return value: the freshly allocated resulting NUL-terminated string if | |
108 | successful, otherwise NULL and errno set. */ | |
109 | extern char * | |
110 | str_iconveh (const char *src, | |
111 | const char *from_codeset, const char *to_codeset, | |
112 | enum iconv_ilseq_handler handler); | |
113 | ||
114 | ||
115 | #ifdef __cplusplus | |
116 | } | |
117 | #endif | |
118 | ||
119 | ||
120 | #endif /* _STRICONVEH_H */ |