]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /** @file\r |
2 | Wide character classification and conversion functions.\r | |
3 | \r | |
4 | Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials are licensed and made available under\r | |
6 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
7 | The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | Copyright (c) 1989 The Regents of the University of California.\r | |
14 | All rights reserved.\r | |
15 | (c) UNIX System Laboratories, Inc.\r | |
16 | All or some portions of this file are derived from material licensed\r | |
17 | to the University of California by American Telephone and Telegraph\r | |
18 | Co. or Unix System Laboratories, Inc. and are reproduced herein with\r | |
19 | the permission of UNIX System Laboratories, Inc.\r | |
20 | \r | |
21 | Redistribution and use in source and binary forms, with or without\r | |
22 | modification, are permitted provided that the following conditions\r | |
23 | are met:\r | |
24 | 1. Redistributions of source code must retain the above copyright\r | |
25 | notice, this list of conditions and the following disclaimer.\r | |
26 | 2. Redistributions in binary form must reproduce the above copyright\r | |
27 | notice, this list of conditions and the following disclaimer in the\r | |
28 | documentation and/or other materials provided with the distribution.\r | |
29 | 3. Neither the name of the University nor the names of its contributors\r | |
30 | may be used to endorse or promote products derived from this software\r | |
31 | without specific prior written permission.\r | |
32 | \r | |
33 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r | |
34 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
35 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
36 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r | |
37 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r | |
38 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r | |
39 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
40 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r | |
41 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r | |
42 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r | |
43 | SUCH DAMAGE.\r | |
44 | \r | |
45 | NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp\r | |
46 | **/\r | |
47 | #include <LibConfig.h>\r | |
48 | #include <sys/EfiCdefs.h>\r | |
49 | #if defined(LIBC_SCCS) && !defined(lint)\r | |
50 | __RCSID("$NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp $");\r | |
51 | #endif /* LIBC_SCCS and not lint */\r | |
52 | \r | |
53 | #include <ctype.h>\r | |
54 | #include <string.h>\r | |
55 | #include <wchar.h>\r | |
56 | #include <wctype.h>\r | |
57 | \r | |
58 | #undef iswalnum\r | |
59 | int\r | |
60 | iswalnum(wint_t c)\r | |
61 | {\r | |
62 | return isalnum((int)c);\r | |
63 | }\r | |
64 | \r | |
65 | #undef iswalpha\r | |
66 | int\r | |
67 | iswalpha(wint_t c)\r | |
68 | {\r | |
69 | return isalpha((int)c);\r | |
70 | }\r | |
71 | \r | |
72 | #undef iswblank\r | |
73 | int\r | |
74 | iswblank(wint_t c)\r | |
75 | {\r | |
76 | return isblank((int)c);\r | |
77 | }\r | |
78 | \r | |
79 | #undef iswcntrl\r | |
80 | int\r | |
81 | iswcntrl(wint_t c)\r | |
82 | {\r | |
83 | return iscntrl((int)c);\r | |
84 | }\r | |
85 | \r | |
86 | #undef iswdigit\r | |
87 | int\r | |
88 | iswdigit(wint_t c)\r | |
89 | {\r | |
90 | return isdigit((int)c);\r | |
91 | }\r | |
92 | \r | |
93 | #undef iswgraph\r | |
94 | int\r | |
95 | iswgraph(wint_t c)\r | |
96 | {\r | |
97 | return isgraph((int)c);\r | |
98 | }\r | |
99 | \r | |
100 | #undef iswlower\r | |
101 | int\r | |
102 | iswlower(wint_t c)\r | |
103 | {\r | |
104 | return islower((int)c);\r | |
105 | }\r | |
106 | \r | |
107 | #undef iswprint\r | |
108 | int\r | |
109 | iswprint(wint_t c)\r | |
110 | {\r | |
111 | return isprint((int)c);\r | |
112 | }\r | |
113 | \r | |
114 | #undef iswpunct\r | |
115 | int\r | |
116 | iswpunct(wint_t c)\r | |
117 | {\r | |
118 | return ispunct((int)c);\r | |
119 | }\r | |
120 | \r | |
121 | #undef iswspace\r | |
122 | int\r | |
123 | iswspace(wint_t c)\r | |
124 | {\r | |
125 | return isspace((int)c);\r | |
126 | }\r | |
127 | \r | |
128 | #undef iswupper\r | |
129 | int\r | |
130 | iswupper(wint_t c)\r | |
131 | {\r | |
132 | return isupper((int)c);\r | |
133 | }\r | |
134 | \r | |
135 | #undef iswxdigit\r | |
136 | int\r | |
137 | iswxdigit(wint_t c)\r | |
138 | {\r | |
139 | return isxdigit((int)c);\r | |
140 | }\r | |
141 | \r | |
142 | #undef towupper\r | |
143 | wint_t\r | |
144 | towupper(wint_t c)\r | |
145 | {\r | |
146 | return toupper((int)c);\r | |
147 | }\r | |
148 | \r | |
149 | #undef towlower\r | |
150 | wint_t\r | |
151 | towlower(wint_t c)\r | |
152 | {\r | |
153 | return tolower((int)c);\r | |
154 | }\r | |
155 | \r | |
156 | #undef wcwidth\r | |
157 | int\r | |
158 | /*ARGSUSED*/\r | |
159 | wcwidth(wchar_t c)\r | |
160 | {\r | |
161 | return 1;\r | |
162 | }\r | |
163 | \r | |
164 | #undef iswctype\r | |
165 | int\r | |
166 | iswctype(wint_t c, wctype_t charclass)\r | |
167 | {\r | |
168 | /*\r | |
169 | * SUSv3: If charclass is 0, iswctype() shall return 0.\r | |
170 | */\r | |
171 | return (__isCClass((int)c, (unsigned int)charclass));\r | |
172 | }\r | |
173 | \r | |
174 | // Additional functions in <wctype.h> but not in NetBSD _sb code.\r | |
175 | static\r | |
176 | struct _typestrval {\r | |
177 | char *name;\r | |
178 | wctype_t value;\r | |
179 | } typestrval[] = {\r | |
180 | { "alnum", (_CD | _CU | _CL | _XA) },\r | |
181 | { "alpha", (_CU | _CL | _XA) },\r | |
182 | { "blank", (_CB) },\r | |
183 | { "cntrl", (_CC) },\r | |
184 | { "digit", (_CD) },\r | |
185 | { "graph", (_CG) },\r | |
186 | { "lower", (_CL) },\r | |
187 | { "print", (_CS | _CG) },\r | |
188 | { "punct", (_CP) },\r | |
189 | { "space", (_CW) },\r | |
190 | { "upper", (_CU) },\r | |
191 | { "xdigit", (_CD | _CX) }\r | |
192 | };\r | |
193 | \r | |
194 | #define NUM_PROPVAL (sizeof(typestrval) / sizeof(struct _typestrval))\r | |
195 | \r | |
196 | static\r | |
197 | struct _transtrval {\r | |
198 | char *name;\r | |
199 | wctrans_t function;\r | |
200 | } transtrval[] = {\r | |
201 | { "tolower", towlower },\r | |
202 | { "toupper", towupper }\r | |
203 | };\r | |
204 | \r | |
205 | #define NUM_TRANSVAL (sizeof(transtrval) / sizeof(struct _transtrval))\r | |
206 | \r | |
207 | wctype_t wctype(const char *property)\r | |
208 | {\r | |
209 | int i;\r | |
210 | \r | |
211 | for(i = 0; i < NUM_PROPVAL; ++i) {\r | |
212 | if( strcmp(typestrval[i].name, property) == 0) {\r | |
213 | return typestrval[i].value;\r | |
214 | }\r | |
215 | }\r | |
216 | return 0;\r | |
217 | }\r | |
218 | \r | |
219 | wint_t towctrans(wint_t p1, wctrans_t tranfunc)\r | |
220 | {\r | |
221 | return tranfunc(p1);\r | |
222 | }\r | |
223 | \r | |
224 | wctrans_t wctrans(const char *property)\r | |
225 | {\r | |
226 | int i;\r | |
227 | \r | |
228 | for(i = 0; i < NUM_TRANSVAL; ++i) {\r | |
229 | if( strcmp(transtrval[i].name, property) == 0) {\r | |
230 | return transtrval[i].function;\r | |
231 | }\r | |
232 | }\r | |
233 | return NULL;\r | |
234 | }\r |