10d5acd74SJohn Marino /*-
20d5acd74SJohn Marino * Copyright (c) 1993
30d5acd74SJohn Marino * The Regents of the University of California. All rights reserved.
40d5acd74SJohn Marino *
50d5acd74SJohn Marino * This code is derived from software contributed to Berkeley by
60d5acd74SJohn Marino * Paul Borman at Krystal Technologies.
70d5acd74SJohn Marino *
80d5acd74SJohn Marino * Copyright (c) 2011 The FreeBSD Foundation
90d5acd74SJohn Marino * All rights reserved.
100d5acd74SJohn Marino * Portions of this software were developed by David Chisnall
110d5acd74SJohn Marino * under sponsorship from the FreeBSD Foundation.
120d5acd74SJohn Marino *
130d5acd74SJohn Marino * Redistribution and use in source and binary forms, with or without
140d5acd74SJohn Marino * modification, are permitted provided that the following conditions
150d5acd74SJohn Marino * are met:
160d5acd74SJohn Marino * 1. Redistributions of source code must retain the above copyright
170d5acd74SJohn Marino * notice, this list of conditions and the following disclaimer.
180d5acd74SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
190d5acd74SJohn Marino * notice, this list of conditions and the following disclaimer in the
200d5acd74SJohn Marino * documentation and/or other materials provided with the distribution.
21*c66c7e2fSzrj * 3. Neither the name of the University nor the names of its contributors
220d5acd74SJohn Marino * may be used to endorse or promote products derived from this software
230d5acd74SJohn Marino * without specific prior written permission.
240d5acd74SJohn Marino *
250d5acd74SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
260d5acd74SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
270d5acd74SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
280d5acd74SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
290d5acd74SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
300d5acd74SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
310d5acd74SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
320d5acd74SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
330d5acd74SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
340d5acd74SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
350d5acd74SJohn Marino * SUCH DAMAGE.
360d5acd74SJohn Marino *
370d5acd74SJohn Marino * $FreeBSD: head/lib/libc/locale/toupper.c 235239 2012-05-10 20:03:34Z dim $
380d5acd74SJohn Marino */
390d5acd74SJohn Marino
400d5acd74SJohn Marino
410d5acd74SJohn Marino #include <ctype.h>
420d5acd74SJohn Marino #include <stdio.h>
430d5acd74SJohn Marino #include <runetype.h>
440d5acd74SJohn Marino #include <wchar.h>
450d5acd74SJohn Marino #include "mblocal.h"
460d5acd74SJohn Marino
470d5acd74SJohn Marino __ct_rune_t
___toupper_l(__ct_rune_t c,locale_t l)4868e609aaSSascha Wildner ___toupper_l(__ct_rune_t c, locale_t l)
490d5acd74SJohn Marino {
500d5acd74SJohn Marino size_t lim;
510d5acd74SJohn Marino FIX_LOCALE(l);
520d5acd74SJohn Marino _RuneRange *rr = &XLOCALE_CTYPE(l)->runes->__mapupper_ext;
530d5acd74SJohn Marino _RuneEntry *base, *re;
540d5acd74SJohn Marino
550d5acd74SJohn Marino if (c < 0 || c == EOF)
560d5acd74SJohn Marino return(c);
570d5acd74SJohn Marino
580d5acd74SJohn Marino /* Binary search -- see bsearch.c for explanation. */
590d5acd74SJohn Marino base = rr->__ranges;
600d5acd74SJohn Marino for (lim = rr->__nranges; lim != 0; lim >>= 1) {
610d5acd74SJohn Marino re = base + (lim >> 1);
620d5acd74SJohn Marino if (re->__min <= c && c <= re->__max)
630d5acd74SJohn Marino {
640d5acd74SJohn Marino return (re->__map + c - re->__min);
650d5acd74SJohn Marino }
660d5acd74SJohn Marino else if (c > re->__max) {
670d5acd74SJohn Marino base = re + 1;
680d5acd74SJohn Marino lim--;
690d5acd74SJohn Marino }
700d5acd74SJohn Marino }
710d5acd74SJohn Marino
720d5acd74SJohn Marino return(c);
730d5acd74SJohn Marino }
740d5acd74SJohn Marino __ct_rune_t
___toupper(__ct_rune_t c)7568e609aaSSascha Wildner ___toupper(__ct_rune_t c)
760d5acd74SJohn Marino {
770d5acd74SJohn Marino return ___toupper_l(c, __get_locale());
780d5acd74SJohn Marino }
79