charset.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:8k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* libxmms-flac - XMMS FLAC input plugin
  2.  * Copyright (C) 2002,2003,2004,2005  Daisuke Shimamura
  3.  *
  4.  * Almost from charset.c
  5.  *  EasyTAG - Tag editor for MP3 and OGG files
  6.  *  Copyright (C) 1999-2001  H鍁ard Kv錶en <havardk@xmms.org>
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License
  10.  * as published by the Free Software Foundation; either version 2
  11.  * of the License, or (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  */
  22. #include <stdlib.h>
  23. #include <glib.h>
  24. #include <string.h>
  25. #include <errno.h>
  26. #include "plugin_common/charset.h"
  27. #include "plugin_common/locale_hack.h"
  28. #include "charset.h"
  29. #include "configure.h"
  30. /****************
  31.  * Declarations *
  32.  ****************/
  33. #define CHARSET_TRANS_ARRAY_LEN ( sizeof(charset_trans_array) / sizeof((charset_trans_array)[0]) )
  34. const CharsetInfo charset_trans_array[] = {
  35. {N_("Arabic (IBM-864)"),                  "IBM864"        },
  36. {N_("Arabic (ISO-8859-6)"),               "ISO-8859-6"    },
  37. {N_("Arabic (Windows-1256)"),             "windows-1256"  },
  38. {N_("Baltic (ISO-8859-13)"),              "ISO-8859-13"   },
  39. {N_("Baltic (ISO-8859-4)"),               "ISO-8859-4"    },
  40. {N_("Baltic (Windows-1257)"),             "windows-1257"  },
  41. {N_("Celtic (ISO-8859-14)"),              "ISO-8859-14"   },
  42. {N_("Central European (IBM-852)"),        "IBM852"        },
  43. {N_("Central European (ISO-8859-2)"),     "ISO-8859-2"    },
  44. {N_("Central European (Windows-1250)"),   "windows-1250"  },
  45. {N_("Chinese Simplified (GB18030)"),      "gb18030"       },
  46. {N_("Chinese Simplified (GB2312)"),       "GB2312"        },
  47. {N_("Chinese Traditional (Big5)"),        "Big5"          },
  48. {N_("Chinese Traditional (Big5-HKSCS)"),  "Big5-HKSCS"    },
  49. {N_("Cyrillic (IBM-855)"),                "IBM855"        },
  50. {N_("Cyrillic (ISO-8859-5)"),             "ISO-8859-5"    },
  51. {N_("Cyrillic (ISO-IR-111)"),             "ISO-IR-111"    },
  52. {N_("Cyrillic (KOI8-R)"),                 "KOI8-R"        },
  53. {N_("Cyrillic (Windows-1251)"),           "windows-1251"  },
  54. {N_("Cyrillic/Russian (CP-866)"),         "IBM866"        },
  55. {N_("Cyrillic/Ukrainian (KOI8-U)"),       "KOI8-U"        },
  56. {N_("English (US-ASCII)"),                "us-ascii"      },
  57. {N_("Greek (ISO-8859-7)"),                "ISO-8859-7"    },
  58. {N_("Greek (Windows-1253)"),              "windows-1253"  },
  59. {N_("Hebrew (IBM-862)"),                  "IBM862"        },
  60. {N_("Hebrew (Windows-1255)"),             "windows-1255"  },
  61. {N_("Japanese (EUC-JP)"),                 "EUC-JP"        },
  62. {N_("Japanese (ISO-2022-JP)"),            "ISO-2022-JP"   },
  63. {N_("Japanese (Shift_JIS)"),              "Shift_JIS"     },
  64. {N_("Korean (EUC-KR)"),                   "EUC-KR"        },
  65. {N_("Nordic (ISO-8859-10)"),              "ISO-8859-10"   },
  66. {N_("South European (ISO-8859-3)"),       "ISO-8859-3"    },
  67. {N_("Thai (TIS-620)"),                    "TIS-620"       },
  68. {N_("Turkish (IBM-857)"),                 "IBM857"        },
  69. {N_("Turkish (ISO-8859-9)"),              "ISO-8859-9"    },
  70. {N_("Turkish (Windows-1254)"),            "windows-1254"  },
  71. {N_("Unicode (UTF-7)"),                   "UTF-7"         },
  72. {N_("Unicode (UTF-8)"),                   "UTF-8"         },
  73. {N_("Unicode (UTF-16BE)"),                "UTF-16BE"      },
  74. {N_("Unicode (UTF-16LE)"),                "UTF-16LE"      },
  75. {N_("Unicode (UTF-32BE)"),                "UTF-32BE"      },
  76. {N_("Unicode (UTF-32LE)"),                "UTF-32LE"      },
  77. {N_("Vietnamese (VISCII)"),               "VISCII"        },
  78. {N_("Vietnamese (Windows-1258)"),         "windows-1258"  },
  79. {N_("Visual Hebrew (ISO-8859-8)"),        "ISO-8859-8"    },
  80. {N_("Western (IBM-850)"),                 "IBM850"        },
  81. {N_("Western (ISO-8859-1)"),              "ISO-8859-1"    },
  82. {N_("Western (ISO-8859-15)"),             "ISO-8859-15"   },
  83. {N_("Western (Windows-1252)"),            "windows-1252"  }
  84. /*
  85.  * From this point, character sets aren't supported by iconv
  86.  */
  87. #if 0
  88. {N_("Arabic (IBM-864-I)"),                "IBM864i"              },
  89. {N_("Arabic (ISO-8859-6-E)"),             "ISO-8859-6-E"         },
  90. {N_("Arabic (ISO-8859-6-I)"),             "ISO-8859-6-I"         },
  91. {N_("Arabic (MacArabic)"),                "x-mac-arabic"         },
  92. {N_("Armenian (ARMSCII-8)"),              "armscii-8"            },
  93. {N_("Central European (MacCE)"),          "x-mac-ce"             },
  94. {N_("Chinese Simplified (GBK)"),          "x-gbk"                },
  95. {N_("Chinese Simplified (HZ)"),           "HZ-GB-2312"           },
  96. {N_("Chinese Traditional (EUC-TW)"),      "x-euc-tw"             },
  97. {N_("Croatian (MacCroatian)"),            "x-mac-croatian"       },
  98. {N_("Cyrillic (MacCyrillic)"),            "x-mac-cyrillic"       },
  99. {N_("Cyrillic/Ukrainian (MacUkrainian)"), "x-mac-ukrainian"      },
  100. {N_("Farsi (MacFarsi)"),                  "x-mac-farsi"},
  101. {N_("Greek (MacGreek)"),                  "x-mac-greek"          },
  102. {N_("Gujarati (MacGujarati)"),            "x-mac-gujarati"       },
  103. {N_("Gurmukhi (MacGurmukhi)"),            "x-mac-gurmukhi"       },
  104. {N_("Hebrew (ISO-8859-8-E)"),             "ISO-8859-8-E"         },
  105. {N_("Hebrew (ISO-8859-8-I)"),             "ISO-8859-8-I"         },
  106. {N_("Hebrew (MacHebrew)"),                "x-mac-hebrew"         },
  107. {N_("Hindi (MacDevanagari)"),             "x-mac-devanagari"     },
  108. {N_("Icelandic (MacIcelandic)"),          "x-mac-icelandic"      },
  109. {N_("Korean (JOHAB)"),                    "x-johab"              },
  110. {N_("Korean (UHC)"),                      "x-windows-949"        },
  111. {N_("Romanian (MacRomanian)"),            "x-mac-romanian"       },
  112. {N_("Turkish (MacTurkish)"),              "x-mac-turkish"        },
  113. {N_("User Defined"),                      "x-user-defined"       },
  114. {N_("Vietnamese (TCVN)"),                 "x-viet-tcvn5712"      },
  115. {N_("Vietnamese (VPS)"),                  "x-viet-vps"           },
  116. {N_("Western (MacRoman)"),                "x-mac-roman"          },
  117. /* charsets whithout posibly translatable names */
  118. {"T61.8bit",                              "T61.8bit"             },
  119. {"x-imap4-modified-utf7",                 "x-imap4-modified-utf7"},
  120. {"x-u-escaped",                           "x-u-escaped"          },
  121. {"windows-936",                           "windows-936"          }
  122. #endif
  123. };
  124. /*************
  125.  * Functions *
  126.  *************/
  127. /*
  128.  * Commons conversion functions
  129.  */
  130. char *convert_from_utf8_to_user(const char *string)
  131. {
  132. return FLAC_plugin__charset_convert_string(string, "UTF-8", flac_cfg.title.user_char_set);
  133. }
  134. char *convert_from_user_to_utf8(const char *string)
  135. {
  136. return FLAC_plugin__charset_convert_string(string, flac_cfg.title.user_char_set, "UTF-8");
  137. }
  138. GList *Charset_Create_List (void)
  139. {
  140. GList *list = NULL;
  141. guint i;
  142. for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
  143. list = g_list_append(list,_(charset_trans_array[i].charset_title));
  144. return list;
  145. }
  146. GList *Charset_Create_List_UTF8_Only (void)
  147. {
  148. GList *list = NULL;
  149. list = g_list_append(list,_(Charset_Get_Title_From_Name("UTF-8")));
  150. return list;
  151. }
  152. /*
  153.  * Return charset_name from charset_title
  154.  */
  155. gchar *Charset_Get_Name_From_Title (gchar *charset_title)
  156. {
  157. guint i;
  158. if (charset_title)
  159. for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
  160. if ( strcasecmp(_(charset_title),_(charset_trans_array[i].charset_title)) == 0 )
  161. return charset_trans_array[i].charset_name;
  162. return "";
  163. }
  164. /*
  165.  * Return charset_title from charset_name
  166.  */
  167. gchar *Charset_Get_Title_From_Name (gchar *charset_name)
  168. {
  169. guint i;
  170. if (charset_name)
  171. for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
  172. if ( strcasecmp(charset_name,charset_trans_array[i].charset_name) == 0 )
  173. return _(charset_trans_array[i].charset_title);
  174. return "";
  175. }