Statistics
| Branch: | Tag: | Revision:

root / libsylph / codeconv.h @ 8d7dcace

History | View | Annotate | Download (6.79 KB)

1
/*
2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2007 Hiroyuki Yamamoto
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library 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 GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19

    
20
#ifndef __CODECONV_H__
21
#define __CODECONV_H__
22

    
23
#ifdef HAVE_CONFIG_H
24
#  include "config.h"
25
#endif
26

    
27
#include <glib.h>
28
#include <iconv.h>
29

    
30
typedef struct _CodeConverter        CodeConverter;
31

    
32
typedef enum
33
{
34
        C_AUTO,
35
        C_US_ASCII,
36
        C_UTF_8,
37
        C_UTF_7,
38
        C_ISO_8859_1,
39
        C_ISO_8859_2,
40
        C_ISO_8859_3,
41
        C_ISO_8859_4,
42
        C_ISO_8859_5,
43
        C_ISO_8859_6,
44
        C_ISO_8859_7,
45
        C_ISO_8859_8,
46
        C_ISO_8859_9,
47
        C_ISO_8859_10,
48
        C_ISO_8859_11,
49
        C_ISO_8859_13,
50
        C_ISO_8859_14,
51
        C_ISO_8859_15,
52
        C_BALTIC,
53
        C_CP932,
54
        C_CP1250,
55
        C_CP1251,
56
        C_CP1252,
57
        C_CP1253,
58
        C_CP1254,
59
        C_CP1255,
60
        C_CP1256,
61
        C_CP1257,
62
        C_CP1258,
63
        C_WINDOWS_932,
64
        C_WINDOWS_1250,
65
        C_WINDOWS_1251,
66
        C_WINDOWS_1252,
67
        C_WINDOWS_1253,
68
        C_WINDOWS_1254,
69
        C_WINDOWS_1255,
70
        C_WINDOWS_1256,
71
        C_WINDOWS_1257,
72
        C_WINDOWS_1258,
73
        C_KOI8_R,
74
        C_KOI8_T,
75
        C_KOI8_U,
76
        C_ISO_2022_JP,
77
        C_ISO_2022_JP_2,
78
        C_ISO_2022_JP_3,
79
        C_EUC_JP,
80
        C_EUC_JP_MS,
81
        C_SHIFT_JIS,
82
        C_ISO_2022_KR,
83
        C_EUC_KR,
84
        C_ISO_2022_CN,
85
        C_EUC_CN,
86
        C_GB2312,
87
        C_GBK,
88
        C_EUC_TW,
89
        C_BIG5,
90
        C_BIG5_HKSCS,
91
        C_TIS_620,
92
        C_WINDOWS_874,
93
        C_GEORGIAN_PS,
94
        C_TCVN5712_1,
95
        C_ISO_8859_16
96
} CharSet;
97

    
98
typedef enum
99
{
100
        C_AD_BY_LOCALE,
101
        C_AD_NEVER,
102
        C_AD_JAPANESE
103
} ConvADType;
104

    
105
typedef gchar *(*CodeConvFunc) (const gchar *inbuf, gint *error);
106

    
107
struct _CodeConverter
108
{
109
        CodeConvFunc code_conv_func;
110
        gchar *src_encoding;
111
        gchar *dest_encoding;
112
};
113

    
114
#define CS_AUTO                        "AUTO"
115
#define CS_US_ASCII                "US-ASCII"
116
#define CS_ANSI_X3_4_1968        "ANSI_X3.4-1968"
117
#define CS_UTF_8                "UTF-8"
118
#define CS_UTF_7                "UTF-7"
119
#define CS_ISO_8859_1                "ISO-8859-1"
120
#define CS_ISO_8859_2                "ISO-8859-2"
121
#define CS_ISO_8859_3                "ISO-8859-3"
122
#define CS_ISO_8859_4                "ISO-8859-4"
123
#define CS_ISO_8859_5                "ISO-8859-5"
124
#define CS_ISO_8859_6                "ISO-8859-6"
125
#define CS_ISO_8859_7                "ISO-8859-7"
126
#define CS_ISO_8859_8                "ISO-8859-8"
127
#define CS_ISO_8859_9                "ISO-8859-9"
128
#define CS_ISO_8859_10                "ISO-8859-10"
129
#define CS_ISO_8859_11                "ISO-8859-11"
130
#define CS_ISO_8859_13                "ISO-8859-13"
131
#define CS_ISO_8859_14                "ISO-8859-14"
132
#define CS_ISO_8859_15                "ISO-8859-15"
133
#define CS_BALTIC                "BALTIC"
134
#define CS_CP932                "CP932"
135
#define CS_CP1250                "CP1250"
136
#define CS_CP1251                "CP1251"
137
#define CS_CP1252                "CP1252"
138
#define CS_CP1253                "CP1253"
139
#define CS_CP1254                "CP1254"
140
#define CS_CP1255                "CP1255"
141
#define CS_CP1256                "CP1256"
142
#define CS_CP1257                "CP1257"
143
#define CS_CP1258                "CP1258"
144
#define CS_WINDOWS_932                "Windows-932"
145
#define CS_WINDOWS_1250                "Windows-1250"
146
#define CS_WINDOWS_1251                "Windows-1251"
147
#define CS_WINDOWS_1252                "Windows-1252"
148
#define CS_WINDOWS_1253                "Windows-1253"
149
#define CS_WINDOWS_1254                "Windows-1254"
150
#define CS_WINDOWS_1255                "Windows-1255"
151
#define CS_WINDOWS_1256                "Windows-1256"
152
#define CS_WINDOWS_1257                "Windows-1257"
153
#define CS_WINDOWS_1258                "Windows-1258"
154
#define CS_KOI8_R                "KOI8-R"
155
#define CS_KOI8_T                "KOI8-T"
156
#define CS_KOI8_U                "KOI8-U"
157
#define CS_ISO_2022_JP                "ISO-2022-JP"
158
#define CS_ISO_2022_JP_2        "ISO-2022-JP-2"
159
#define CS_ISO_2022_JP_3        "ISO-2022-JP-3"
160
#define CS_EUC_JP                "EUC-JP"
161
#define CS_EUCJP                "EUCJP"
162
#define CS_EUC_JP_MS                "EUC-JP-MS"
163
#define CS_SHIFT_JIS                "Shift_JIS"
164
#define CS_SHIFT__JIS                "SHIFT-JIS"
165
#define CS_SJIS                        "SJIS"
166
#define CS_X_SJIS                "X-SJIS"
167
#define CS_ISO_2022_KR                "ISO-2022-KR"
168
#define CS_EUC_KR                "EUC-KR"
169
#define CS_KS_C_5601_1987        "ks_c_5601-1987"
170
#define CS_ISO_2022_CN                "ISO-2022-CN"
171
#define CS_EUC_CN                "EUC-CN"
172
#define CS_GB2312                "GB2312"
173
#define CS_GBK                        "GBK"
174
#define CS_X_GBK                "X-GBK"
175
#define CS_EUC_TW                "EUC-TW"
176
#define CS_BIG5                        "Big5"
177
#define CS_BIG5_HKSCS                "BIG5-HKSCS"
178
#define CS_TIS_620                "TIS-620"
179
#define CS_WINDOWS_874                "Windows-874"
180
#define CS_GEORGIAN_PS                "GEORGIAN-PS"
181
#define CS_TCVN5712_1                "TCVN5712-1"
182
#define CS_ISO_8859_16                "ISO-8859-16"
183

    
184
#define C_INTERNAL                C_UTF_8
185
#define CS_INTERNAL                CS_UTF_8
186

    
187
//void conv_mb_alnum(gchar *str);
188

    
189
CharSet conv_guess_ja_encoding                (const gchar        *str);
190

    
191
gchar *conv_utf8todisp                        (const gchar        *inbuf,
192
                                         gint                *error);
193
gchar *conv_localetodisp                (const gchar        *inbuf,
194
                                         gint                *error);
195

    
196
CodeConverter *conv_code_converter_new        (const gchar        *src_encoding,
197
                                         const gchar        *dest_encoding);
198
void conv_code_converter_destroy        (CodeConverter        *conv);
199
gchar *conv_convert                        (CodeConverter        *conv,
200
                                         const gchar        *inbuf);
201

    
202
#define conv_codeset_strdup(inbuf, src_code, dest_code) \
203
        (conv_codeset_strdup_full(inbuf, src_code, dest_code, NULL))
204

    
205
gchar *conv_codeset_strdup_full                (const gchar        *inbuf,
206
                                         const gchar        *src_encoding,
207
                                         const gchar        *dest_encoding,
208
                                         gint                *error);
209

    
210
CodeConvFunc conv_get_code_conv_func        (const gchar        *src_encoding,
211
                                         const gchar        *dest_encoding);
212

    
213
gchar *conv_iconv_strdup                (const gchar        *inbuf,
214
                                         const gchar        *src_encoding,
215
                                         const gchar        *dest_encoding,
216
                                         gint                *error);
217
gchar *conv_iconv_strdup_with_cd        (const gchar        *inbuf,
218
                                         iconv_t         cd,
219
                                         gint                *error);
220

    
221
const gchar *conv_get_charset_str                (CharSet         charset);
222
CharSet conv_get_charset_from_str                (const gchar        *charset);
223
CharSet conv_get_locale_charset                        (void);
224
const gchar *conv_get_locale_charset_str        (void);
225
CharSet conv_get_internal_charset                (void);
226
const gchar *conv_get_internal_charset_str        (void);
227
CharSet conv_get_outgoing_charset                (void);
228
const gchar *conv_get_outgoing_charset_str        (void);
229
gboolean conv_is_multibyte_encoding                (CharSet         encoding);
230

    
231
const gchar *conv_get_current_locale                (void);
232
gboolean conv_is_ja_locale                        (void);
233

    
234
void conv_set_autodetect_type                        (ConvADType         type);
235
ConvADType conv_get_autodetect_type                (void);
236

    
237
gchar *conv_unmime_header                (const gchar        *str,
238
                                         const gchar        *default_encoding);
239
void conv_encode_header                        (gchar                *dest,
240
                                         gint                 len,
241
                                         const gchar        *src,
242
                                         gint                 header_len,
243
                                         gboolean         addr_field,
244
                                         const gchar        *out_encoding);
245
gchar *conv_encode_filename                (const gchar        *src,
246
                                         const gchar        *param_name,
247
                                         const gchar        *out_encoding);
248

    
249
gint conv_copy_file                        (const gchar        *src,
250
                                         const gchar        *dest,
251
                                         const gchar        *src_encoding);
252
gint conv_copy_dir                        (const gchar        *src,
253
                                         const gchar        *dest,
254
                                         const gchar        *src_encoding);
255

    
256
CharSet conv_check_file_encoding        (const gchar        *file);
257

    
258
gchar *conv_filename_from_utf8                (const gchar        *utf8_file);
259
gchar *conv_filename_to_utf8                (const gchar        *fs_file);
260

    
261
#endif /* __CODECONV_H__ */