update nearly all FSF copyright year lists to include 2010
[gnulib.git] / lib / unictype / categ_byname.c
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.
4
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.
9
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.
14
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/>.  */
17
18 #include <config.h>
19
20 /* Specification.  */
21 #include "unictype.h"
22
23 uc_general_category_t
24 uc_general_category_byname (const char *category_name)
25 {
26   if (category_name[0] != '\0'
27       && (category_name[1] == '\0' || category_name[2] == '\0'))
28     switch (category_name[0])
29       {
30       case 'L':
31         switch (category_name[1])
32           {
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;
39           }
40         break;
41       case 'M':
42         switch (category_name[1])
43           {
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;
48           }
49         break;
50       case 'N':
51         switch (category_name[1])
52           {
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;
57           }
58         break;
59       case 'P':
60         switch (category_name[1])
61           {
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;
70           }
71         break;
72       case 'S':
73         switch (category_name[1])
74           {
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;
80           }
81         break;
82       case 'Z':
83         switch (category_name[1])
84           {
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;
89           }
90         break;
91       case 'C':
92         switch (category_name[1])
93           {
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;
100           }
101         break;
102       }
103   /* Invalid category name.  */
104   return _UC_CATEGORY_NONE;
105 }