1 /* -*- Mode: C; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3 -*- */ 2 3 /* 4 * GImageView 5 * Copyright (C) 2001 Takuro Ashie 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 * 21 * $Id: charset.h,v 1.10 2004/09/21 08:44:31 makeinu Exp $ 22 */ 23 24 #ifndef __CHARSET_H__ 25 #define __CHARSET_H__ 26 27 #ifdef HAVE_CONFIG_H 28 # include "config.h" 29 #endif 30 31 #include <glib.h> 32 33 34 #ifdef USE_GTK2 35 #else 36 typedef guint32 gunichar; 37 38 gboolean g_utf8_validate (const gchar *str, 39 gssize max_len, 40 const gchar **end); 41 #endif 42 43 44 #define CHARSET_ASCII "US-ASCII" 45 #define CHARSET_UTF8 "UTF-8" 46 47 /* japanese character set */ 48 #define CHARSET_SJIS "SHIFT_JIS" 49 #define CHARSET_EUC_JP "EUC-JP" 50 #define CHARSET_JIS "ISO-2022-JP" 51 52 /* for detecting locale charset */ 53 typedef const gchar *(*CharsetDetectLocaleFn) (const gchar *locale); 54 /* for auto detecting charset */ 55 typedef const gchar *(*CharsetAutoDetectFn) (const gchar *string); 56 /* for alternative character set conversion method */ 57 typedef gchar *(*CharsetConvFn) (const gchar *string, 58 const gchar *src_codeset, 59 const gchar *dest_codeset); 60 61 62 typedef enum { 63 CHARSET_TO_INTERNAL_NEVER, /* do not convert */ 64 CHARSET_TO_INTERNAL_LOCALE, /* convert to locale charset */ 65 CHARSET_TO_INTERNAL_AUTO, /* use auto detect function */ 66 CHARSET_TO_INTERNAL_ANY /* convert from specified charset */ 67 } CharsetToInternalTypes; 68 69 typedef enum { 70 CHARSET_TO_LOCALE_NEVER, 71 CHARSET_TO_LOCALE_INTERNAL, 72 CHARSET_TO_LOCALE_AUTO, 73 CHARSET_TO_LOCALE_ANY 74 } CharsetToLocaleTypes; 75 76 typedef enum { 77 CHARSET_AUTODETECT_NONE, 78 CHARSET_AUTODETECT_JAPANESE 79 } CharsetAutoDetectType; 80 81 extern const gchar *charset_auto_detect_labels[]; 82 83 84 GList *charset_get_known_list (const gchar *lang); 85 const gchar *get_lang (void); 86 87 /* wrapper for nl_langinfo() */ 88 void charset_set_locale_charset (const gchar *charset); 89 void charset_set_internal_charset (const gchar *charset); 90 const gchar *charset_get_locale (void); 91 const gchar *charset_get_internal (void); 92 CharsetAutoDetectFn charset_get_auto_detect_func (CharsetAutoDetectType type); 93 94 95 /* 96 * any code -> internal converter 97 */ 98 99 /* wrapper for all converter */ 100 /* src_codeset can be NULL if type is not CHARSET_TO_INTERNAL_ANY */ 101 /* func can be NULL if type is not CHARSET_TO_INTERNAL_AUTO */ 102 gchar *charset_to_internal (const gchar *src, 103 const gchar *src_codeset, 104 CharsetAutoDetectFn func, 105 CharsetToInternalTypes type); 106 107 gchar *charset_locale_to_internal (const gchar *src); 108 gchar *charset_to_internal_auto (const gchar *src, 109 CharsetAutoDetectFn func); 110 111 /* 112 * any code -> locale converter 113 */ 114 115 /* wrapper for all converter */ 116 /* src_codeset can be NULL if type is not CHARSET_TO_INTERNAL_ANY */ 117 /* func can be NULL if type is not CHARSET_TO_INTERNAL_AUTO */ 118 gchar *charset_to_locale (const gchar *src, 119 const gchar *src_codeset, 120 CharsetAutoDetectFn func, 121 CharsetToLocaleTypes type); 122 123 gchar *charset_internal_to_locale (const gchar *src); 124 gchar *charset_to_locale_auto (const gchar *src, 125 CharsetAutoDetectFn func); 126 127 /* 128 * internal -> any code converter 129 */ 130 gchar *charset_from_internal (const gchar *src, 131 const gchar *dest_codeset); 132 133 /* 134 * locale -> any code converter 135 */ 136 gchar *charset_from_locale (const gchar *src, 137 const gchar *dest_codeset); 138 139 /* 140 * any -> any code converter 141 */ 142 gchar *charset_conv (const gchar *src, 143 const gchar *src_codeset, 144 const gchar *dest_codeset); 145 gchar *charset_conv_auto (const gchar *src, 146 const gchar *dest_codeset, 147 CharsetAutoDetectFn func); 148 149 #endif /* __CHARSET_H__ */ 150