wctype.c revision 227753
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: head/lib/libc/locale/wctype.c 227753 2011-11-20 14:45:42Z theraven $"); 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{ 60177311Santoine static const struct { 61101253Stjr const char *name; 62101253Stjr wctype_t mask; 63101253Stjr } props[] = { 64101253Stjr { "alnum", _CTYPE_A|_CTYPE_D }, 65101253Stjr { "alpha", _CTYPE_A }, 66101253Stjr { "blank", _CTYPE_B }, 67101253Stjr { "cntrl", _CTYPE_C }, 68101253Stjr { "digit", _CTYPE_D }, 69101253Stjr { "graph", _CTYPE_G }, 70101253Stjr { "lower", _CTYPE_L }, 71101253Stjr { "print", _CTYPE_R }, 72101253Stjr { "punct", _CTYPE_P }, 73101253Stjr { "space", _CTYPE_S }, 74101253Stjr { "upper", _CTYPE_U }, 75101253Stjr { "xdigit", _CTYPE_X }, 76101253Stjr { "ideogram", _CTYPE_I }, /* BSD extension */ 77101253Stjr { "special", _CTYPE_T }, /* BSD extension */ 78101253Stjr { "phonogram", _CTYPE_Q }, /* BSD extension */ 79127477Stjr { "rune", 0xFFFFFF00L }, /* BSD extension */ 80101314Stjr { NULL, 0UL }, /* Default */ 81101253Stjr }; 82101253Stjr int i; 83101253Stjr 84101253Stjr i = 0; 85101253Stjr while (props[i].name != NULL && strcmp(props[i].name, property) != 0) 86101253Stjr i++; 87101253Stjr 88101253Stjr return (props[i].mask); 89101253Stjr} 90227753Stheraven 91227753Stheravenwctype_t wctype(const char *property) 92227753Stheraven{ 93227753Stheraven return wctype_l(property, 0); 94227753Stheraven} 95