Mercurial > gftp.yaz
comparison lib/charset-conv.c @ 988:63555c9744c2
remote charset should be specified by each bookmark entry.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 14 Aug 2009 07:54:55 +0900 |
parents | c7d7a081cd9c |
children | c99b134c6185 |
comparison
equal
deleted
inserted
replaced
987:2f6924c67846 | 988:63555c9744c2 |
---|---|
72 | 72 |
73 printf (_("Error converting string '%s' from character set %s to character set %s: %s\n"), | 73 printf (_("Error converting string '%s' from character set %s to character set %s: %s\n"), |
74 str, fromset, toset, error->message); | 74 str, fromset, toset, error->message); |
75 } | 75 } |
76 | 76 |
77 | |
78 /*@null@*/ static char * | 77 /*@null@*/ static char * |
79 _do_convert_string (gftp_request * request, int is_filename, int force_local, | 78 _do_convert_string (gftp_request * request, int is_filename, int force_local, |
80 const char *str, size_t *dest_len, int from_utf8) | 79 const char *str, size_t *dest_len, int from_utf8) |
81 { | 80 { |
82 char *remote_charsets, *ret, *fromset, *toset, *stpos, *cur_charset; | 81 char *remote_charset = NULL, *default_charset = NULL, *ret, *fromset, |
82 *toset, *stpos, *cur_charset; | |
83 GError * error; | 83 GError * error; |
84 gsize bread; | 84 gsize bread; |
85 | 85 |
86 if (request == NULL) | 86 if (request == NULL) |
87 return (NULL); | 87 return (NULL); |
88 | 88 |
89 if (g_utf8_validate (str, -1, NULL) != from_utf8) | 89 if (g_utf8_validate (str, -1, NULL) != from_utf8) |
90 return (NULL); | 90 return (NULL); |
91 | 91 |
92 error = NULL; | 92 error = NULL; |
93 gftp_lookup_request_option (request, "remote_charsets", &remote_charsets); | 93 // gftp_lookup_request_option (request, "remote_charset", &remote_charset); |
94 if (*remote_charsets == '\0' || request->use_local_encoding || | 94 remote_charset = request->remote_charset; |
95 gftp_lookup_global_option ("default_charset", &default_charset); | |
96 if(!remote_charset) | |
97 remote_charset = (default_charset && *default_charset != '\0') | |
98 ? default_charset : "UTF8"; | |
99 | |
100 if (*remote_charset == '\0' || request->use_local_encoding || | |
95 force_local == 1) | 101 force_local == 1) |
96 { | 102 { |
97 if (from_utf8) | 103 if (from_utf8) |
98 { | 104 { |
99 if (is_filename) | 105 if (is_filename) |
138 | 144 |
139 return (ret); | 145 return (ret); |
140 } | 146 } |
141 } | 147 } |
142 | 148 |
143 stpos = remote_charsets; | 149 stpos = remote_charset; |
144 while ((cur_charset = _gftp_get_next_charset (&stpos)) != NULL) | 150 while ((cur_charset = _gftp_get_next_charset (&stpos)) != NULL) |
145 { | 151 { |
146 if (from_utf8) | 152 if (from_utf8) |
147 { | 153 { |
148 fromset = "UTF-8"; | 154 fromset = "UTF-8"; |
195 } | 201 } |
196 | 202 |
197 return (NULL); | 203 return (NULL); |
198 } | 204 } |
199 | 205 |
206 | |
200 char * | 207 char * |
201 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t *dest_len) | 208 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t *dest_len) |
202 { | 209 { |
203 return (_do_convert_string (request, 0, 0, str, dest_len, 0)); | 210 return (_do_convert_string (request, 0, 0, str, dest_len, 0)); |
204 } | 211 } |
225 size_t *dest_len) | 232 size_t *dest_len) |
226 { | 233 { |
227 return (_do_convert_string (request, 1, 0, str, dest_len, 1)); | 234 return (_do_convert_string (request, 1, 0, str, dest_len, 1)); |
228 } | 235 } |
229 | 236 |
237 | |
238 char * | |
239 gftp_remote_filename_to_utf8 (gftp_request * request, const char *str, | |
240 size_t *dest_len) | |
241 { | |
242 char *remote_charset = NULL, *default_charset = NULL; | |
243 GError *error = NULL; | |
244 gchar *ret = NULL; | |
245 | |
246 if(request == NULL) | |
247 return (NULL); | |
248 | |
249 /* get remote_charset */ | |
250 // gftp_lookup_request_option (request, "remote_charset", &remote_charset); | |
251 remote_charset = request->remote_charset; | |
252 gftp_lookup_global_option ("default_charset", &default_charset); | |
253 if(!remote_charset) | |
254 remote_charset = (default_charset && *default_charset != '\0') | |
255 ? default_charset : "UTF8"; | |
256 | |
257 ret = g_convert(str, -1, "UTF8", remote_charset, NULL, dest_len, error); | |
258 return ret; | |
259 } | |
260 | |
261 | |
262 char * | |
263 gftp_remote_filename_from_utf8 (gftp_request *request, const char *str, | |
264 size_t *dest_len) | |
265 { | |
266 char *remote_charset = NULL, *default_charset = NULL; | |
267 GError *error = NULL; | |
268 gchar *ret = NULL; | |
269 | |
270 if(request == NULL) | |
271 return (NULL); | |
272 | |
273 if(!g_utf8_validate (str, -1, NULL)) | |
274 return (NULL); | |
275 | |
276 /* get remote_charset */ | |
277 // gftp_lookup_request_option (request, "remote_charset", &remote_charset); | |
278 remote_charset = request->remote_charset; | |
279 gftp_lookup_global_option ("default_charset", &default_charset); | |
280 if(!remote_charset) | |
281 remote_charset = (default_charset && *default_charset != '\0') | |
282 ? default_charset : "UTF8"; | |
283 | |
284 ret = g_convert(str, -1, remote_charset, "UTF8", NULL, dest_len, error); | |
285 return ret; | |
286 } | |
287 | |
230 #else | 288 #else |
231 | 289 |
232 char * | 290 char * |
233 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t dest_len) | 291 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t dest_len) |
234 { | 292 { |
256 const char *str, size_t dest_len) | 314 const char *str, size_t dest_len) |
257 { | 315 { |
258 return (NULL); | 316 return (NULL); |
259 } | 317 } |
260 | 318 |
319 char * | |
320 gftp_remote_filename_to_utf8 (gftp_request * request, const char *str, size_t dest_len) | |
321 { | |
322 return (NULL); | |
323 } | |
324 | |
325 | |
326 char * | |
327 gftp_remote_filename_from_utf8 (gftp_request * request, int force_local, | |
328 const char *str, size_t dest_len) | |
329 { | |
330 return (NULL); | |
331 } | |
332 | |
261 #endif | 333 #endif |
262 | 334 |
263 | 335 |