10d5acd74SJohn Marino /*-
20d5acd74SJohn Marino * Copyright (c) 2002 Tim J. Robbins.
30d5acd74SJohn Marino * All rights reserved.
40d5acd74SJohn Marino *
50d5acd74SJohn Marino * Copyright (c) 2011 The FreeBSD Foundation
60d5acd74SJohn Marino * All rights reserved.
70d5acd74SJohn Marino * Portions of this software were developed by David Chisnall
80d5acd74SJohn Marino * under sponsorship from the FreeBSD Foundation.
90d5acd74SJohn Marino *
100d5acd74SJohn Marino * Redistribution and use in source and binary forms, with or without
110d5acd74SJohn Marino * modification, are permitted provided that the following conditions
120d5acd74SJohn Marino * are met:
130d5acd74SJohn Marino * 1. Redistributions of source code must retain the above copyright
140d5acd74SJohn Marino * notice, this list of conditions and the following disclaimer.
150d5acd74SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
160d5acd74SJohn Marino * notice, this list of conditions and the following disclaimer in the
170d5acd74SJohn Marino * documentation and/or other materials provided with the distribution.
180d5acd74SJohn Marino *
190d5acd74SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
200d5acd74SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
210d5acd74SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220d5acd74SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
230d5acd74SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
240d5acd74SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
250d5acd74SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
260d5acd74SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
270d5acd74SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
280d5acd74SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
290d5acd74SJohn Marino * SUCH DAMAGE.
300d5acd74SJohn Marino *
310d5acd74SJohn Marino * $FreeBSD: head/lib/libc/locale/wctype.c 228269 2011-12-05 00:00:47Z jilles $
320d5acd74SJohn Marino */
330d5acd74SJohn Marino
340d5acd74SJohn Marino
350d5acd74SJohn Marino #include <ctype.h>
360d5acd74SJohn Marino #include <string.h>
370d5acd74SJohn Marino #include <wctype.h>
380d5acd74SJohn Marino #include <xlocale.h>
390d5acd74SJohn Marino
400d5acd74SJohn Marino #undef iswctype
410d5acd74SJohn Marino int
iswctype(wint_t wc,wctype_t charclass)420d5acd74SJohn Marino iswctype(wint_t wc, wctype_t charclass)
430d5acd74SJohn Marino {
440d5acd74SJohn Marino return (__istype(wc, charclass));
450d5acd74SJohn Marino }
460d5acd74SJohn Marino int
iswctype_l(wint_t wc,wctype_t charclass,locale_t locale)470d5acd74SJohn Marino iswctype_l(wint_t wc, wctype_t charclass, locale_t locale)
480d5acd74SJohn Marino {
490d5acd74SJohn Marino return __istype_l(wc, charclass, locale);
500d5acd74SJohn Marino }
510d5acd74SJohn Marino
520d5acd74SJohn Marino /*
530d5acd74SJohn Marino * IMPORTANT: The 0 in the call to this function in wctype() must be changed to
540d5acd74SJohn Marino * __get_locale() if wctype_l() is ever modified to actually use the locale
550d5acd74SJohn Marino * parameter.
560d5acd74SJohn Marino */
570d5acd74SJohn Marino wctype_t
wctype_l(const char * property,locale_t locale __unused)58*5dcdf778SSascha Wildner wctype_l(const char *property, locale_t locale __unused)
590d5acd74SJohn Marino {
600d5acd74SJohn Marino const char *propnames =
610d5acd74SJohn Marino "alnum\0"
620d5acd74SJohn Marino "alpha\0"
630d5acd74SJohn Marino "blank\0"
640d5acd74SJohn Marino "cntrl\0"
650d5acd74SJohn Marino "digit\0"
660d5acd74SJohn Marino "graph\0"
670d5acd74SJohn Marino "lower\0"
680d5acd74SJohn Marino "print\0"
690d5acd74SJohn Marino "punct\0"
700d5acd74SJohn Marino "space\0"
710d5acd74SJohn Marino "upper\0"
720d5acd74SJohn Marino "xdigit\0"
730d5acd74SJohn Marino "ideogram\0" /* BSD extension */
740d5acd74SJohn Marino "special\0" /* BSD extension */
750d5acd74SJohn Marino "phonogram\0" /* BSD extension */
7631c9f6f2SJohn Marino "number\0" /* BSD extension */
770d5acd74SJohn Marino "rune\0"; /* BSD extension */
780d5acd74SJohn Marino static const wctype_t propmasks[] = {
7931c9f6f2SJohn Marino _CTYPE_A|_CTYPE_N,
800d5acd74SJohn Marino _CTYPE_A,
810d5acd74SJohn Marino _CTYPE_B,
820d5acd74SJohn Marino _CTYPE_C,
830d5acd74SJohn Marino _CTYPE_D,
840d5acd74SJohn Marino _CTYPE_G,
850d5acd74SJohn Marino _CTYPE_L,
860d5acd74SJohn Marino _CTYPE_R,
870d5acd74SJohn Marino _CTYPE_P,
880d5acd74SJohn Marino _CTYPE_S,
890d5acd74SJohn Marino _CTYPE_U,
900d5acd74SJohn Marino _CTYPE_X,
910d5acd74SJohn Marino _CTYPE_I,
920d5acd74SJohn Marino _CTYPE_T,
930d5acd74SJohn Marino _CTYPE_Q,
9431c9f6f2SJohn Marino _CTYPE_N,
950d5acd74SJohn Marino 0xFFFFFF00L
960d5acd74SJohn Marino };
970d5acd74SJohn Marino size_t len1, len2;
980d5acd74SJohn Marino const char *p;
990d5acd74SJohn Marino const wctype_t *q;
1000d5acd74SJohn Marino
1010d5acd74SJohn Marino len1 = strlen(property);
1020d5acd74SJohn Marino q = propmasks;
1030d5acd74SJohn Marino for (p = propnames; (len2 = strlen(p)) != 0; p += len2 + 1) {
1040d5acd74SJohn Marino if (len1 == len2 && memcmp(property, p, len1) == 0)
1050d5acd74SJohn Marino return (*q);
1060d5acd74SJohn Marino q++;
1070d5acd74SJohn Marino }
1080d5acd74SJohn Marino
1090d5acd74SJohn Marino return (0UL);
1100d5acd74SJohn Marino }
1110d5acd74SJohn Marino
wctype(const char * property)1120d5acd74SJohn Marino wctype_t wctype(const char *property)
1130d5acd74SJohn Marino {
1140d5acd74SJohn Marino return wctype_l(property, 0);
1150d5acd74SJohn Marino }
116