1 /* tag: Tom Lord Tue Dec  4 14:41:37 2001 (unidata.c)
2  */
3 /* unidata.c -
4  *
5  ****************************************************************
6  * Copyright (C) 2000 Tom Lord
7  *
8  * See the file "COPYING" for further information about
9  * the copyright and warranty status of this work.
10  */
11 
12 
13 #include "hackerlab/char/str.h"
14 #include "hackerlab/uni/unidata.h"
15 
16 
17 /*(c uni_bidi_category)
18  * enum uni_bidi_categories;
19  *
20  * An enumeration of the bi-directional classifications of
21  * of Unicode characters.
22  *
23  * (See the *Unicode 3.0* specification for more information
24  * on the meaning of these categories.)
25  *
26  * Each category name is formed by prefixing `uni_bidi_' to
27  * a category name (`L', `LRE', etc.):
28  *
29  * 	uni_bidi_L
30  * 	uni_bidi_LRE
31  * 	etc.
32  *
33  * The macro `UNI_BIDI_CATEGORIES' may also be handy:
34  *
35  */
36 
37 
38 #undef UNI_BIDI_CATEGORY
39 #define UNI_BIDI_CATEGORY(n,ign)	{ #n, uni_bidi_ ## n },
40 const struct uni_bidi_category_name uni_bidi_category_names[] =
41 {
42   UNI_BIDI_CATEGORIES
43     {0, 0}
44 };
45 
46 const int n_uni_bidi_categories = sizeof (uni_bidi_category_names) / sizeof (struct uni_bidi_category_name);
47 
48 
49 /*(c uni_bidi_category_lookup_n)
50  * int uni_bidi_category_lookup_n (t_uchar * name, size_t len);
51  *
52  * Given the name of a bidirectional category (e.g. "l"), return the
53  * corresponding `enum uni_bidi_category'.  If `name' is not valid,
54  * return -1.
55  *
56  * `name' -- the bidi category name to look up.
57  * `len' -- the length of `name' in bytes.
58  */
59 int
uni_bidi_category_lookup_n(t_uchar * name,size_t len)60 uni_bidi_category_lookup_n (t_uchar * name, size_t len)
61 {
62   int x;
63 
64   for (x = 0; x < n_uni_bidi_categories; ++x)
65     {
66       if (!str_casecmp_n (uni_bidi_category_names[x].name, str_length (uni_bidi_category_names[x].name), name, len))
67 	return uni_bidi_category_names[x].category;
68     }
69 
70   return -1;
71 }
72 
73 
74 
75 /*(c uni_bidi_category_lookup)
76  * int uni_bidi_category_lookup (t_uchar * name);
77  *
78  * Given the name of a bidirectional category (e.g. "l"), return the
79  * corresponding `enum uni_bidi_category'.  IF `name' is not valid,
80  * return -1.
81  *
82  * `name' -- the bidi category name to look up (0-terminated).
83  */
84 int
uni_bidi_category_lookup(t_uchar * name)85 uni_bidi_category_lookup (t_uchar * name)
86 {
87   return uni_bidi_category_lookup_n (name, str_length (name));
88 }
89 
90 
91 
92 
93 const struct uni_general_category_name uni_general_category_names[] =
94 {
95 #define UNI_GENERAL_CATEGORY_NAME(NAME, ALT_NAME, DESC) \
96 	{ #NAME, uni_general_category_##NAME },
97 #define UNI_SYNTH_CATEGORY_NAME(NAME, ALT_NAME, DESC) \
98 	{ #NAME, uni_general_category_##NAME },
99 
100   UNI_GENERAL_CATEGORIES_LIST(_NAME)
101   UNI_SYNTHETIC_CATEGORIES_LIST(_NAME)
102     {0, 0}
103 };
104 
105 const enum uni_general_category uni_first_synthetic_category = uni_general_category_L;
106 const int uni_n_categories = (uni_general_category_symbol + 1);
107 
108 
109 int
uni_general_category_lookup_n(t_uchar * name,size_t len)110 uni_general_category_lookup_n (t_uchar * name, size_t len)
111 {
112   int x;
113   for (x = 0; uni_general_category_names[x].name; ++x)
114     if (!str_casecmp_n (name, len, uni_general_category_names[x].name, str_length (uni_general_category_names[x].name)))
115       return uni_general_category_names[x].category;
116 
117   return -1;
118 }
119 
120 
121 int
uni_general_category_lookup(t_uchar * name)122 uni_general_category_lookup (t_uchar * name)
123 {
124   return uni_general_category_lookup_n (name, str_length (name));
125 }
126 
127 
128 
129 #undef UNI_DECOMPOSITION_TYPE
130 #define UNI_DECOMPOSITION_TYPE(n)	{ #n, uni_decomposition_ ## n },
131 const struct uni_decomposition_type_name uni_decomposition_type_names[] =
132 {
133   UNI_DECOMPOSITION_TYPES
134     {0, 0}
135 };
136 
137 const int n_uni_decomposition_types = sizeof (uni_decomposition_type_names) / sizeof (struct uni_decomposition_type_name);
138 
139 
140 /*(c uni_decomposition_type_lookup_n)
141  * int uni_decomposition_type_lookup_n (t_uchar * name, size_t len);
142  *
143  * Given the name of a decomposition mapping type (e.g. "font"), return the
144  * corresponding `enum uni_decomposition_type'.  If `name' is not valid,
145  * return -1.
146  *
147  * `name' -- the bidi category name to look up.
148  * `len' -- the length of `name' in bytes.
149  */
150 int
uni_decomposition_type_lookup_n(t_uchar * name,size_t len)151 uni_decomposition_type_lookup_n (t_uchar * name, size_t len)
152 {
153   int x;
154 
155   for (x = 0; x < n_uni_bidi_categories; ++x)
156     {
157       if (!str_casecmp_n (uni_decomposition_type_names[x].name, str_length (uni_decomposition_type_names[x].name), name, len))
158 	return uni_decomposition_type_names[x].category;
159     }
160 
161   return -1;
162 }
163 
164 
165 
166 /*(c uni_decomposition_type_lookup)
167  * int uni_decomposition_type_lookup (t_uchar * name);
168  *
169  * Given the name of a bidirectional category (e.g. "l"), return the
170  * corresponding `enum uni_decomposition_type'.  If `name' is not valid,
171  * return -1.
172  *
173  * `name' -- the bidi category name to look up (0-terminated).
174  */
175 int
uni_decomposition_type_lookup(t_uchar * name)176 uni_decomposition_type_lookup (t_uchar * name)
177 {
178   return uni_decomposition_type_lookup_n (name, str_length (name));
179 }
180