Statistics
| Revision:

root / libsylph / codeconv.h @ 2916

History | View | Annotate | Download (6.8 kB)

1 528 hiro
/*
2 578 hiro
 * LibSylph -- E-Mail client library
3 1626 hiro
 * Copyright (C) 1999-2007 Hiroyuki Yamamoto
4 528 hiro
 *
5 578 hiro
 * This library is free software; you can redistribute it and/or
6 578 hiro
 * modify it under the terms of the GNU Lesser General Public
7 578 hiro
 * License as published by the Free Software Foundation; either
8 578 hiro
 * version 2.1 of the License, or (at your option) any later version.
9 528 hiro
 *
10 578 hiro
 * This library is distributed in the hope that it will be useful,
11 528 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 578 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 578 hiro
 * Lesser General Public License for more details.
14 528 hiro
 *
15 578 hiro
 * You should have received a copy of the GNU Lesser General Public
16 578 hiro
 * License along with this library; if not, write to the Free Software
17 578 hiro
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 528 hiro
 */
19 528 hiro
20 528 hiro
#ifndef __CODECONV_H__
21 528 hiro
#define __CODECONV_H__
22 528 hiro
23 528 hiro
#ifdef HAVE_CONFIG_H
24 528 hiro
#  include "config.h"
25 528 hiro
#endif
26 528 hiro
27 528 hiro
#include <glib.h>
28 528 hiro
#include <iconv.h>
29 528 hiro
30 528 hiro
typedef struct _CodeConverter        CodeConverter;
31 528 hiro
32 528 hiro
typedef enum
33 528 hiro
{
34 528 hiro
        C_AUTO,
35 528 hiro
        C_US_ASCII,
36 528 hiro
        C_UTF_8,
37 528 hiro
        C_UTF_7,
38 528 hiro
        C_ISO_8859_1,
39 528 hiro
        C_ISO_8859_2,
40 528 hiro
        C_ISO_8859_3,
41 528 hiro
        C_ISO_8859_4,
42 528 hiro
        C_ISO_8859_5,
43 528 hiro
        C_ISO_8859_6,
44 528 hiro
        C_ISO_8859_7,
45 528 hiro
        C_ISO_8859_8,
46 528 hiro
        C_ISO_8859_9,
47 528 hiro
        C_ISO_8859_10,
48 528 hiro
        C_ISO_8859_11,
49 528 hiro
        C_ISO_8859_13,
50 528 hiro
        C_ISO_8859_14,
51 528 hiro
        C_ISO_8859_15,
52 528 hiro
        C_BALTIC,
53 645 hiro
        C_CP932,
54 528 hiro
        C_CP1250,
55 528 hiro
        C_CP1251,
56 528 hiro
        C_CP1252,
57 528 hiro
        C_CP1253,
58 528 hiro
        C_CP1254,
59 528 hiro
        C_CP1255,
60 528 hiro
        C_CP1256,
61 528 hiro
        C_CP1257,
62 528 hiro
        C_CP1258,
63 645 hiro
        C_WINDOWS_932,
64 528 hiro
        C_WINDOWS_1250,
65 528 hiro
        C_WINDOWS_1251,
66 528 hiro
        C_WINDOWS_1252,
67 528 hiro
        C_WINDOWS_1253,
68 528 hiro
        C_WINDOWS_1254,
69 528 hiro
        C_WINDOWS_1255,
70 528 hiro
        C_WINDOWS_1256,
71 528 hiro
        C_WINDOWS_1257,
72 528 hiro
        C_WINDOWS_1258,
73 528 hiro
        C_KOI8_R,
74 528 hiro
        C_KOI8_T,
75 528 hiro
        C_KOI8_U,
76 528 hiro
        C_ISO_2022_JP,
77 528 hiro
        C_ISO_2022_JP_2,
78 528 hiro
        C_ISO_2022_JP_3,
79 528 hiro
        C_EUC_JP,
80 528 hiro
        C_EUC_JP_MS,
81 528 hiro
        C_SHIFT_JIS,
82 528 hiro
        C_ISO_2022_KR,
83 528 hiro
        C_EUC_KR,
84 528 hiro
        C_ISO_2022_CN,
85 528 hiro
        C_EUC_CN,
86 528 hiro
        C_GB2312,
87 528 hiro
        C_GBK,
88 528 hiro
        C_EUC_TW,
89 528 hiro
        C_BIG5,
90 528 hiro
        C_BIG5_HKSCS,
91 528 hiro
        C_TIS_620,
92 528 hiro
        C_WINDOWS_874,
93 528 hiro
        C_GEORGIAN_PS,
94 1626 hiro
        C_TCVN5712_1,
95 1626 hiro
        C_ISO_8859_16
96 528 hiro
} CharSet;
97 528 hiro
98 2019 hiro
typedef enum
99 2019 hiro
{
100 2019 hiro
        C_AD_BY_LOCALE,
101 2019 hiro
        C_AD_NEVER,
102 2019 hiro
        C_AD_JAPANESE
103 2019 hiro
} ConvADType;
104 2019 hiro
105 528 hiro
typedef gchar *(*CodeConvFunc) (const gchar *inbuf, gint *error);
106 528 hiro
107 528 hiro
struct _CodeConverter
108 528 hiro
{
109 528 hiro
        CodeConvFunc code_conv_func;
110 528 hiro
        gchar *src_encoding;
111 528 hiro
        gchar *dest_encoding;
112 528 hiro
};
113 528 hiro
114 528 hiro
#define CS_AUTO                        "AUTO"
115 528 hiro
#define CS_US_ASCII                "US-ASCII"
116 528 hiro
#define CS_ANSI_X3_4_1968        "ANSI_X3.4-1968"
117 528 hiro
#define CS_UTF_8                "UTF-8"
118 528 hiro
#define CS_UTF_7                "UTF-7"
119 528 hiro
#define CS_ISO_8859_1                "ISO-8859-1"
120 528 hiro
#define CS_ISO_8859_2                "ISO-8859-2"
121 528 hiro
#define CS_ISO_8859_3                "ISO-8859-3"
122 528 hiro
#define CS_ISO_8859_4                "ISO-8859-4"
123 528 hiro
#define CS_ISO_8859_5                "ISO-8859-5"
124 528 hiro
#define CS_ISO_8859_6                "ISO-8859-6"
125 528 hiro
#define CS_ISO_8859_7                "ISO-8859-7"
126 528 hiro
#define CS_ISO_8859_8                "ISO-8859-8"
127 528 hiro
#define CS_ISO_8859_9                "ISO-8859-9"
128 528 hiro
#define CS_ISO_8859_10                "ISO-8859-10"
129 528 hiro
#define CS_ISO_8859_11                "ISO-8859-11"
130 528 hiro
#define CS_ISO_8859_13                "ISO-8859-13"
131 528 hiro
#define CS_ISO_8859_14                "ISO-8859-14"
132 528 hiro
#define CS_ISO_8859_15                "ISO-8859-15"
133 528 hiro
#define CS_BALTIC                "BALTIC"
134 645 hiro
#define CS_CP932                "CP932"
135 528 hiro
#define CS_CP1250                "CP1250"
136 528 hiro
#define CS_CP1251                "CP1251"
137 528 hiro
#define CS_CP1252                "CP1252"
138 528 hiro
#define CS_CP1253                "CP1253"
139 528 hiro
#define CS_CP1254                "CP1254"
140 528 hiro
#define CS_CP1255                "CP1255"
141 528 hiro
#define CS_CP1256                "CP1256"
142 528 hiro
#define CS_CP1257                "CP1257"
143 528 hiro
#define CS_CP1258                "CP1258"
144 645 hiro
#define CS_WINDOWS_932                "Windows-932"
145 528 hiro
#define CS_WINDOWS_1250                "Windows-1250"
146 528 hiro
#define CS_WINDOWS_1251                "Windows-1251"
147 528 hiro
#define CS_WINDOWS_1252                "Windows-1252"
148 528 hiro
#define CS_WINDOWS_1253                "Windows-1253"
149 528 hiro
#define CS_WINDOWS_1254                "Windows-1254"
150 528 hiro
#define CS_WINDOWS_1255                "Windows-1255"
151 528 hiro
#define CS_WINDOWS_1256                "Windows-1256"
152 528 hiro
#define CS_WINDOWS_1257                "Windows-1257"
153 528 hiro
#define CS_WINDOWS_1258                "Windows-1258"
154 528 hiro
#define CS_KOI8_R                "KOI8-R"
155 528 hiro
#define CS_KOI8_T                "KOI8-T"
156 528 hiro
#define CS_KOI8_U                "KOI8-U"
157 528 hiro
#define CS_ISO_2022_JP                "ISO-2022-JP"
158 528 hiro
#define CS_ISO_2022_JP_2        "ISO-2022-JP-2"
159 528 hiro
#define CS_ISO_2022_JP_3        "ISO-2022-JP-3"
160 528 hiro
#define CS_EUC_JP                "EUC-JP"
161 528 hiro
#define CS_EUCJP                "EUCJP"
162 528 hiro
#define CS_EUC_JP_MS                "EUC-JP-MS"
163 528 hiro
#define CS_SHIFT_JIS                "Shift_JIS"
164 528 hiro
#define CS_SHIFT__JIS                "SHIFT-JIS"
165 528 hiro
#define CS_SJIS                        "SJIS"
166 528 hiro
#define CS_X_SJIS                "X-SJIS"
167 528 hiro
#define CS_ISO_2022_KR                "ISO-2022-KR"
168 528 hiro
#define CS_EUC_KR                "EUC-KR"
169 835 hiro
#define CS_KS_C_5601_1987        "ks_c_5601-1987"
170 528 hiro
#define CS_ISO_2022_CN                "ISO-2022-CN"
171 528 hiro
#define CS_EUC_CN                "EUC-CN"
172 528 hiro
#define CS_GB2312                "GB2312"
173 528 hiro
#define CS_GBK                        "GBK"
174 528 hiro
#define CS_X_GBK                "X-GBK"
175 528 hiro
#define CS_EUC_TW                "EUC-TW"
176 528 hiro
#define CS_BIG5                        "Big5"
177 528 hiro
#define CS_BIG5_HKSCS                "BIG5-HKSCS"
178 528 hiro
#define CS_TIS_620                "TIS-620"
179 528 hiro
#define CS_WINDOWS_874                "Windows-874"
180 528 hiro
#define CS_GEORGIAN_PS                "GEORGIAN-PS"
181 528 hiro
#define CS_TCVN5712_1                "TCVN5712-1"
182 1626 hiro
#define CS_ISO_8859_16                "ISO-8859-16"
183 528 hiro
184 528 hiro
#define C_INTERNAL                C_UTF_8
185 528 hiro
#define CS_INTERNAL                CS_UTF_8
186 528 hiro
187 528 hiro
//void conv_mb_alnum(gchar *str);
188 528 hiro
189 528 hiro
CharSet conv_guess_ja_encoding                (const gchar        *str);
190 528 hiro
191 528 hiro
gchar *conv_utf8todisp                        (const gchar        *inbuf,
192 528 hiro
                                         gint                *error);
