* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.8 2002/08/21 16:19:56 mike Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.13 2007/01/09 00:28:01 imp Exp $");
+
+#include "xlocale_private.h"
+#include <ctype.h>
#include <stdio.h>
-#include <rune.h>
+#include <runetype.h>
__ct_rune_t
-___toupper(c)
+___toupper_l(c, loc)
__ct_rune_t c;
+ locale_t loc;
{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
- _RuneEntry *re = rr->ranges;
+ size_t lim;
+ _RuneRange *rr;
+ _RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(c);
- for (x = 0; x < rr->nranges; ++x, ++re) {
- if (c < re->min)
- return(c);
- if (c <= re->max)
- return(re->map + c - re->min);
+ NORMALIZE_LOCALE(loc);
+ /*
+ * the following is not used by toupper(), but can be used by
+ * toupper_l(). This provides the oppurtunity to optimize toupper()
+ * when compatibility for Panther and lower is no longer needed
+ */
+ if (c < _CACHED_RUNES)
+ return loc->__lc_ctype->_CurrentRuneLocale.__mapupper[c];
+ rr = &loc->__lc_ctype->_CurrentRuneLocale.__mapupper_ext;
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+ re = base + (lim >> 1);
+ if (re->__min <= c && c <= re->__max)
+ return (re->__map + c - re->__min);
+ else if (c > re->__max) {
+ base = re + 1;
+ lim--;
+ }
}
return(c);
}
+
+__ct_rune_t
+___toupper(c)
+ __ct_rune_t c;
+{
+ return ___toupper_l(c, __current_locale());
+}