X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_utf8.h;h=74fd19bb0046a543990f8cc32c5e376b735dbd18;hp=ab4e05feb6c4e58491c46a49d62abc8954e278b7;hb=30061b8b7dcf2713a84ad80afca74002e0492aae;hpb=1e16f290236f1d669f4fba501d06a334e03f5827 diff --git a/src/php_http_utf8.h b/src/php_http_utf8.h index ab4e05f..74fd19b 100644 --- a/src/php_http_utf8.h +++ b/src/php_http_utf8.h @@ -786,24 +786,51 @@ static inline size_t utf8towc(unsigned *wc, const unsigned char *uc, size_t len) static inline zend_bool isualpha(unsigned ch) { - unsigned j; - const utf8_range_t *u = &utf8_ranges[0], *e = &utf8_ranges[sizeof(utf8_ranges)/sizeof(utf8_range_t)-1]; + unsigned count = sizeof(utf8_ranges)/sizeof(utf8_range_t), + lo = 0, + hi = count-1, + cur = (count-1)/2, + prev; + +#undef u +#define u (utf8_ranges[cur]) do { - if (u->start == ch) { +#if 0 + fprintf(stderr, "=> cur=%u lo=%u hi=%u (%u in %u-%u)\n", cur, lo, hi, ch, u.start, u.end); +#endif + if (u.start == ch) { return 1; - } else if (u->start <= ch && u->end >= ch) { - if (u->step == 1) { + } else if (u.start <= ch && u.end >= ch) { + unsigned j; + + if (u.step == 1) { return 1; } - for (j = u->start; j <= u->end; j+= u->step) { + for (j = u.start; j <= u.end; j+= u.step) { if (ch == j) { return 1; } } return 0; } - } while (++u != e); + + prev = cur; + + if (u.start > ch) { + hi = cur; + cur -= (cur - lo) / 2; + } else if ((u.end && u.end < ch) || (!u.end && u.start < ch)) { + lo = cur; + cur += (hi - cur) / 2; + } else { + return 0; + } + + } while (cur != prev); + +#undef u +#undef check return 0; }