X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..15de9d6b4ab2de27ae24b13b7b6c4d55fffe4aef:/locale/FreeBSD/runetype.c diff --git a/locale/FreeBSD/runetype.c b/locale/FreeBSD/runetype.c index e843637..6ffcf72 100644 --- a/locale/FreeBSD/runetype.c +++ b/locale/FreeBSD/runetype.c @@ -13,10 +13,6 @@ * 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. @@ -35,32 +31,46 @@ */ #include -__FBSDID("$FreeBSD: src/lib/libc/locale/runetype.c,v 1.8 2002/08/21 16:19:56 mike Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/locale/runetype.c,v 1.14 2007/01/09 00:28:00 imp Exp $"); +#include "xlocale_private.h" + +#include #include -#include +#include unsigned long -___runetype(c) - __ct_rune_t c; +___runetype_l(__ct_rune_t c, locale_t loc) { - int x; - _RuneRange *rr = &_CurrentRuneLocale->runetype_ext; - _RuneEntry *re = rr->ranges; + size_t lim; + _RuneRange *rr; + _RuneEntry *base, *re; if (c < 0 || c == EOF) return(0L); - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(0L); - if (c <= re->max) { - if (re->types) - return(re->types[c - re->min]); + NORMALIZE_LOCALE(loc); + rr = &loc->__lc_ctype->_CurrentRuneLocale.__runetype_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) { + if (re->__types) + return(re->__types[c - re->__min]); else - return(re->map); + return(re->__map); + } else if (c > re->__max) { + base = re + 1; + lim--; } } return(0L); } + +unsigned long +___runetype(__ct_rune_t c) +{ + return ___runetype_l(c, __current_locale()); +}