47
47
#define CHARSET_TRANS_ARRAY_LEN ( sizeof(charset_trans_array) / sizeof((charset_trans_array)[0]) )
48
const CharsetInfo charset_trans_array[] = {
48
static const CharsetInfo charset_trans_array[] = {
49
49
{N_("Arabic (IBM-864)"), "IBM864" },
50
50
{N_("Arabic (ISO-8859-6)"), "ISO-8859-6" },
51
51
{N_("Arabic (Windows-1256)"), "windows-1256" },
186
186
/* "C" is plain ascii */
187
187
insert_locales (encodings, "ASCII", "C", NULL);
189
189
insert_locales (encodings, "windows-1256", "ar", NULL); // 2006.12.31 - For testing with Arabic
190
#else /* !G_OS_WIN32 */
191
191
insert_locales (encodings, "ISO-8859-6", "ar", NULL);
192
#endif /* !G_OS_WIN32 */
193
193
insert_locales (encodings, "ARMSCII-8", "by", NULL);
194
194
insert_locales (encodings, "BIG5", "zh_TW", NULL);
195
195
insert_locales (encodings, "CP1251", "be", "bg", NULL);
203
203
/*insert_locales (encodings, "GEORGIAN-ACADEMY", NULL);*/
204
204
insert_locales (encodings, "GEORGIAN-PS", "ka", NULL);
205
205
insert_locales (encodings, "ISO-8859-1", "br", "ca", "da", "de", "en", "es", "eu", "fi", "fr", "gl", "it", "nl", "wa", "nb", "nn", "pt", "pt", "sv", NULL);
207
207
insert_locales (encodings, "windows-1250", "cs", "hr", "hu", "pl", "ro", "sk", "sl", "sq", "sr", NULL);
208
#else /* !G_OS_WIN32 */
209
209
insert_locales (encodings, "ISO-8859-2", "cs", "hr", "hu", "pl", "ro", "sk", "sl", "sq", "sr", NULL);
210
#endif /* !G_OS_WIN32 */
211
211
insert_locales (encodings, "ISO-8859-3", "eo", NULL);
212
212
insert_locales (encodings, "ISO-8859-5", "mk", "sp", NULL);
214
214
insert_locales (encodings, "windows-1253", "el", NULL);
215
#else /* !G_OS_WIN32 */
216
216
insert_locales (encodings, "ISO-8859-7", "el", NULL);
217
#endif /* !G_OS_WIN32 */
219
219
insert_locales (encodings, "windows-1254", "tr", NULL);
220
#else /* !G_OS_WIN32 */
221
221
insert_locales (encodings, "ISO-8859-9", "tr", NULL);
222
#endif /* !G_OS_WIN32 */
223
223
insert_locales (encodings, "ISO-8859-13", "lt", "lv", "mi", NULL);
224
224
insert_locales (encodings, "ISO-8859-14", "ga", "cy", NULL);
225
225
insert_locales (encodings, "ISO-8859-15", "et", NULL);
227
227
insert_locales (encodings, "windows-1251", "ru", NULL);
228
#else /* !G_OS_WIN32 */
229
229
insert_locales (encodings, "KOI8-R", "ru", NULL);
230
#endif /* !G_OS_WIN32 */
231
231
insert_locales (encodings, "KOI8-U", "uk", NULL);
232
232
if (check_locale ("TCVN-5712")) {
233
233
insert_locales (encodings, "TCVN-5712", "vi", NULL);
235
235
insert_locales (encodings, "TCVN", "vi", NULL);
237
237
insert_locales (encodings, "TIS-620", "th", NULL);
239
239
insert_locales (encodings, "windows-1255", "he", NULL);
240
#endif /* G_OS_WIN32 */
241
241
/*insert_locales (encodings, "VISCII", NULL);*/
382
382
return convert_string_1(string, -1, from_codeset, to_codeset, display_error);
384
385
/* Length must be passed, as the string might be Unicode, in which case we can't
385
386
* count zeroes (see strlen call below). */
386
gchar *convert_string_1 (const gchar *string, gssize length, const gchar *from_codeset,
388
convert_string_1 (const gchar *string, gssize length, const gchar *from_codeset,
387
389
const gchar *to_codeset, const gboolean display_error)
390
392
GError *error = NULL;
391
393
gsize bytes_written;
395
g_return_val_if_fail (string != NULL, NULL);
396
397
output = g_convert(string, length, to_codeset, from_codeset, NULL, &bytes_written, &error);
397
398
//output = g_convert_with_fallback(string, length, to_codeset, from_codeset, "?", NULL, &bytes_written, &error);
420
421
// g_convert returns null-terminated string only with one \0 at the
421
422
// end. It can cause some garbage at the end of a string for UTF-16.
422
423
// The second \0 should be set manually.
423
output = g_realloc(output, bytes_written + 2);
425
new_output = g_realloc (output, bytes_written + 2);
426
if (new_output != NULL)
425
429
output[bytes_written] = output[bytes_written + 1] = 0;
428
433
//g_print("from %s => len: %d, string: '%s'\n (%x %x %x %x %x %x %x %x)\n",from_codeset,length,string,string[0],string[1],string[2],string[3],string[4],string[5],string[6],string[7]);
470
gchar *convert_from_utf8 (const char *string)
473
GError *error = NULL;
478
output = g_locale_from_utf8(string, -1, NULL, NULL, &error);
482
const gchar *usercharset;
483
gchar *escaped_str = g_strescape(string, NULL);
484
g_get_charset(&usercharset);
485
Log_Print(LOG_ERROR,"convert_from_utf8(): Failed conversion to charset '%s'. "
486
"String '%s'. Errcode %d (%s).",
487
usercharset, escaped_str, error->code, error->message);
490
if (g_utf8_validate(string, -1, NULL))
491
Log_Print(LOG_ERROR,"convert_from_utf8(): String was valid UTF-8.");
493
Log_Print(LOG_ERROR,"convert_from_utf8(): String was INVALID UTF-8.");
496
return g_strdup(string);
505
476
* Convert a string from the filename system encoding to UTF-8.
506
477
* - conversion OK : returns the UTF-8 string (new allocated)
507
478
* - conversion KO : tries others encodings else returns an 'escaped' string
509
gchar *filename_to_display (const gchar *string)
481
filename_to_display (const gchar *string)
511
483
gchar *ret = NULL;
512
484
GError *error = NULL;
486
g_return_val_if_fail (string != NULL, NULL);
517
488
if (g_utf8_validate(string, -1, NULL))
735
706
* Return charset_name from charset_title
737
gchar *Charset_Get_Name_From_Title (const gchar *charset_title)
742
for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
743
if ( strcasecmp(_(charset_title),_(charset_trans_array[i].charset_title)) == 0 )
744
return charset_trans_array[i].charset_name;
750
* Return charset_title from charset_name
752
gchar *Charset_Get_Title_From_Name (gchar *charset_name)
757
for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
758
if ( strcasecmp(charset_name,charset_trans_array[i].charset_name) == 0 )
759
return _(charset_trans_array[i].charset_title);
766
* Test if the conversion is supported between two character sets ('from' and 'to)
767
* (function called in the preferences window).
768
* Note : for UTF-16 (2 byte for each character) we make a special test...
770
gboolean test_conversion_charset (const gchar *from, const gchar *to)
777
// Do a quick test conversion and examine error output
778
if ( strcmp(from,"UTF-16BE") == 0 )
780
temp = convert_string_1("F\0O\0O\0\0\0", 6, from, to, FALSE);
781
}else if ( strcmp(from,"UTF-16LE") == 0 )
783
temp = convert_string_1("\0F\0O\0O\0\0", 6, from, to, FALSE);
786
temp = convert_string("FOO", from, to, FALSE);
791
/*// Error in conversion
792
if (error && error->code == G_CONVERT_ERROR_NO_CONVERSION)
794
Log_Print(LOG_ERROR,"Conversion error from '%s' to '%s' (G_CONVERT_ERROR_NO_CONVERSION)",from,to);
795
} else if (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
797
Log_Print(LOG_ERROR,"Conversion error from '%s' to '%s' (G_CONVERT_ERROR_ILLEGAL_SEQUENCE)",from,to);
798
} else if (error && error->code == G_CONVERT_ERROR_FAILED)
800
Log_Print(LOG_ERROR,"Conversion error from '%s' to '%s' (G_CONVERT_ERROR_FAILED)",from,to);
801
} else if (error && error->code == G_CONVERT_ERROR_PARTIAL_INPUT)
803
Log_Print(LOG_ERROR,"Conversion error from '%s' to '%s' (G_CONVERT_ERROR_PARTIAL_INPUT)",from,to);
804
} else if (error && error->code == G_CONVERT_ERROR_BAD_URI)
806
Log_Print(LOG_ERROR,"Conversion error from '%s' to '%s' (G_CONVERT_ERROR_BAD_URI)",from,to);
807
} else if (error && error->code == G_CONVERT_ERROR_NOT_ABSOLUTE_PATH)
809
Log_Print(LOG_ERROR,"Conversion error from '%s' to '%s' (G_CONVERT_ERROR_NOT_ABSOLUTE_PATH)",from,to);
812
Log_Print(LOG_ERROR,"Conversion error from '%s' to '%s' (unknown : %d)",from,to,error->code);
709
Charset_Get_Name_From_Title (const gchar *charset_title)
713
g_return_val_if_fail (charset_title != NULL, NULL);
715
for (i = 0; i < CHARSET_TRANS_ARRAY_LEN; i++)
717
if (strcasecmp (_(charset_title),
718
_(charset_trans_array[i].charset_title)) == 0)
720
return charset_trans_array[i].charset_name;
816
g_error_free(error);*/
822
g_error_free(error);*/