1 /* Categories of Unicode characters.
2 Copyright (C) 2002, 2006-2007, 2009-2010 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/>. */
24 uc_general_category_byname (const char *category_name)
26 if (category_name[0] != '\0'
27 && (category_name[1] == '\0' || category_name[2] == '\0'))
28 switch (category_name[0])
31 switch (category_name[1])
33 case '\0': return UC_CATEGORY_L;
34 case 'u': return UC_CATEGORY_Lu;
35 case 'l': return UC_CATEGORY_Ll;
36 case 't': return UC_CATEGORY_Lt;
37 case 'm': return UC_CATEGORY_Lm;
38 case 'o': return UC_CATEGORY_Lo;
42 switch (category_name[1])
44 case '\0': return UC_CATEGORY_M;
45 case 'n': return UC_CATEGORY_Mn;
46 case 'c': return UC_CATEGORY_Mc;
47 case 'e': return UC_CATEGORY_Me;
51 switch (category_name[1])
53 case '\0': return UC_CATEGORY_N;
54 case 'd': return UC_CATEGORY_Nd;
55 case 'l': return UC_CATEGORY_Nl;
56 case 'o': return UC_CATEGORY_No;
60 switch (category_name[1])
62 case '\0': return UC_CATEGORY_P;
63 case 'c': return UC_CATEGORY_Pc;
64 case 'd': return UC_CATEGORY_Pd;
65 case 's': return UC_CATEGORY_Ps;
66 case 'e': return UC_CATEGORY_Pe;
67 case 'i': return UC_CATEGORY_Pi;
68 case 'f': return UC_CATEGORY_Pf;
69 case 'o': return UC_CATEGORY_Po;
73 switch (category_name[1])
75 case '\0': return UC_CATEGORY_S;
76 case 'm': return UC_CATEGORY_Sm;
77 case 'c': return UC_CATEGORY_Sc;
78 case 'k': return UC_CATEGORY_Sk;
79 case 'o': return UC_CATEGORY_So;
83 switch (category_name[1])
85 case '\0': return UC_CATEGORY_Z;
86 case 's': return UC_CATEGORY_Zs;
87 case 'l': return UC_CATEGORY_Zl;
88 case 'p': return UC_CATEGORY_Zp;
92 switch (category_name[1])
94 case '\0': return UC_CATEGORY_C;
95 case 'c': return UC_CATEGORY_Cc;
96 case 'f': return UC_CATEGORY_Cf;
97 case 's': return UC_CATEGORY_Cs;
98 case 'o': return UC_CATEGORY_Co;
99 case 'n': return UC_CATEGORY_Cn;
103 /* Invalid category name. */
104 return _UC_CATEGORY_NONE;