1101253Stjr/*- 2101253Stjr * Copyright (c) 2002 Tim J. Robbins. 3101253Stjr * All rights reserved. 4101253Stjr * 5227753Stheraven * Copyright (c) 2011 The FreeBSD Foundation 6227753Stheraven * All rights reserved. 7227753Stheraven * Portions of this software were developed by David Chisnall 8227753Stheraven * under sponsorship from the FreeBSD Foundation. 9227753Stheraven * 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> 38227753Stheraven#include <xlocale.h> 39101253Stjr 40101253Stjr#undef iswctype 41101253Stjrint 42101253Stjriswctype(wint_t wc, wctype_t charclass) 43101253Stjr{ 44101253Stjr return (__istype(wc, charclass)); 45101253Stjr} 46227753Stheravenint 47227753Stheraveniswctype_l(wint_t wc, wctype_t charclass, locale_t locale) 48227753Stheraven{ 49227753Stheraven return __istype_l(wc, charclass, locale); 50227753Stheraven} 51101253Stjr 52227753Stheraven/* 53227753Stheraven * IMPORTANT: The 0 in the call to this function in wctype() must be changed to 54227753Stheraven * __get_locale() if wctype_l() is ever modified to actually use the locale 55227753Stheraven * parameter. 56227753Stheraven */ 57101253Stjrwctype_t 58227753Stheravenwctype_l(const char *property, locale_t locale) 59101253Stjr{ 60228269Sjilles const char *propnames = 61228269Sjilles "alnum\0" 62228269Sjilles "alpha\0" 63228269Sjilles "blank\0" 64228269Sjilles "cntrl\0" 65228269Sjilles "digit\0" 66228269Sjilles "graph\0" 67228269Sjilles "lower\0" 68228269Sjilles "print\0" 69228269Sjilles "punct\0" 70228269Sjilles "space\0" 71228269Sjilles "upper\0" 72228269Sjilles "xdigit\0" 73228269Sjilles "ideogram\0" /* BSD extension */ 74228269Sjilles "special\0" /* BSD extension */ 75228269Sjilles "phonogram\0" /* BSD extension */ 76290494Sbapt "number\0" /* BSD extension */ 77228269Sjilles "rune\0"; /* BSD extension */ 78228269Sjilles static const wctype_t propmasks[] = { 79290494Sbapt _CTYPE_A|_CTYPE_N, 80228269Sjilles _CTYPE_A, 81228269Sjilles _CTYPE_B, 82228269Sjilles _CTYPE_C, 83228269Sjilles _CTYPE_D, 84228269Sjilles _CTYPE_G, 85228269Sjilles _CTYPE_L, 86228269Sjilles _CTYPE_R, 87228269Sjilles _CTYPE_P, 88228269Sjilles _CTYPE_S, 89228269Sjilles _CTYPE_U, 90228269Sjilles _CTYPE_X, 91228269Sjilles _CTYPE_I, 92228269Sjilles _CTYPE_T, 93228269Sjilles _CTYPE_Q, 94290494Sbapt _CTYPE_N, 95228269Sjilles 0xFFFFFF00L 96101253Stjr }; 97228269Sjilles size_t len1, len2; 98228269Sjilles const char *p; 99228269Sjilles const wctype_t *q; 100101253Stjr 101228269Sjilles len1 = strlen(property); 102228269Sjilles q = propmasks; 103228269Sjilles for (p = propnames; (len2 = strlen(p)) != 0; p += len2 + 1) { 104228269Sjilles if (len1 == len2 && memcmp(property, p, len1) == 0) 105228269Sjilles return (*q); 106228269Sjilles q++; 107228269Sjilles } 108101253Stjr 109228269Sjilles return (0UL); 110101253Stjr} 111227753Stheraven 112227753Stheravenwctype_t wctype(const char *property) 113227753Stheraven{ 114227753Stheraven return wctype_l(property, 0); 115227753Stheraven} 116