193 528 hiro
gchar *conv_localetodisp                (const gchar        *inbuf,
194 528 hiro
                                         gint                *error);
195 528 hiro
196 528 hiro
CodeConverter *conv_code_converter_new        (const gchar        *src_encoding,
197 528 hiro
                                         const gchar        *dest_encoding);
198 528 hiro
void conv_code_converter_destroy        (CodeConverter        *conv);
199 528 hiro
gchar *conv_convert                        (CodeConverter        *conv,
200 528 hiro
                                         const gchar        *inbuf);
201 528 hiro
202 528 hiro
#define conv_codeset_strdup(inbuf, src_code, dest_code) \
203 528 hiro
        (conv_codeset_strdup_full(inbuf, src_code, dest_code, NULL))
204 528 hiro
205 528 hiro
gchar *conv_codeset_strdup_full                (const gchar        *inbuf,
206 528 hiro
                                         const gchar        *src_encoding,
207 528 hiro
                                         const gchar        *dest_encoding,
208 528 hiro
                                         gint                *error);
209 528 hiro
210 528 hiro
CodeConvFunc conv_get_code_conv_func        (const gchar        *src_encoding,
211 528 hiro
                                         const gchar        *dest_encoding);
212 528 hiro
213 528 hiro
gchar *conv_iconv_strdup                (const gchar        *inbuf,
214 528 hiro
                                         const gchar        *src_encoding,
215 528 hiro
                                         const gchar        *dest_encoding,
216 528 hiro
                                         gint                *error);
