Mercurial > hg > octave-lojdl > gnulib-hg
changeset 17237:899138bc3a58
regex: implement rational ranges
Reported by Aharon Robbins in
<http://sourceware.org/ml/libc-alpha/2012-12/msg00456.html>.
* lib/regcomp.c (build_range_exp) [!_LIBC]:
* lib/regexec.c (check_node_accept_bytes) [!_LIBC]:
Implement rational ranges.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 29 Dec 2012 23:31:08 -0800 |
parents | d7e0ca139637 |
children | 02e05b27fe6e |
files | ChangeLog lib/regcomp.c lib/regexec.c |
diffstat | 3 files changed, 12 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2012-12-29 Paul Eggert <eggert@cs.ucla.edu> + regex: implement rational ranges + Reported by Aharon Robbins in + <http://sourceware.org/ml/libc-alpha/2012-12/msg00456.html>. + * lib/regcomp.c (build_range_exp) [!_LIBC]: + * lib/regexec.c (check_node_accept_bytes) [!_LIBC]: + Implement rational ranges. + regex: avoid redefining __wctype Reported by Aharon Robbins in <http://sourceware.org/ml/libc-alpha/2012-12/msg00456.html>.
--- a/lib/regcomp.c +++ b/lib/regcomp.c @@ -2712,7 +2712,6 @@ wchar_t wc; wint_t start_wc; wint_t end_wc; - wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0] @@ -2726,11 +2725,7 @@ ? __btowc (end_ch) : end_elem->opr.wch); if (start_wc == WEOF || end_wc == WEOF) return REG_ECOLLATE; - cmp_buf[0] = start_wc; - cmp_buf[4] = end_wc; - - if (BE ((syntax & RE_NO_EMPTY_RANGES) - && wcscoll (cmp_buf, cmp_buf + 4) > 0, 0)) + else if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc, 0)) return REG_ERANGE; /* Got valid collation sequence values, add them as a new entry. @@ -2771,9 +2766,7 @@ /* Build the table for single byte characters. */ for (wc = 0; wc < SBC_MAX; ++wc) { - cmp_buf[2] = wc; - if (wcscoll (cmp_buf, cmp_buf + 2) <= 0 - && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0) + if (start_wc <= wc && wc <= end_wc) bitset_set (sbcset, wc); } } @@ -2970,6 +2963,7 @@ 0)) return REG_ERANGE; + /* FIXME: Implement rational ranges here, too. */ start_collseq = lookup_collation_sequence_value (start_elem); end_collseq = lookup_collation_sequence_value (end_elem); /* Check start/end collation sequence values. */
--- a/lib/regexec.c +++ b/lib/regexec.c @@ -3936,6 +3936,7 @@ in_collseq = find_collation_sequence_value (pin, elem_len); } /* match with range expression? */ + /* FIXME: Implement rational ranges here, too. */ for (i = 0; i < cset->nranges; ++i) if (cset->range_starts[i] <= in_collseq && in_collseq <= cset->range_ends[i]) @@ -3987,18 +3988,9 @@ # endif /* _LIBC */ { /* match with range expression? */ -#if __GNUC__ >= 2 && ! (__STDC_VERSION__ < 199901L && defined __STRICT_ANSI__) - wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'}; -#else - wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'}; - cmp_buf[2] = wc; -#endif for (i = 0; i < cset->nranges; ++i) { - cmp_buf[0] = cset->range_starts[i]; - cmp_buf[4] = cset->range_ends[i]; - if (wcscoll (cmp_buf, cmp_buf + 2) <= 0 - && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0) + if (cset->range_starts[i] <= wc && wc <= cset->range_ends[i]) { match_len = char_len; goto check_node_accept_bytes_match;