1 /* Categories of Unicode characters.
2 Copyright (C) 2002, 2006-2007, 2011 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2002.
5 This program is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 /* Indices stored in the 'struct named_category' elements of the perfect hash
27 table. We don't use uc_general_category_t values or their addresses
28 directly, because this would introduce load-time relocations. */
71 #include "unictype/categ_byname.h"
74 uc_general_category_byname (const char *category_name)
78 len = strlen (category_name);
79 if (len <= MAX_WORD_LENGTH)
81 char buf[MAX_WORD_LENGTH + 1];
82 const struct named_category *found;
84 /* Copy category_name into buf, converting '_' and '-' to ' '. */
86 const char *p = category_name;
93 if (c == '_' || c == '-')
100 /* Here q == buf + len. */
102 /* Do a hash table lookup, with case-insensitive comparison. */
103 found = uc_general_category_lookup (buf, len);
105 /* Use a 'switch' statement here, because a table would introduce
106 load-time relocations. */
107 switch (found->category_index)
109 case UC_CATEGORY_INDEX_L:
110 return UC_CATEGORY_L;
111 case UC_CATEGORY_INDEX_LC:
112 return UC_CATEGORY_LC;
113 case UC_CATEGORY_INDEX_Lu:
114 return UC_CATEGORY_Lu;
115 case UC_CATEGORY_INDEX_Ll:
116 return UC_CATEGORY_Ll;
117 case UC_CATEGORY_INDEX_Lt:
118 return UC_CATEGORY_Lt;
119 case UC_CATEGORY_INDEX_Lm:
120 return UC_CATEGORY_Lm;
121 case UC_CATEGORY_INDEX_Lo:
122 return UC_CATEGORY_Lo;
123 case UC_CATEGORY_INDEX_M:
124 return UC_CATEGORY_M;
125 case UC_CATEGORY_INDEX_Mn:
126 return UC_CATEGORY_Mn;
127 case UC_CATEGORY_INDEX_Mc:
128 return UC_CATEGORY_Mc;
129 case UC_CATEGORY_INDEX_Me:
130 return UC_CATEGORY_Me;
131 case UC_CATEGORY_INDEX_N:
132 return UC_CATEGORY_N;
133 case UC_CATEGORY_INDEX_Nd:
134 return UC_CATEGORY_Nd;
135 case UC_CATEGORY_INDEX_Nl:
136 return UC_CATEGORY_Nl;
137 case UC_CATEGORY_INDEX_No:
138 return UC_CATEGORY_No;
139 case UC_CATEGORY_INDEX_P:
140 return UC_CATEGORY_P;
141 case UC_CATEGORY_INDEX_Pc:
142 return UC_CATEGORY_Pc;
143 case UC_CATEGORY_INDEX_Pd:
144 return UC_CATEGORY_Pd;
145 case UC_CATEGORY_INDEX_Ps:
146 return UC_CATEGORY_Ps;
147 case UC_CATEGORY_INDEX_Pe:
148 return UC_CATEGORY_Pe;
149 case UC_CATEGORY_INDEX_Pi:
150 return UC_CATEGORY_Pi;
151 case UC_CATEGORY_INDEX_Pf:
152 return UC_CATEGORY_Pf;
153 case UC_CATEGORY_INDEX_Po:
154 return UC_CATEGORY_Po;
155 case UC_CATEGORY_INDEX_S:
156 return UC_CATEGORY_S;
157 case UC_CATEGORY_INDEX_Sm:
158 return UC_CATEGORY_Sm;
159 case UC_CATEGORY_INDEX_Sc:
160 return UC_CATEGORY_Sc;
161 case UC_CATEGORY_INDEX_Sk:
162 return UC_CATEGORY_Sk;
163 case UC_CATEGORY_INDEX_So:
164 return UC_CATEGORY_So;
165 case UC_CATEGORY_INDEX_Z:
166 return UC_CATEGORY_Z;
167 case UC_CATEGORY_INDEX_Zs:
168 return UC_CATEGORY_Zs;
169 case UC_CATEGORY_INDEX_Zl:
170 return UC_CATEGORY_Zl;
171 case UC_CATEGORY_INDEX_Zp:
172 return UC_CATEGORY_Zp;
173 case UC_CATEGORY_INDEX_C:
174 return UC_CATEGORY_C;
175 case UC_CATEGORY_INDEX_Cc:
176 return UC_CATEGORY_Cc;
177 case UC_CATEGORY_INDEX_Cf:
178 return UC_CATEGORY_Cf;
179 case UC_CATEGORY_INDEX_Cs:
180 return UC_CATEGORY_Cs;
181 case UC_CATEGORY_INDEX_Co:
182 return UC_CATEGORY_Co;
183 case UC_CATEGORY_INDEX_Cn:
184 return UC_CATEGORY_Cn;
189 /* Invalid category name. */
190 return _UC_CATEGORY_NONE;