1 /* FriBidi
2 * fribidi-bidi-types.c - character bidi types
3 *
4 * Authors:
5 * Behdad Esfahbod, 2001, 2002, 2004
6 *
7 * Copyright (C) 2004 Sharif FarsiWeb, Inc.
8 * Copyright (C) 2001,2002 Behdad Esfahbod
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library, in a file named COPYING; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA
24 *
25 * For licensing issues, contact <fribidi.license@gmail.com>.
26 */
27
28 #include "common.h"
29
30 #include <fribidi-bidi-types.h>
31
32 #include "bidi-types.h"
33
34 enum FriBidiCharTypeLinearEnum
35 {
36 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE,
37 # include "fribidi-bidi-types-list.h"
38 # undef _FRIBIDI_ADD_TYPE
39 _FRIBIDI_NUM_TYPES
40 };
41
42 #include "bidi-type.tab.i"
43
44 /* Map FriBidiCharTypeLinearEnum to FriBidiCharType. */
45 static const FriBidiCharType linear_enum_to_char_type[] = {
46 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) FRIBIDI_TYPE_##TYPE,
47 # include "fribidi-bidi-types-list.h"
48 # undef _FRIBIDI_ADD_TYPE
49 };
50
51 FRIBIDI_ENTRY FriBidiCharType
52 fribidi_get_bidi_type (
53 /* input */
54 FriBidiChar ch
55 )
56 {
57 return linear_enum_to_char_type[FRIBIDI_GET_BIDI_TYPE (ch)];
58 }
59
60 FRIBIDI_ENTRY void
61 fribidi_get_bidi_types (
62 /* input */
63 const FriBidiChar *str,
64 const FriBidiStrIndex len,
65 /* output */
66 FriBidiCharType *btypes
67 )
68 {
69 register FriBidiStrIndex i = len;
70 for (; i; i--)
71 {
72 *btypes++ = linear_enum_to_char_type[FRIBIDI_GET_BIDI_TYPE (*str)];
73 str++;
74 }
75 }
76
77 FRIBIDI_ENTRY const char *
78 fribidi_get_bidi_type_name (
79 /* input */
80 FriBidiCharType t
81 )
82 {
83 switch ((int)t)
84 {
85 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) case FRIBIDI_TYPE_##TYPE: return STRINGIZE(TYPE);
86 # define _FRIBIDI_ALL_TYPES
87 # include "fribidi-bidi-types-list.h"
88 # undef _FRIBIDI_ALL_TYPES
89 # undef _FRIBIDI_ADD_TYPE
90 default:
91 return "?";
92 }
93 }
94
95 #ifdef DEBUG
96
97 char
98 fribidi_char_from_bidi_type (
99 /* input */
100 FriBidiCharType t
101 )
102 {
103 switch ((int)t)
104 {
105 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) case FRIBIDI_TYPE_##TYPE: return SYMBOL;
106 # define _FRIBIDI_ALL_TYPES
107 # include "fribidi-bidi-types-list.h"
108 # undef _FRIBIDI_ALL_TYPES
109 # undef _FRIBIDI_ADD_TYPE
110 default:
111 return '?';
112 }
113 }
114
115 #endif /* DEBUG */
116
117 /* Editor directions:
118 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
119 */