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