1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
/* FriBidi
* fribidi-char-sets.c - character set conversion routines
*
* $Id: fribidi-char-sets.c,v 1.7 2006-01-31 03:23:12 behdad Exp $
* $Author: behdad $
* $Date: 2006-01-31 03:23:12 $
* $Revision: 1.7 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/charset/fribidi-char-sets.c,v $
*
* Authors:
* Behdad Esfahbod, 2001, 2002, 2004
* Dov Grobgeld, 1999, 2000
*
* Copyright (C) 2004 Sharif FarsiWeb, Inc
* Copyright (C) 2001,2002 Behdad Esfahbod
* Copyright (C) 1999,2000 Dov Grobgeld
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library, in a file named COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA
*
* For licensing issues, contact <fribidi.license@gmail.com>.
*/
#include <common.h>
#include <fribidi-char-sets.h>
#include "fribidi-char-sets-cap-rtl.h"
#include "fribidi-char-sets-utf8.h"
#include "fribidi-char-sets-iso8859-6.h"
#include "fribidi-char-sets-cp1256.h"
#include "fribidi-char-sets-iso8859-8.h"
#include "fribidi-char-sets-cp1255.h"
typedef struct
{
FriBidiChar (
*charset_to_unicode_c
) (
char ch
);
FriBidiStrIndex (
*charset_to_unicode
) (
const char *s,
FriBidiStrIndex len,
FriBidiChar *us
);
char (
*unicode_to_charset_c
) (
FriBidiChar uch
);
FriBidiStrIndex (
*unicode_to_charset
) (
const FriBidiChar *us,
FriBidiStrIndex len,
char *s
);
const char *name;
const char *title;
const char *(
*desc
) (
void
);
}
FriBidiCharSetHandler;
static FriBidiCharSetHandler char_sets[FRIBIDI_CHAR_SETS_NUM + 1] = {
{NULL, NULL, NULL, NULL, "N/A", "Character set not available", NULL},
# define _FRIBIDI_ADD_CHAR_SET_ONE2ONE(CHAR_SET, char_set) \
{ \
fribidi_##char_set##_to_unicode_c, \
NULL, \
fribidi_unicode_to_##char_set##_c, \
NULL, \
fribidi_char_set_name_##char_set, \
fribidi_char_set_title_##char_set, \
fribidi_char_set_desc_##char_set \
},
# define _FRIBIDI_ADD_CHAR_SET_OTHERS(CHAR_SET, char_set) \
{ \
NULL, \
fribidi_##char_set##_to_unicode, \
NULL, \
fribidi_unicode_to_##char_set, \
fribidi_char_set_name_##char_set, \
fribidi_char_set_title_##char_set, \
fribidi_char_set_desc_##char_set \
},
# include <fribidi-char-sets-list.h>
# undef _FRIBIDI_ADD_CHAR_SET_OTHERS
# undef _FRIBIDI_ADD_CHAR_SET_ONE2ONE
};
static char
fribidi_toupper (
/* input */
char c
)
{
return c < 'a' || c > 'z' ? c : c + 'A' - 'a';
}
static int
fribidi_strcasecmp (
/* input */
const char *s1,
const char *s2
)
{
while (*s1 && fribidi_toupper (*s1) == fribidi_toupper (*s2))
{
s1++;
s2++;
}
return fribidi_toupper (*s1) - fribidi_toupper (*s2);
}
FRIBIDI_ENTRY FriBidiCharSet
fribidi_parse_charset (
/* input */
const char *s
)
{
int i;
for (i = FRIBIDI_CHAR_SETS_NUM; i; i--)
if (fribidi_strcasecmp (s, char_sets[i].name) == 0)
return i;
return FRIBIDI_CHAR_SET_NOT_FOUND;
}
FRIBIDI_ENTRY FriBidiStrIndex
fribidi_charset_to_unicode (
/* input */
FriBidiCharSet char_set,
const char *s,
FriBidiStrIndex len,
/* output */
FriBidiChar *us
)
{
if (char_sets[char_set].charset_to_unicode)
return (*char_sets[char_set].charset_to_unicode) (s, len, us);
else if (char_sets[char_set].charset_to_unicode_c)
{
register FriBidiStrIndex l;
for (l = len; l; l--)
*us++ = (*char_sets[char_set].charset_to_unicode_c) (*s++);
return len;
}
else
return 0;
}
FRIBIDI_ENTRY FriBidiStrIndex
fribidi_unicode_to_charset (
/* input */
FriBidiCharSet char_set,
const FriBidiChar *us,
FriBidiStrIndex len,
/* output */
char *s
)
{
if (char_sets[char_set].unicode_to_charset)
return (*char_sets[char_set].unicode_to_charset) (us, len, s);
else if (char_sets[char_set].unicode_to_charset_c)
{
register FriBidiStrIndex l;
for (l = len; l; l--)
*s++ = (*char_sets[char_set].unicode_to_charset_c) (*us++);
*s = '\0';
return len;
}
else
return 0;
}
FRIBIDI_ENTRY const char *
fribidi_char_set_name (
/* input */
FriBidiCharSet char_set
)
{
return char_sets[char_set].name ? char_sets[char_set].name : "";
}
FRIBIDI_ENTRY const char *
fribidi_char_set_title (
/* input */
FriBidiCharSet char_set
)
{
return char_sets[char_set].title ? char_sets[char_set].
title : fribidi_char_set_name (char_set);
}
FRIBIDI_ENTRY const char *
fribidi_char_set_desc (
/* input */
FriBidiCharSet char_set
)
{
return char_sets[char_set].desc ? char_sets[char_set].desc () : NULL;
}
/* Editor directions:
* vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
*/
|