217 528 hiro
gchar *conv_iconv_strdup_with_cd        (const gchar        *inbuf,
218 528 hiro
                                         iconv_t         cd,
219 528 hiro
                                         gint                *error);
220 528 hiro
221 528 hiro
const gchar *conv_get_charset_str                (CharSet         charset);
222 528 hiro
CharSet conv_get_charset_from_str                (const gchar        *charset);
223 528 hiro
CharSet conv_get_locale_charset                        (void);
224 528 hiro
const gchar *conv_get_locale_charset_str        (void);
225 528 hiro
CharSet conv_get_internal_charset                (void);
226 528 hiro
const gchar *conv_get_internal_charset_str        (void);
227 528 hiro
CharSet conv_get_outgoing_charset                (void);
228 528 hiro
const gchar *conv_get_outgoing_charset_str        (void);
229 528 hiro
gboolean conv_is_multibyte_encoding                (CharSet         encoding);
230 528 hiro
231 528 hiro
const gchar *conv_get_current_locale                (void);
232 528 hiro
gboolean conv_is_ja_locale                        (void);
233 528 hiro
234 2019 hiro
void conv_set_autodetect_type                        (ConvADType         type);
235 2019 hiro
ConvADType conv_get_autodetect_type                (void);
236 2019 hiro
237 528 hiro
gchar *conv_unmime_header                (const gchar        *str,
238 528 hiro
                                         const gchar        *default_encoding);
239 528 hiro
void conv_encode_header                        (gchar                *dest,
240 528 hiro
                                         gint                 len,
241 528 hiro
                                         const gchar        *src,
242 528 hiro
                                         gint                 header_len,
243 528 hiro
                                         gboolean         addr_field,
244 528 hiro
                                         const gchar        *out_encoding);
245 1052 hiro
gchar *conv_encode_filename                (const gchar        *src,
246 1052 hiro
                                         const gchar        *param_name,
247 1052 hiro
                                         const gchar        *out_encoding);
248 528 hiro
249 528 hiro
gint conv_copy_file                        (const gchar        *src,
250 528 hiro
                                         const gchar        *dest,
251 528 hiro
                                         const gchar        *src_encoding);
252 528 hiro
gint conv_copy_dir                        (const gchar        *src,
253 528 hiro
                                         const gchar        *dest,
254 528 hiro
                                         const gchar        *src_encoding);
255 528 hiro
256 1121 hiro
CharSet conv_check_file_encoding        (const gchar        *file);
257 1121 hiro
258 528 hiro
gchar *conv_filename_from_utf8                (const gchar        *utf8_file);
259 528 hiro
gchar *conv_filename_to_utf8                (const gchar        *fs_file);
260 528 hiro
261 528 hiro
#endif /* __CODECONV_H__ */