aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-11-12 17:47:46 +0000
committerUlrich Drepper <drepper@redhat.com>2003-11-12 17:47:46 +0000
commit3c0fb5745f66c8920ed4cfa8d3ead55216b15ec1 (patch)
treed993d46e33582e130e8324c5bd7fb7817d2a7f54
parente432c0378ecfa545948d4be68190ab470446554b (diff)
downloadglibc-3c0fb5745f66c8920ed4cfa8d3ead55216b15ec1.tar.xz
glibc-3c0fb5745f66c8920ed4cfa8d3ead55216b15ec1.zip
Update.
2003-11-12 Jakub Jelinek <jakub@redhat.com> * io/ftw.c (NFTW_NEW_NAME, NFTW_OLD_NAME): Add prototypes. 2003-11-12 Jakub Jelinek <jakub@redhat.com> * posix/tst-regex.c (umemlen): New variable. (test_expr): Add expectedicase argument. Test case insensitive searches as well as backwards searches (case sensitive and insensitive) too. (run_test): Add icase argument. Use it to compute regcomp flags. (run_test_backwards): New function. (main): Cast read to size_t to avoid warning. Set umemlen. Add expectedicase arguments to test_expr. * posix/regex_internal.c (re_string_reconstruct): If is_utf8, find previous character by walking back instead of converting all chars from beginning. 2003-11-12 Jakub Jelinek <jakub@redhat.com> * posix/regex_internal.h (struct re_string_t): Add is_utf8 and mb_cur_max fields. (struct re_dfa_t): Likewise. Reorder fields to make structure smaller on 64-bit arches. (re_string_allocate, re_string_construct): Add mb_cur_max and is_utf8 arguments. (re_string_char_size_at, re_string_wchar_at): Use pstr->mb_cur_max instead of MB_CUR_MAX. * posix/regcomp.c (re_compile_fastmap_iter): Use dfa->mb_cur_max instead of MB_CUR_MAX. (re_compile_internal): Pass new arguments to re_string_construct. (init_dfa): Initialize mb_cur_max and is_utf8 fields. (peek_token, peek_token_bracket): Use input->mb_cur_max instead of MB_CUR_MAX. (parse_expression, parse_bracket_exp, parse_charclass_op): Use dfa->mb_cur_max instead of MB_CUR_MAX. * posix/regex_internal.c (re_string_construct_common): Add mb_cur_max and is_utf8 arguments. Initialize fields with them. (re_string_allocate, re_string_construct): Add mb_cur_max and is_utf8 arguments, pass them to re_string_construct_common. Use mb_cur_max instead of MB_CUR_MAX. (re_string_realloc_buffers): Use pstr->mb_cur_max instead of MB_CUR_MAX. (re_string_reconstruct): Likewise. (re_string_context_at): Use input->mb_cur_max instead of MB_CUR_MAX. (create_ci_newstate, create_cd_newstate): Use dfa->mb_cur_max instead of MB_CUR_MAX. * posix/regexec.c (re_search_internal): Likewise. Pass new arguments to re_string_allocate. (check_matching, transit_state_sb): Use dfa->mb_cur_max instead of MB_CUR_MAX. (extend_buffers): Use pstr->mb_cur_max instead of MB_CUR_MAX. 2003-11-12 Jakub Jelinek <jakub@redhat.com> * posix/Makefile (tests): Add bug-regex19. (bug-regex19-ENV): Add LOCPATH. * posix/bug-regex19.c: New test.
-rw-r--r--ChangeLog60
-rw-r--r--io/ftw.c4
-rw-r--r--posix/Makefile4
-rw-r--r--posix/bug-regex19.c112
-rw-r--r--posix/regcomp.c34
-rw-r--r--posix/regex_internal.c86
-rw-r--r--posix/regex_internal.h23
-rw-r--r--posix/regexec.c13
-rw-r--r--posix/tst-regex.c141
9 files changed, 409 insertions, 68 deletions
diff --git a/ChangeLog b/ChangeLog
index e4bc7e1228..6021fb6620 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,63 @@
+2003-11-12 Jakub Jelinek <jakub@redhat.com>
+
+ * io/ftw.c (NFTW_NEW_NAME, NFTW_OLD_NAME): Add prototypes.
+
+2003-11-12 Jakub Jelinek <jakub@redhat.com>
+
+ * posix/tst-regex.c (umemlen): New variable.
+ (test_expr): Add expectedicase argument. Test case insensitive
+ searches as well as backwards searches (case sensitive and
+ insensitive) too.
+ (run_test): Add icase argument. Use it to compute regcomp flags.
+ (run_test_backwards): New function.
+ (main): Cast read to size_t to avoid warning. Set umemlen.
+ Add expectedicase arguments to test_expr.
+ * posix/regex_internal.c (re_string_reconstruct): If is_utf8,
+ find previous character by walking back instead of converting
+ all chars from beginning.
+
+2003-11-12 Jakub Jelinek <jakub@redhat.com>
+
+ * posix/regex_internal.h (struct re_string_t): Add is_utf8
+ and mb_cur_max fields.
+ (struct re_dfa_t): Likewise. Reorder fields to make structure
+ smaller on 64-bit arches.
+ (re_string_allocate, re_string_construct): Add mb_cur_max and
+ is_utf8 arguments.
+ (re_string_char_size_at, re_string_wchar_at): Use pstr->mb_cur_max
+ instead of MB_CUR_MAX.
+ * posix/regcomp.c (re_compile_fastmap_iter): Use dfa->mb_cur_max
+ instead of MB_CUR_MAX.
+ (re_compile_internal): Pass new arguments to re_string_construct.
+ (init_dfa): Initialize mb_cur_max and is_utf8 fields.
+ (peek_token, peek_token_bracket): Use input->mb_cur_max instead
+ of MB_CUR_MAX.
+ (parse_expression, parse_bracket_exp, parse_charclass_op): Use
+ dfa->mb_cur_max instead of MB_CUR_MAX.
+ * posix/regex_internal.c (re_string_construct_common): Add
+ mb_cur_max and is_utf8 arguments. Initialize fields with them.
+ (re_string_allocate, re_string_construct): Add mb_cur_max and
+ is_utf8 arguments, pass them to re_string_construct_common.
+ Use mb_cur_max instead of MB_CUR_MAX.
+ (re_string_realloc_buffers): Use pstr->mb_cur_max instead of
+ MB_CUR_MAX.
+ (re_string_reconstruct): Likewise.
+ (re_string_context_at): Use input->mb_cur_max instead of
+ MB_CUR_MAX.
+ (create_ci_newstate, create_cd_newstate): Use dfa->mb_cur_max
+ instead of MB_CUR_MAX.
+ * posix/regexec.c (re_search_internal): Likewise.
+ Pass new arguments to re_string_allocate.
+ (check_matching, transit_state_sb): Use dfa->mb_cur_max instead of
+ MB_CUR_MAX.
+ (extend_buffers): Use pstr->mb_cur_max instead of MB_CUR_MAX.
+
+2003-11-12 Jakub Jelinek <jakub@redhat.com>
+
+ * posix/Makefile (tests): Add bug-regex19.
+ (bug-regex19-ENV): Add LOCPATH.
+ * posix/bug-regex19.c: New test.
+
2003-11-11 Jakub Jelinek <jakub@redhat.com>
* posix/regcomp.c (re_compile_fastmap_iter): Handle RE_ICASE
diff --git a/io/ftw.c b/io/ftw.c
index c4d2157bd9..20cf694e24 100644
--- a/io/ftw.c
+++ b/io/ftw.c
@@ -757,6 +757,8 @@ NFTW_NAME (path, func, descriptors, flags)
#include <shlib-compat.h>
+int NFTW_NEW_NAME (const char *, NFTW_FUNC_T, int, int);
+
int
NFTW_NEW_NAME (path, func, descriptors, flags)
const char *path;
@@ -779,6 +781,8 @@ versioned_symbol (libc, NFTW_NEW_NAME, NFTW_NAME, GLIBC_2_3_3);
/* Older nftw* version just ignored all unknown flags. */
+int NFTW_OLD_NAME (const char *, NFTW_FUNC_T, int, int);
+
int
NFTW_OLD_NAME (path, func, descriptors, flags)
const char *path;
diff --git a/posix/Makefile b/posix/Makefile
index 10329577b5..b20e1c314e 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -77,7 +77,8 @@ tests := tstgetopt testfnm runtests runptests \
tst-gnuglob tst-regex bug-regex5 bug-regex6 bug-regex7 \
bug-regex8 bug-regex9 bug-regex10 bug-regex11 bug-regex12 \
bug-regex13 bug-regex14 bug-regex15 bug-regex16 \
- bug-regex17 bug-regex18 tst-nice tst-nanosleep transbug
+ bug-regex17 bug-regex18 bug-regex19 \
+ tst-nice tst-nanosleep transbug
ifeq (yes,$(build-shared))
test-srcs := globtest
tests += wordexp-test tst-exec tst-spawn
@@ -155,6 +156,7 @@ bug-regex5-ENV = LOCPATH=$(common-objpfx)localedata
bug-regex6-ENV = LOCPATH=$(common-objpfx)localedata
bug-regex17-ENV = LOCPATH=$(common-objpfx)localedata
bug-regex18-ENV = LOCPATH=$(common-objpfx)localedata
+bug-regex19-ENV = LOCPATH=$(common-objpfx)localedata
testcases.h: TESTS TESTS2C.sed
sed -f TESTS2C.sed < $< > $@T
diff --git a/posix/bug-regex19.c b/posix/bug-regex19.c
new file mode 100644
index 0000000000..837ab654bc
--- /dev/null
+++ b/posix/bug-regex19.c
@@ -0,0 +1,112 @@
+/* Regular expression tests.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/types.h>
+#include <mcheck.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+
+static struct
+{
+ int syntax;
+ const char *pattern;
+ const char *string;
+ int start, res;
+} tests[] = {
+ /* \xc3\x84 LATIN CAPITAL LETTER A WITH DIAERESIS
+ \xc3\x96 LATIN CAPITAL LETTER O WITH DIAERESIS
+ \xe2\x80\x94 EM DASH */
+ /* Should not match. */
+ {RE_SYNTAX_POSIX_BASIC, "\\<A", "aOAA", 2, -1},
+ {RE_SYNTAX_POSIX_BASIC, "A\\>", "aAAO", 1, -1},
+ {RE_SYNTAX_POSIX_BASIC, "\\bA", "aOAA", 2, -1},
+ {RE_SYNTAX_POSIX_BASIC, "A\\b", "aAAO", 1, -1},
+ {RE_SYNTAX_POSIX_BASIC, "\\<\xc3\x84", "a\xc3\x96\xc3\x84\xc3\x84", 3, -1},
+ {RE_SYNTAX_POSIX_BASIC, "\xc3\x84\\>", "a\xc3\x84\xc3\x84\xc3\x96", 1, -1},
+#if 0
+ /* XXX Not used since they fail so far. */
+ {RE_SYNTAX_POSIX_BASIC, "\\b\xc3\x84", "a\xc3\x96\xc3\x84\xc3\x84", 3, -1},
+ {RE_SYNTAX_POSIX_BASIC, "\xc3\x84\\b", "a\xc3\x84\xc3\x84\xc3\x96", 1, -1},
+#endif
+ /* Should match. */
+ {RE_SYNTAX_POSIX_BASIC, "\\<A", "AA", 0, 0},
+ {RE_SYNTAX_POSIX_BASIC, "\\<A", "a-AA", 2, 2},
+ {RE_SYNTAX_POSIX_BASIC, "A\\>", "aAA-", 1, 2},
+ {RE_SYNTAX_POSIX_BASIC, "A\\>", "aAA", 1, 2},
+ {RE_SYNTAX_POSIX_BASIC, "\\bA", "AA", 0, 0},
+ {RE_SYNTAX_POSIX_BASIC, "\\bA", "a-AA", 2, 2},
+ {RE_SYNTAX_POSIX_BASIC, "A\\b", "aAA-", 1, 2},
+ {RE_SYNTAX_POSIX_BASIC, "A\\b", "aAA", 1, 2},
+#if 0
+ /* XXX Not used since they fail so far. */
+ {RE_SYNTAX_POSIX_BASIC, "\\<\xc3\x84", "\xc3\x84\xc3\x84", 0, 0},
+ {RE_SYNTAX_POSIX_BASIC, "\\<\xc3\x84", "a\xe2\x80\x94\xc3\x84\xc3\x84", 4, 4},
+ {RE_SYNTAX_POSIX_BASIC, "\xc3\x84\\>", "a\xc3\x84\xc3\x84\xe2\x80\x94", 1, 3},
+ {RE_SYNTAX_POSIX_BASIC, "\xc3\x84\\>", "a\xc3\x84\xc3\x84", 1, 3},
+ {RE_SYNTAX_POSIX_BASIC, "\\b\xc3\x84", "\xc3\x84\xc3\x84", 0, 0},
+ {RE_SYNTAX_POSIX_BASIC, "\\b\xc3\x84", "a\xe2\x80\x94\xc3\x84\xc3\x84", 4, 4},
+ {RE_SYNTAX_POSIX_BASIC, "\xc3\x84\\b", "a\xc3\x84\xc3\x84\xe2\x80\x94", 1, 3},
+ {RE_SYNTAX_POSIX_BASIC, "\xc3\x84\\b", "a\xc3\x84\xc3\x84", 1, 3}
+#endif
+};
+
+int
+main (void)
+{
+ struct re_pattern_buffer regbuf;
+ const char *err;
+ size_t i;
+ int ret = 0;
+
+ mtrace ();
+
+ setlocale (LC_ALL, "de_DE.UTF-8");
+ for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
+ {
+ int res;
+ re_set_syntax (tests[i].syntax);
+ memset (&regbuf, '\0', sizeof (regbuf));
+ err = re_compile_pattern (tests[i].pattern, strlen (tests[i].pattern),
+ &regbuf);
+ if (err != NULL)
+ {
+ printf ("re_compile_pattern failed: %s\n", err);
+ ret = 1;
+ continue;
+ }
+
+ res = re_search (&regbuf, tests[i].string, strlen (tests[i].string),
+ tests[i].start,
+ strlen (tests[i].string) - tests[i].start, NULL);
+ if (res != tests[i].res)
+ {
+ printf ("re_search %zd failed: %d\n", i, res);
+ ret = 1;
+ regfree (&regbuf);
+ continue;
+ }
+ regfree (&regbuf);
+ }
+
+ return ret;
+}
diff --git a/posix/regcomp.c b/posix/regcomp.c
index 2b850378b2..82d4bb1c57 100644
--- a/posix/regcomp.c
+++ b/posix/regcomp.c
@@ -312,7 +312,7 @@ re_compile_fastmap_iter (bufp, init_state, fastmap)
{
re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
int node_cnt;
- int icase = (MB_CUR_MAX == 1 && (bufp->syntax & RE_ICASE));
+ int icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
{
int node = init_state->nodes.elems[node_cnt];
@@ -324,7 +324,7 @@ re_compile_fastmap_iter (bufp, init_state, fastmap)
#ifdef RE_ENABLE_I18N
if ((bufp->syntax & RE_ICASE) && !icase)
{
- unsigned char *buf = alloca (MB_CUR_MAX), *p;
+ unsigned char *buf = alloca (dfa->mb_cur_max), *p;
wchar_t wc;
mbstate_t state;
@@ -376,7 +376,7 @@ re_compile_fastmap_iter (bufp, init_state, fastmap)
re_set_fastmap (fastmap, icase, ch);
}
# else
- if (MB_CUR_MAX > 1)
+ if (dfa->mb_cur_max > 1)
for (i = 0; i < SBC_MAX; ++i)
if (__btowc (i) == WEOF)
re_set_fastmap (fastmap, icase, i);
@@ -744,7 +744,8 @@ re_compile_internal (preg, pattern, length, syntax)
#endif
err = re_string_construct (&regexp, pattern, length, preg->translate,
- syntax & RE_ICASE);
+ syntax & RE_ICASE, dfa->mb_cur_max,
+ dfa->is_utf8);
if (BE (err != REG_NOERROR, 0))
{
re_free (dfa);
@@ -812,6 +813,13 @@ init_dfa (dfa, pat_len)
dfa->subexps = re_malloc (re_subexp_t, dfa->subexps_alloc);
dfa->word_char = NULL;
+ dfa->mb_cur_max = MB_CUR_MAX;
+#ifdef _LIBC
+ if (dfa->mb_cur_max > 1
+ && strcmp (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_CODESET_NAME), "UTF-8") == 0)
+ dfa->is_utf8 = 1;
+#endif
+
if (BE (dfa->nodes == NULL || dfa->state_table == NULL
|| dfa->subexps == NULL, 0))
{
@@ -1522,7 +1530,7 @@ peek_token (token, input, syntax)
#ifdef RE_ENABLE_I18N
token->mb_partial = 0;
- if (MB_CUR_MAX > 1 &&
+ if (input->mb_cur_max > 1 &&
!re_string_first_byte (input, re_string_cur_idx (input)))
{
token->type = CHARACTER;
@@ -1738,7 +1746,7 @@ peek_token_bracket (token, input, syntax)
token->opr.c = c;
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1 &&
+ if (input->mb_cur_max > 1 &&
!re_string_first_byte (input, re_string_cur_idx (input)))
{
token->type = CHARACTER;
@@ -1976,7 +1984,7 @@ parse_expression (regexp, preg, token, syntax, nest, err)
return NULL;
}
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (dfa->mb_cur_max > 1)
{
while (!re_string_eoi (regexp)
&& !re_string_first_byte (regexp, re_string_cur_idx (regexp)))
@@ -2111,7 +2119,7 @@ parse_expression (regexp, preg, token, syntax, nest, err)
*err = REG_ESPACE;
return NULL;
}
- if (MB_CUR_MAX > 1)
+ if (dfa->mb_cur_max > 1)
dfa->has_mb_node = 1;
break;
case OP_WORD:
@@ -2883,7 +2891,7 @@ parse_bracket_exp (regexp, dfa, token, syntax, err)
goto parse_bracket_exp_free_return;
}
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (dfa->mb_cur_max > 1)
for (i = 0; i < SBC_MAX; ++i)
if (__btowc (i) == WEOF)
bitset_set (sbcset, i);
@@ -3042,8 +3050,8 @@ parse_bracket_exp (regexp, dfa, token, syntax, err)
#ifdef RE_ENABLE_I18N
if (mbcset->nmbchars || mbcset->ncoll_syms || mbcset->nequiv_classes
- || mbcset->nranges || (MB_CUR_MAX > 1 && (mbcset->nchar_classes
- || mbcset->non_match)))
+ || mbcset->nranges || (dfa->mb_cur_max > 1 && (mbcset->nchar_classes
+ || mbcset->non_match)))
{
re_token_t alt_token;
bin_tree_t *mbc_tree;
@@ -3377,7 +3385,7 @@ build_charclass_op (dfa, trans, class_name, extra, not, err)
bitset_set(cset->sbcset, '\0');
*/
mbcset->non_match = 1;
- if (MB_CUR_MAX > 1)
+ if (dfa->mb_cur_max > 1)
for (i = 0; i < SBC_MAX; ++i)
if (__btowc (i) == WEOF)
bitset_set (sbcset, i);
@@ -3423,7 +3431,7 @@ build_charclass_op (dfa, trans, class_name, extra, not, err)
goto build_word_op_espace;
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (dfa->mb_cur_max > 1)
{
re_token_t alt_token;
bin_tree_t *mbc_tree;
diff --git a/posix/regex_internal.c b/posix/regex_internal.c
index e328243a57..329fc81de9 100644
--- a/posix/regex_internal.c
+++ b/posix/regex_internal.c
@@ -20,7 +20,8 @@
static void re_string_construct_common (const char *str, int len,
re_string_t *pstr,
- RE_TRANSLATE_TYPE trans, int icase);
+ RE_TRANSLATE_TYPE trans, int icase,
+ int mb_cur_max, int is_utf8);
#ifdef RE_ENABLE_I18N
static int re_string_skip_chars (re_string_t *pstr, int new_raw_idx,
wint_t *last_wc);
@@ -46,15 +47,17 @@ static unsigned int inline calc_state_hash (const re_node_set *nodes,
re_string_reconstruct before using the object. */
static reg_errcode_t
-re_string_allocate (pstr, str, len, init_len, trans, icase)
+re_string_allocate (pstr, str, len, init_len, trans, icase,
+ mb_cur_max, is_utf8)
re_string_t *pstr;
const char *str;
- int len, init_len, icase;
+ int len, init_len, icase, mb_cur_max, is_utf8;
RE_TRANSLATE_TYPE trans;
{
reg_errcode_t ret;
int init_buf_len = (len + 1 < init_len) ? len + 1: init_len;
- re_string_construct_common (str, len, pstr, trans, icase);
+ re_string_construct_common (str, len, pstr, trans, icase,
+ mb_cur_max, is_utf8);
pstr->stop = pstr->len;
ret = re_string_realloc_buffers (pstr, init_buf_len);
@@ -65,21 +68,22 @@ re_string_allocate (pstr, str, len, init_len, trans, icase)
: (unsigned char *) str);
pstr->mbs = MBS_ALLOCATED (pstr) ? pstr->mbs : pstr->mbs_case;
pstr->valid_len = (MBS_CASE_ALLOCATED (pstr) || MBS_ALLOCATED (pstr)
- || MB_CUR_MAX > 1) ? pstr->valid_len : len;
+ || mb_cur_max > 1) ? pstr->valid_len : len;
return REG_NOERROR;
}
/* This function allocate the buffers, and initialize them. */
static reg_errcode_t
-re_string_construct (pstr, str, len, trans, icase)
+re_string_construct (pstr, str, len, trans, icase, mb_cur_max, is_utf8)
re_string_t *pstr;
const char *str;
- int len, icase;
+ int len, icase, mb_cur_max, is_utf8;
RE_TRANSLATE_TYPE trans;
{
reg_errcode_t ret;
- re_string_construct_common (str, len, pstr, trans, icase);
+ re_string_construct_common (str, len, pstr, trans, icase,
+ mb_cur_max, is_utf8);
pstr->stop = pstr->len;
/* Set 0 so that this function can initialize whole buffers. */
pstr->valid_len = 0;
@@ -97,7 +101,7 @@ re_string_construct (pstr, str, len, trans, icase)
if (icase)
{
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (mb_cur_max > 1)
build_wcs_upper_buffer (pstr);
else
#endif /* RE_ENABLE_I18N */
@@ -106,7 +110,7 @@ re_string_construct (pstr, str, len, trans, icase)
else
{
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (mb_cur_max > 1)
build_wcs_buffer (pstr);
else
#endif /* RE_ENABLE_I18N */
@@ -131,7 +135,7 @@ re_string_realloc_buffers (pstr, new_buf_len)
int new_buf_len;
{
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (pstr->mb_cur_max > 1)
{
wint_t *new_array = re_realloc (pstr->wcs, wint_t, new_buf_len);
if (BE (new_array == NULL, 0))
@@ -163,18 +167,20 @@ re_string_realloc_buffers (pstr, new_buf_len)
static void
-re_string_construct_common (str, len, pstr, trans, icase)
+re_string_construct_common (str, len, pstr, trans, icase, mb_cur_max, is_utf8)
const char *str;
int len;
re_string_t *pstr;
RE_TRANSLATE_TYPE trans;
- int icase;
+ int icase, mb_cur_max, is_utf8;
{
memset (pstr, '\0', sizeof (re_string_t));
pstr->raw_mbs = (const unsigned char *) str;
pstr->len = len;
pstr->trans = trans;
pstr->icase = icase ? 1 : 0;
+ pstr->mb_cur_max = mb_cur_max;
+ pstr->is_utf8 = is_utf8;
}
#ifdef RE_ENABLE_I18N
@@ -372,7 +378,7 @@ re_string_translate_buffer (pstr)
}
/* This function re-construct the buffers.
- Concretely, convert to wide character in case of MB_CUR_MAX > 1,
+ Concretely, convert to wide character in case of pstr->mb_cur_max > 1,
convert to upper case in case of REG_ICASE, apply translation. */
static reg_errcode_t
@@ -385,7 +391,7 @@ re_string_reconstruct (pstr, idx, eflags, newline)
{
/* Reset buffer. */
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (pstr->mb_cur_max > 1)
memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
#endif /* RE_ENABLE_I18N */
pstr->len += pstr->raw_mbs_idx;
@@ -409,7 +415,7 @@ re_string_reconstruct (pstr, idx, eflags, newline)
pstr->tip_context = re_string_context_at (pstr, offset - 1, eflags,
newline);
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (pstr->mb_cur_max > 1)
memmove (pstr->wcs, pstr->wcs + offset,
(pstr->valid_len - offset) * sizeof (wint_t));
#endif /* RE_ENABLE_I18N */
@@ -429,13 +435,43 @@ re_string_reconstruct (pstr, idx, eflags, newline)
/* No, skip all characters until IDX. */
pstr->valid_len = 0;
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (pstr->mb_cur_max > 1)
{
int wcs_idx;
- wint_t wc;
- pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx;
- for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx)
- pstr->wcs[wcs_idx] = WEOF;
+ wint_t wc = WEOF;
+
+ if (pstr->is_utf8)
+ {
+ const unsigned char *raw, *p, *end;
+
+ /* Special case UTF-8. Multi-byte chars start with any
+ byte other than 0x80 - 0xbf. */
+ raw = pstr->raw_mbs + pstr->raw_mbs_idx;
+ end = raw + (pstr->valid_len > offset - pstr->mb_cur_max
+ ? pstr->valid_len : offset - pstr->mb_cur_max);
+ for (p = raw + offset - 1; p >= end; --p)
+ if ((*p & 0xc0) != 0x80)
+ {
+ mbstate_t cur_state;
+ wchar_t wc2;
+
+ memset (&cur_state, 0, sizeof (cur_state));
+ if (mbrtowc (&wc2, p, raw + offset - p, &cur_state)
+ == raw + offset - p)
+ {
+ memset (&pstr->cur_state, '\0',
+ sizeof (mbstate_t));
+ wc = wc2;
+ }
+ break;
+ }
+ }
+ if (wc == WEOF)
+ {
+ pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx;
+ for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx)
+ pstr->wcs[wcs_idx] = WEOF;
+ }
if (pstr->trans && wc <= 0xff)
wc = pstr->trans[wc];
pstr->tip_context = (IS_WIDE_WORD_CHAR (wc) ? CONTEXT_WORD
@@ -467,7 +503,7 @@ re_string_reconstruct (pstr, idx, eflags, newline)
/* Then build the buffers. */
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (pstr->mb_cur_max > 1)
{
if (pstr->icase)
build_wcs_upper_buffer (pstr);
@@ -519,7 +555,7 @@ re_string_context_at (input, idx, eflags, newline_anchor)
: CONTEXT_NEWLINE | CONTEXT_ENDBUF);
}
#ifdef RE_ENABLE_I18N
- if (MB_CUR_MAX > 1)
+ if (input->mb_cur_max > 1)
{
wint_t wc;
int wc_idx = idx;
@@ -1157,7 +1193,7 @@ create_ci_newstate (dfa, nodes, hash)
newstate->halt = 1;
#ifdef RE_ENABLE_I18N
else if (type == COMPLEX_BRACKET
- || (type == OP_PERIOD && MB_CUR_MAX > 1))
+ || (type == OP_PERIOD && dfa->mb_cur_max > 1))
newstate->accept_mb = 1;
#endif /* RE_ENABLE_I18N */
else if (type == OP_BACK_REF)<