toupper.c revision 130961
1110211Smarcel/*- 2110211Smarcel * Copyright (c) 1993 3110211Smarcel * The Regents of the University of California. All rights reserved. 4110211Smarcel * 5110211Smarcel * This code is derived from software contributed to Berkeley by 6110211Smarcel * Paul Borman at Krystal Technologies. 7110211Smarcel * 8110211Smarcel * Redistribution and use in source and binary forms, with or without 9110211Smarcel * modification, are permitted provided that the following conditions 10110211Smarcel * are met: 11110211Smarcel * 1. Redistributions of source code must retain the above copyright 12110211Smarcel * notice, this list of conditions and the following disclaimer. 13110211Smarcel * 2. Redistributions in binary form must reproduce the above copyright 14110211Smarcel * notice, this list of conditions and the following disclaimer in the 15110211Smarcel * documentation and/or other materials provided with the distribution. 16110211Smarcel * 3. All advertising materials mentioning features or use of this software 17110211Smarcel * must display the following acknowledgement: 18110211Smarcel * This product includes software developed by the University of 19110211Smarcel * California, Berkeley and its contributors. 20110211Smarcel * 4. Neither the name of the University nor the names of its contributors 21110211Smarcel * may be used to endorse or promote products derived from this software 22110211Smarcel * without specific prior written permission. 23110211Smarcel * 24110211Smarcel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25110211Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26110211Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27110211Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28110211Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29110211Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30110211Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31110211Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32110211Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33110211Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34110211Smarcel * SUCH DAMAGE. 35110211Smarcel */ 36110211Smarcel 37110211Smarcel#include <sys/cdefs.h> 38110211Smarcel__FBSDID("$FreeBSD: head/lib/libc/locale/toupper.c 130961 2004-06-23 07:01:44Z tjr $"); 39110211Smarcel 40110211Smarcel#include <stdio.h> 41110211Smarcel#include <rune.h> 42110211Smarcel 43110211Smarcel__ct_rune_t 44110211Smarcel___toupper(c) 45110211Smarcel __ct_rune_t c; 46110211Smarcel{ 47110211Smarcel size_t lim; 48110211Smarcel _RuneRange *rr = &_CurrentRuneLocale->__mapupper_ext; 49110211Smarcel _RuneEntry *base, *re; 50110211Smarcel 51110211Smarcel if (c < 0 || c == EOF) 52110211Smarcel return(c); 53110211Smarcel 54110211Smarcel /* Binary search -- see bsearch.c for explanation. */ 55110211Smarcel base = rr->__ranges; 56110211Smarcel for (lim = rr->__nranges; lim != 0; lim >>= 1) { 57110211Smarcel re = base + (lim >> 1); 58110211Smarcel if (re->__min <= c && c <= re->__max) 59110211Smarcel return (re->__map + c - re->__min); 60110211Smarcel else if (c > re->__max) { 61110211Smarcel base = re + 1; 62110211Smarcel lim--; 63110211Smarcel } 64110211Smarcel } 65110211Smarcel 66110211Smarcel return(c); 67110211Smarcel} 68110211Smarcel