1101253Stjr/*-
2101253Stjr * Copyright (c) 2002 Tim J. Robbins.
3101253Stjr * All rights reserved.
4101253Stjr *
5235785Stheraven * Copyright (c) 2011 The FreeBSD Foundation
6235785Stheraven * All rights reserved.
7235785Stheraven * Portions of this software were developed by David Chisnall
8235785Stheraven * under sponsorship from the FreeBSD Foundation.
9235785Stheraven *
10101253Stjr * Redistribution and use in source and binary forms, with or without
11101253Stjr * modification, are permitted provided that the following conditions
12101253Stjr * are met:
13101253Stjr * 1. Redistributions of source code must retain the above copyright
14101253Stjr *    notice, this list of conditions and the following disclaimer.
15101253Stjr * 2. Redistributions in binary form must reproduce the above copyright
16101253Stjr *    notice, this list of conditions and the following disclaimer in the
17101253Stjr *    documentation and/or other materials provided with the distribution.
18101253Stjr *
19101253Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20101253Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21101253Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22101253Stjr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23101253Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24101253Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25101253Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26101253Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27101253Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28101253Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29101253Stjr * SUCH DAMAGE.
30101253Stjr */
31101253Stjr
32101253Stjr#include <sys/cdefs.h>
33101253Stjr__FBSDID("$FreeBSD$");
34101253Stjr
35101253Stjr#include <ctype.h>
36101253Stjr#include <string.h>
37101253Stjr#include <wctype.h>
38235785Stheraven#include <xlocale.h>
39101253Stjr
40101253Stjr#undef iswctype
41101253Stjrint
42101253Stjriswctype(wint_t wc, wctype_t charclass)
43101253Stjr{
44101253Stjr	return (__istype(wc, charclass));
45101253Stjr}
46235785Stheravenint
47235785Stheraveniswctype_l(wint_t wc, wctype_t charclass, locale_t locale)
48235785Stheraven{
49235785Stheraven	return __istype_l(wc, charclass, locale);
50235785Stheraven}
51101253Stjr
52235785Stheraven/*
53235785Stheraven * IMPORTANT: The 0 in the call to this function in wctype() must be changed to
54235785Stheraven * __get_locale() if wctype_l() is ever modified to actually use the locale
55235785Stheraven * parameter.
56235785Stheraven */
57101253Stjrwctype_t
58235785Stheravenwctype_l(const char *property, locale_t locale)
59101253Stjr{
60250215Spluknet	const char *propnames =
61250215Spluknet		"alnum\0"
62250215Spluknet		"alpha\0"
63250215Spluknet		"blank\0"
64250215Spluknet		"cntrl\0"
65250215Spluknet		"digit\0"
66250215Spluknet		"graph\0"
67250215Spluknet		"lower\0"
68250215Spluknet		"print\0"
69250215Spluknet		"punct\0"
70250215Spluknet		"space\0"
71250215Spluknet		"upper\0"
72250215Spluknet		"xdigit\0"
73250215Spluknet		"ideogram\0"	/* BSD extension */
74250215Spluknet		"special\0"	/* BSD extension */
75250215Spluknet		"phonogram\0"	/* BSD extension */
76250215Spluknet		"rune\0";	/* BSD extension */
77250215Spluknet	static const wctype_t propmasks[] = {
78250215Spluknet		_CTYPE_A|_CTYPE_D,
79250215Spluknet		_CTYPE_A,
80250215Spluknet		_CTYPE_B,
81250215Spluknet		_CTYPE_C,
82250215Spluknet		_CTYPE_D,
83250215Spluknet		_CTYPE_G,
84250215Spluknet		_CTYPE_L,
85250215Spluknet		_CTYPE_R,
86250215Spluknet		_CTYPE_P,
87250215Spluknet		_CTYPE_S,
88250215Spluknet		_CTYPE_U,
89250215Spluknet		_CTYPE_X,
90250215Spluknet		_CTYPE_I,
91250215Spluknet		_CTYPE_T,
92250215Spluknet		_CTYPE_Q,
93250215Spluknet		0xFFFFFF00L
94101253Stjr	};
95250215Spluknet	size_t len1, len2;
96250215Spluknet	const char *p;
97250215Spluknet	const wctype_t *q;
98101253Stjr
99250215Spluknet	len1 = strlen(property);
100250215Spluknet	q = propmasks;
101250215Spluknet	for (p = propnames; (len2 = strlen(p)) != 0; p += len2 + 1) {
102250215Spluknet		if (len1 == len2 && memcmp(property, p, len1) == 0)
103250215Spluknet			return (*q);
104250215Spluknet		q++;
105250215Spluknet	}
106101253Stjr
107250215Spluknet	return (0UL);
108101253Stjr}
109235785Stheraven
110235785Stheravenwctype_t wctype(const char *property)
111235785Stheraven{
112235785Stheraven	return wctype_l(property, 0);
113235785Stheraven}
114