2 * fribidi-char-sets.c - character set conversion routines
5 * Behdad Esfahbod, 2001, 2002, 2004
6 * Dov Grobgeld, 1999, 2000
8 * Copyright (C) 2004 Sharif FarsiWeb, Inc
9 * Copyright (C) 2001,2002 Behdad Esfahbod
10 * Copyright (C) 1999,2000 Dov Grobgeld
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library, in a file named COPYING; if not, write to the
24 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA
27 * For licensing issues, contact <fribidi.license@gmail.com>.
32 #include <fribidi-char-sets.h>
34 #include "fribidi-char-sets-cap-rtl.h"
35 #include "fribidi-char-sets-utf8.h"
36 #include "fribidi-char-sets-iso8859-6.h"
37 #include "fribidi-char-sets-cp1256.h"
38 #include "fribidi-char-sets-iso8859-8.h"
39 #include "fribidi-char-sets-cp1255.h"
66 const FriBidiChar *us,
81 FriBidiCharSetHandler;
83 static FriBidiCharSetHandler char_sets[FRIBIDI_CHAR_SETS_NUM + 1] = {
84 {NULL, NULL, NULL, NULL, "N/A", "Character set not available", NULL},
85 # define _FRIBIDI_ADD_CHAR_SET_ONE2ONE(CHAR_SET, char_set) \
87 fribidi_##char_set##_to_unicode_c, \
89 fribidi_unicode_to_##char_set##_c, \
91 fribidi_char_set_name_##char_set, \
92 fribidi_char_set_title_##char_set, \
93 fribidi_char_set_desc_##char_set \
95 # define _FRIBIDI_ADD_CHAR_SET_OTHERS(CHAR_SET, char_set) \
98 fribidi_##char_set##_to_unicode, \
100 fribidi_unicode_to_##char_set, \
101 fribidi_char_set_name_##char_set, \
102 fribidi_char_set_title_##char_set, \
103 fribidi_char_set_desc_##char_set \
105 # include <fribidi-char-sets-list.h>
106 # undef _FRIBIDI_ADD_CHAR_SET_OTHERS
107 # undef _FRIBIDI_ADD_CHAR_SET_ONE2ONE
116 return c < 'a' || c > 'z' ? c : c + 'A' - 'a';
126 while (*s1 && fribidi_toupper (*s1) == fribidi_toupper (*s2))
131 return fribidi_toupper (*s1) - fribidi_toupper (*s2);
134 FRIBIDI_ENTRY FriBidiCharSet
135 fribidi_parse_charset (
142 for (i = FRIBIDI_CHAR_SETS_NUM; i; i--)
143 if (fribidi_strcasecmp (s, char_sets[i].name) == 0)
146 return FRIBIDI_CHAR_SET_NOT_FOUND;
149 FRIBIDI_ENTRY FriBidiStrIndex
150 fribidi_charset_to_unicode (
152 FriBidiCharSet char_set,
159 if (char_sets[char_set].charset_to_unicode)
160 return (*char_sets[char_set].charset_to_unicode) (s, len, us);
161 else if (char_sets[char_set].charset_to_unicode_c)
163 register FriBidiStrIndex l;
164 for (l = len; l; l--)
165 *us++ = (*char_sets[char_set].charset_to_unicode_c) (*s++);
172 FRIBIDI_ENTRY FriBidiStrIndex
173 fribidi_unicode_to_charset (
175 FriBidiCharSet char_set,
176 const FriBidiChar *us,
182 if (char_sets[char_set].unicode_to_charset)
183 return (*char_sets[char_set].unicode_to_charset) (us, len, s);
184 else if (char_sets[char_set].unicode_to_charset_c)
186 register FriBidiStrIndex l;
187 for (l = len; l; l--)
188 *s++ = (*char_sets[char_set].unicode_to_charset_c) (*us++);
196 FRIBIDI_ENTRY const char *
197 fribidi_char_set_name (
199 FriBidiCharSet char_set
202 return char_sets[char_set].name ? char_sets[char_set].name : "";
205 FRIBIDI_ENTRY const char *
206 fribidi_char_set_title (
208 FriBidiCharSet char_set
211 return char_sets[char_set].title ? char_sets[char_set].
212 title : fribidi_char_set_name (char_set);
215 FRIBIDI_ENTRY const char *
216 fribidi_char_set_desc (
218 FriBidiCharSet char_set
221 return char_sets[char_set].desc ? char_sets[char_set].desc () : NULL;
224 /* Editor directions:
225 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent