1101313Stjr/*- 2101313Stjr * Copyright (c) 2002 Tim J. Robbins. 3101313Stjr * All rights reserved. 4101313Stjr * 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 * 10101313Stjr * Redistribution and use in source and binary forms, with or without 11101313Stjr * modification, are permitted provided that the following conditions 12101313Stjr * are met: 13101313Stjr * 1. Redistributions of source code must retain the above copyright 14101313Stjr * notice, this list of conditions and the following disclaimer. 15101313Stjr * 2. Redistributions in binary form must reproduce the above copyright 16101313Stjr * notice, this list of conditions and the following disclaimer in the 17101313Stjr * documentation and/or other materials provided with the distribution. 18101313Stjr * 19101313Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20101313Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21101313Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22101313Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23101313Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24101313Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25101313Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26101313Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27101313Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28101313Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29101313Stjr * SUCH DAMAGE. 30101313Stjr */ 31101313Stjr 32101313Stjr#include <sys/cdefs.h> 33101313Stjr__FBSDID("$FreeBSD$"); 34101313Stjr 35101313Stjr#include <errno.h> 36101313Stjr#include <string.h> 37101313Stjr#include <wctype.h> 38235785Stheraven#include "xlocale_private.h" 39101313Stjr 40101313Stjrenum { 41101313Stjr _WCT_ERROR = 0, 42101313Stjr _WCT_TOLOWER = 1, 43101313Stjr _WCT_TOUPPER = 2 44101313Stjr}; 45101313Stjr 46101313Stjrwint_t 47235785Stheraventowctrans_l(wint_t wc, wctrans_t desc, locale_t locale) 48101313Stjr{ 49101313Stjr switch (desc) { 50101313Stjr case _WCT_TOLOWER: 51235785Stheraven wc = towlower_l(wc, locale); 52101313Stjr break; 53101313Stjr case _WCT_TOUPPER: 54235785Stheraven wc = towupper_l(wc, locale); 55101313Stjr break; 56101313Stjr case _WCT_ERROR: 57101313Stjr default: 58101313Stjr errno = EINVAL; 59101313Stjr break; 60101313Stjr } 61101313Stjr 62101313Stjr return (wc); 63101313Stjr} 64235785Stheravenwint_t 65235785Stheraventowctrans(wint_t wc, wctrans_t desc) 66235785Stheraven{ 67235785Stheraven return towctrans_l(wc, desc, __get_locale()); 68235785Stheraven} 69101313Stjr 70235785Stheraven/* 71235785Stheraven * wctrans() calls this will a 0 locale. If this is ever modified to actually 72235785Stheraven * use the locale, wctrans() must be modified to call __get_locale(). 73235785Stheraven */ 74101313Stjrwctrans_t 75235785Stheravenwctrans_l(const char *charclass, locale_t locale) 76101313Stjr{ 77101313Stjr struct { 78101313Stjr const char *name; 79101313Stjr wctrans_t trans; 80101313Stjr } ccls[] = { 81101313Stjr { "tolower", _WCT_TOLOWER }, 82101313Stjr { "toupper", _WCT_TOUPPER }, 83101313Stjr { NULL, _WCT_ERROR }, /* Default */ 84101313Stjr }; 85101313Stjr int i; 86101313Stjr 87101313Stjr i = 0; 88101313Stjr while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0) 89101313Stjr i++; 90101313Stjr 91101313Stjr if (ccls[i].trans == _WCT_ERROR) 92101313Stjr errno = EINVAL; 93101313Stjr return (ccls[i].trans); 94101313Stjr} 95235785Stheraven 96235785Stheravenwctrans_t 97235785Stheravenwctrans(const char *charclass) 98235785Stheraven{ 99235785Stheraven return wctrans_l(charclass, 0); 100235785Stheraven} 101235785Stheraven 102