summaryrefslogtreecommitdiff
path: root/StdLib/LibC/Locale/iswctype_sb.c
blob: 454201543fd3c8db7d16fc5697e394703b2008ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/** @file
    Wide character classification and conversion functions.

    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
    This program and the accompanying materials are licensed and made available under
    the terms and conditions of the BSD License that accompanies this distribution.
    The full text of the license may be found at
    http://opensource.org/licenses/bsd-license.php.

    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

    Copyright (c) 1989 The Regents of the University of California.
    All rights reserved.
    (c) UNIX System Laboratories, Inc.
    All or some portions of this file are derived from material licensed
    to the University of California by American Telephone and Telegraph
    Co. or Unix System Laboratories, Inc. and are reproduced herein with
    the permission of UNIX System Laboratories, Inc.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
      1. Redistributions of source code must retain the above copyright
         notice, this list of conditions and the following disclaimer.
      2. Redistributions in binary form must reproduce the above copyright
         notice, this list of conditions and the following disclaimer in the
         documentation and/or other materials provided with the distribution.
      3. Neither the name of the University nor the names of its contributors
         may be used to endorse or promote products derived from this software
         without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    SUCH DAMAGE.

    NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp
**/
#include  <LibConfig.h>
#include  <sys/EfiCdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: iswctype_sb.c,v 1.4 2004/07/21 20:27:46 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */

#include  <ctype.h>
#include  <string.h>
#include  <wchar.h>
#include  <wctype.h>

#undef iswalnum
int
iswalnum(wint_t c)
{
  return isalnum((int)c);
}

#undef iswalpha
int
iswalpha(wint_t c)
{
  return isalpha((int)c);
}

#undef iswblank
int
iswblank(wint_t c)
{
  return isblank((int)c);
}

#undef iswcntrl
int
iswcntrl(wint_t c)
{
  return iscntrl((int)c);
}

#undef iswdigit
int
iswdigit(wint_t c)
{
  return isdigit((int)c);
}

#undef iswgraph
int
iswgraph(wint_t c)
{
  return isgraph((int)c);
}

#undef iswlower
int
iswlower(wint_t c)
{
  return islower((int)c);
}

#undef iswprint
int
iswprint(wint_t c)
{
  return isprint((int)c);
}

#undef iswpunct
int
iswpunct(wint_t c)
{
  return ispunct((int)c);
}

#undef iswspace
int
iswspace(wint_t c)
{
  return isspace((int)c);
}

#undef iswupper
int
iswupper(wint_t c)
{
  return isupper((int)c);
}

#undef iswxdigit
int
iswxdigit(wint_t c)
{
  return isxdigit((int)c);
}

#undef towupper
wint_t
towupper(wint_t c)
{
  return toupper((int)c);
}

#undef towlower
wint_t
towlower(wint_t c)
{
  return tolower((int)c);
}

#undef wcwidth
int
/*ARGSUSED*/
wcwidth(wchar_t c)
{
  return 1;
}

#undef iswctype
int
iswctype(wint_t c, wctype_t charclass)
{
  /*
  * SUSv3: If charclass is 0, iswctype() shall return 0.
  */
  return (__isCClass((int)c, (unsigned int)charclass));
}

// Additional functions in <wctype.h> but not in NetBSD _sb code.
static
struct _typestrval {
  char    *name;
  wctype_t  value;
} typestrval[] = {
  { "alnum",    (_CD | _CU | _CL | _XA) },
  { "alpha",    (_CU | _CL | _XA)       },
  { "blank",    (_CB)                   },
  { "cntrl",    (_CC)                   },
  { "digit",    (_CD)                   },
  { "graph",    (_CG)                   },
  { "lower",    (_CL)                   },
  { "print",    (_CS | _CG)             },
  { "punct",    (_CP)                   },
  { "space",    (_CW)                   },
  { "upper",    (_CU)                   },
  { "xdigit",   (_CD | _CX)             }
};

#define NUM_PROPVAL   (sizeof(typestrval) / sizeof(struct _typestrval))

static
struct _transtrval {
  char       *name;
  wctrans_t   function;
} transtrval[] = {
  { "tolower",  towlower },
  { "toupper",  towupper }
};

#define NUM_TRANSVAL   (sizeof(transtrval) / sizeof(struct _transtrval))

wctype_t wctype(const char *property)
{
  int i;

  for(i = 0; i < NUM_PROPVAL; ++i) {
    if( strcmp(typestrval[i].name, property) == 0) {
      return typestrval[i].value;
    }
  }
  return 0;
}

wint_t  towctrans(wint_t p1, wctrans_t tranfunc)
{
  return tranfunc(p1);
}

wctrans_t wctrans(const char *property)
{
  int i;

  for(i = 0; i < NUM_TRANSVAL; ++i) {
    if( strcmp(transtrval[i].name, property) == 0) {
      return transtrval[i].function;
    }
  }
  return NULL;
}