1 /* $NetBSD: src/lib/libc/locale/iswctype.c,v 1.14 2003/08/07 16:43:04 agc Exp $ */
2 /* $DragonFly: src/lib/libc/locale/iswctype.c,v 1.1 2005/03/16 06:54:41 joerg Exp $ */
5 * Copyright (c) 1989 The Regents of the University of California.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 #include "rune_local.h"
46 #include "_wctrans_local.h"
48 static _RuneType __runetype_w(wint_t);
49 static int __isctype_w(wint_t, _RuneType);
50 static wint_t __toupper_w(wint_t);
51 static wint_t __tolower_w(wint_t);
54 __runetype_w(wint_t c)
56 _RuneLocale *rl = _CurrentRuneLocale;
58 if (_RUNE_ISCACHED(c))
59 return(rl->rl_runetype[c]);
61 return(___runetype_mb(c));
65 __isctype_w(wint_t c, _RuneType f)
67 if (__runetype_w(c) & f)
76 return(_towctrans(c, _wctrans_upper(_CurrentRuneLocale)));
82 return(_towctrans(c, _wctrans_lower(_CurrentRuneLocale)));
89 return(__isctype_w((c), _CTYPE_A|_CTYPE_D));
96 return(__isctype_w((c), _CTYPE_A));
103 return(__isctype_w((c), _CTYPE_B));
110 return(__isctype_w((c), _CTYPE_C));
117 return(__isctype_w((c), _CTYPE_D));
124 return(__isctype_w((c), _CTYPE_G));
131 return(__isctype_w((c), _CTYPE_L));
138 return(__isctype_w((c), _CTYPE_R));
145 return(__isctype_w((c), _CTYPE_P));
152 return(__isctype_w((c), _CTYPE_S));
159 return(__isctype_w((c), _CTYPE_U));
166 return(__isctype_w((c), _CTYPE_X));
173 return(__toupper_w(c));
180 return(__tolower_w(c));
187 return(((unsigned)__runetype_w(c) & _CTYPE_SWM) >> _CTYPE_SWS);
192 wctrans(const char *charclass)
195 _RuneLocale *rl = _CurrentRuneLocale;
197 if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name == NULL)
200 for (i = 0; i < _WCTRANS_NINDEXES; i++) {
201 if (strcmp(rl->rl_wctrans[i].te_name, charclass) == 0)
202 return((wctrans_t)&rl->rl_wctrans[i]);
205 return((wctrans_t)NULL);
210 towctrans(wint_t c, wctrans_t desc)
216 return(_towctrans(c, (_WCTransEntry *)desc));
221 wctype(const char *property)
224 _RuneLocale *rl = _CurrentRuneLocale;
226 for (i=0; i < _WCTYPE_NINDEXES; i++) {
227 if (strcmp(rl->rl_wctype[i].te_name, property) == 0)
228 return((wctype_t)&rl->rl_wctype[i]);
230 return((wctype_t)NULL);
235 iswctype(wint_t c, wctype_t charclass)
238 * SUSv3: If charclass is 0, iswctype() shall return 0.
240 if (charclass == (wctype_t)0)
243 return (__isctype_w(c, ((_WCTypeEntry *)charclass)->te_mask));