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