2 * fribidi-char-sets.c - character set conversion routines
4 * $Id: fribidi-char-sets.c,v 1.7 2006-01-31 03:23:12 behdad Exp $
6 * $Date: 2006-01-31 03:23:12 $
8 * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/charset/fribidi-char-sets.c,v $
11 * Behdad Esfahbod, 2001, 2002, 2004
12 * Dov Grobgeld, 1999, 2000
14 * Copyright (C) 2004 Sharif FarsiWeb, Inc
15 * Copyright (C) 2001,2002 Behdad Esfahbod
16 * Copyright (C) 1999,2000 Dov Grobgeld
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with this library, in a file named COPYING; if not, write to the
30 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31 * Boston, MA 02110-1301, USA
33 * For licensing issues, contact <license@farsiweb.info>.
38 #include <fribidi-char-sets.h>
40 #include "fribidi-char-sets-cap-rtl.h"
41 #include "fribidi-char-sets-utf8.h"
42 #include "fribidi-char-sets-iso8859-6.h"
43 #include "fribidi-char-sets-cp1256.h"
44 #include "fribidi-char-sets-iso8859-8.h"
45 #include "fribidi-char-sets-cp1255.h"
72 const FriBidiChar *us,
87 FriBidiCharSetHandler;
89 static FriBidiCharSetHandler char_sets[FRIBIDI_CHAR_SETS_NUM + 1] = {
90 {NULL, NULL, NULL, NULL, "N/A", "Character set not available", NULL},
91 # define _FRIBIDI_ADD_CHAR_SET_ONE2ONE(CHAR_SET, char_set) \
93 fribidi_##char_set##_to_unicode_c, \
95 fribidi_unicode_to_##char_set##_c, \
97 fribidi_char_set_name_##char_set, \
98 fribidi_char_set_title_##char_set, \
99 fribidi_char_set_desc_##char_set \
101 # define _FRIBIDI_ADD_CHAR_SET_OTHERS(CHAR_SET, char_set) \
104 fribidi_##char_set##_to_unicode, \
106 fribidi_unicode_to_##char_set, \
107 fribidi_char_set_name_##char_set, \
108 fribidi_char_set_title_##char_set, \
109 fribidi_char_set_desc_##char_set \
111 # include <fribidi-char-sets-list.h>
112 # undef _FRIBIDI_ADD_CHAR_SET_OTHERS
113 # undef _FRIBIDI_ADD_CHAR_SET_ONE2ONE
116 #if FRIBIDI_USE_GLIB+0
118 # define fribidi_strcasecmp g_ascii_strcasecmp
119 #else /* !FRIBIDI_USE_GLIB */
126 return c < 'a' || c > 'z' ? c : c + 'A' - 'a';
136 while (*s1 && toupper (*s1) == toupper (*s2))
141 return toupper (*s1) - toupper (*s2);
143 #endif /* !FRIBIDI_USE_GLIB */
145 FRIBIDI_ENTRY FriBidiCharSet
146 fribidi_parse_charset (
153 for (i = FRIBIDI_CHAR_SETS_NUM; i; i--)
154 if (fribidi_strcasecmp (s, char_sets[i].name) == 0)
157 return FRIBIDI_CHAR_SET_NOT_FOUND;
160 FRIBIDI_ENTRY FriBidiStrIndex
161 fribidi_charset_to_unicode (
163 FriBidiCharSet char_set,
170 if (char_sets[char_set].charset_to_unicode)
171 return (*char_sets[char_set].charset_to_unicode) (s, len, us);
172 else if (char_sets[char_set].charset_to_unicode_c)
174 register FriBidiStrIndex l;
175 for (l = len; l; l--)
176 *us++ = (*char_sets[char_set].charset_to_unicode_c) (*s++);
183 FRIBIDI_ENTRY FriBidiStrIndex
184 fribidi_unicode_to_charset (
186 FriBidiCharSet char_set,
187 const FriBidiChar *us,
193 if (char_sets[char_set].unicode_to_charset)
194 return (*char_sets[char_set].unicode_to_charset) (us, len, s);
195 else if (char_sets[char_set].unicode_to_charset_c)
197 register FriBidiStrIndex l;
198 for (l = len; l; l--)
199 *s++ = (*char_sets[char_set].unicode_to_charset_c) (*us++);
207 FRIBIDI_ENTRY const char *
208 fribidi_char_set_name (
210 FriBidiCharSet char_set
213 return char_sets[char_set].name ? char_sets[char_set].name : "";
216 FRIBIDI_ENTRY const char *
217 fribidi_char_set_title (
219 FriBidiCharSet char_set
222 return char_sets[char_set].title ? char_sets[char_set].
223 title : fribidi_char_set_name (char_set);
226 FRIBIDI_ENTRY const char *
227 fribidi_char_set_desc (
229 FriBidiCharSet char_set
232 return char_sets[char_set].desc ? char_sets[char_set].desc () : NULL;
235 /* Editor directions:
236 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent