155714Skris/*-
255714Skris * SPDX-License-Identifier: BSD-2-Clause
355714Skris *
455714Skris * Copyright (c) 2002 Tim J. Robbins.
555714Skris * All rights reserved.
655714Skris *
755714Skris * Copyright (c) 2011 The FreeBSD Foundation
8280304Sjkim *
955714Skris * Portions of this software were developed by David Chisnall
1055714Skris * under sponsorship from the FreeBSD Foundation.
1155714Skris *
1255714Skris * Redistribution and use in source and binary forms, with or without
1355714Skris * modification, are permitted provided that the following conditions
1455714Skris * are met:
15280304Sjkim * 1. Redistributions of source code must retain the above copyright
1655714Skris *    notice, this list of conditions and the following disclaimer.
1755714Skris * 2. Redistributions in binary form must reproduce the above copyright
1855714Skris *    notice, this list of conditions and the following disclaimer in the
1955714Skris *    documentation and/or other materials provided with the distribution.
2055714Skris *
2155714Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22280304Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2455714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3155714Skris * SUCH DAMAGE.
3255714Skris */
3355714Skris
3455714Skris#include <ctype.h>
3555714Skris#include <string.h>
3655714Skris#include <wctype.h>
37280304Sjkim#include <xlocale.h>
3855714Skris
3955714Skris#undef iswctype
40280304Sjkimint
4155714Skrisiswctype(wint_t wc, wctype_t charclass)
4255714Skris{
4355714Skris	return (__istype(wc, charclass));
4455714Skris}
4555714Skrisint
4655714Skrisiswctype_l(wint_t wc, wctype_t charclass, locale_t locale)
4755714Skris{
4855714Skris	return __istype_l(wc, charclass, locale);
4955714Skris}
5055714Skris
5155714Skris/*
52280304Sjkim * IMPORTANT: The 0 in the call to this function in wctype() must be changed to
5355714Skris * __get_locale() if wctype_l() is ever modified to actually use the locale
5455714Skris * parameter.
5555714Skris */
5655714Skriswctype_t
5755714Skriswctype_l(const char *property, locale_t locale)
5855714Skris{
5955714Skris	const char *propnames =
6055714Skris		"alnum\0"
6155714Skris		"alpha\0"
6255714Skris		"blank\0"
63109998Smarkm		"cntrl\0"
64109998Smarkm		"digit\0"
65160814Ssimon		"graph\0"
6655714Skris		"lower\0"
6755714Skris		"print\0"
68160814Ssimon		"punct\0"
69280304Sjkim		"space\0"
7055714Skris		"upper\0"
7155714Skris		"xdigit\0"
72280304Sjkim		"ideogram\0"	/* BSD extension */
73280304Sjkim		"special\0"	/* BSD extension */
7455714Skris		"phonogram\0"	/* BSD extension */
75280304Sjkim		"number\0"	/* BSD extension */
76280304Sjkim		"rune\0";	/* BSD extension */
77280304Sjkim	static const wctype_t propmasks[] = {
7855714Skris		_CTYPE_A|_CTYPE_N,
79280304Sjkim		_CTYPE_A,
80280304Sjkim		_CTYPE_B,
8155714Skris		_CTYPE_C,
82280304Sjkim		_CTYPE_D,
83280304Sjkim		_CTYPE_G,
84280304Sjkim		_CTYPE_L,
85280304Sjkim		_CTYPE_R,
86280304Sjkim		_CTYPE_P,
8755714Skris		_CTYPE_S,
88280304Sjkim		_CTYPE_U,
89280304Sjkim		_CTYPE_X,
90280304Sjkim		_CTYPE_I,
91280304Sjkim		_CTYPE_T,
92280304Sjkim		_CTYPE_Q,
9355714Skris		_CTYPE_N,
94280304Sjkim		0xFFFFFF00L
95280304Sjkim	};
96280304Sjkim	size_t len1, len2;
97280304Sjkim	const char *p;
98280304Sjkim	const wctype_t *q;
99280304Sjkim
100280304Sjkim	len1 = strlen(property);
101280304Sjkim	q = propmasks;
102280304Sjkim	for (p = propnames; (len2 = strlen(p)) != 0; p += len2 + 1) {
103280304Sjkim		if (len1 == len2 && memcmp(property, p, len1) == 0)
104280304Sjkim			return (*q);
10555714Skris		q++;
10655714Skris	}
107280304Sjkim
108280304Sjkim	return (0UL);
109280304Sjkim}
110280304Sjkim
111280304Sjkimwctype_t wctype(const char *property)
112280304Sjkim{
113280304Sjkim	return wctype_l(property, 0);
11455714Skris}
115280304Sjkim