summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorK.Takata <kentkt@csc.jp>2019-01-29 19:00:12 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2026-01-12 20:01:42 +0900
commitf9131412f874aa348df383266cee7dc2cc82a9ca (patch)
tree2f7302d9b73c42f1cc09a3ebf98977c56e006d0d
parentbbf9bf3fc5c322ab8e622714b0178aca58e82191 (diff)
[k-takata/Onigmo] Revise set_bm_skip()
https://github.com/k-takata/Onigmo/commit/6875da50f7
-rw-r--r--regcomp.c89
-rw-r--r--regint.h2
2 files changed, 43 insertions, 48 deletions
diff --git a/regcomp.c b/regcomp.c
index 6ad72bcbd0..41154b5485 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -4225,64 +4225,59 @@ set_bm_skip(UChar* s, UChar* end, regex_t* reg,
OnigEncoding enc = reg->enc;
len = end - s;
- if (len < ONIG_CHAR_TABLE_SIZE) {
- if (ignore_case) {
- for (i = 0; i < len; i += clen) {
- p = s + i;
- n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
- p, end, items);
- clen = enclen(enc, p, end);
- if (p + clen > end)
- clen = (int )(end - p);
-
- for (j = 0; j < n; j++) {
- if ((items[j].code_len != 1) || (items[j].byte_len != clen)) {
- /* Different length isn't supported. Stop optimization at here. */
- end = p;
- goto endcheck;
- }
- flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf);
- if (flen != clen) {
- /* Different length isn't supported. Stop optimization at here. */
- end = p;
- goto endcheck;
- }
- }
- }
-endcheck:
- ;
- }
+ if (len >= ONIG_CHAR_TABLE_SIZE) {
+ /* This should not happen. */
+ return ONIGERR_TYPE_BUG;
+ }
- len = end - s;
- for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
- skip[i] = (UChar )(len + 1);
- n = 0;
+ if (ignore_case) {
for (i = 0; i < len; i += clen) {
p = s + i;
- if (ignore_case)
- n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
- p, end, items);
+ n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
+ p, end, items);
clen = enclen(enc, p, end);
if (p + clen > end)
clen = (int )(end - p);
- for (j = 0; j < clen; j++) {
- skip[s[i + j]] = (UChar )(len - i - j);
- for (k = 0; k < n; k++) {
- ONIGENC_CODE_TO_MBC(enc, items[k].code[0], buf);
- skip[buf[j]] = (UChar )(len - i - j);
- }
+ for (j = 0; j < n; j++) {
+ if ((items[j].code_len != 1) || (items[j].byte_len != clen)) {
+ /* Different length isn't supported. Stop optimization at here. */
+ end = p;
+ goto endcheck;
+ }
+ flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf);
+ if (flen != clen) {
+ /* Different length isn't supported. Stop optimization at here. */
+ end = p;
+ goto endcheck;
+ }
}
}
+endcheck:
+ len = end - s;
}
- else {
-# if OPT_EXACT_MAXLEN < ONIG_CHAR_TABLE_SIZE
- /* This should not happen. */
- return ONIGERR_TYPE_BUG;
-# else
-# error OPT_EXACT_MAXLEN exceeds ONIG_CHAR_TABLE_SIZE.
-# endif
+
+ for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
+ skip[i] = (UChar )(len + 1);
+ n = 0;
+ for (i = 0; i < len; i += clen) {
+ p = s + i;
+ if (ignore_case)
+ n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
+ p, end, items);
+ clen = enclen(enc, p, end);
+ if (p + clen > end)
+ clen = (int )(end - p);
+
+ for (j = 0; j < clen; j++) {
+ skip[s[i + j]] = (UChar )(len - i - j);
+ for (k = 0; k < n; k++) {
+ ONIGENC_CODE_TO_MBC(enc, items[k].code[0], buf);
+ skip[buf[j]] = (UChar )(len - i - j);
+ }
+ }
}
+
return (int)len;
}
diff --git a/regint.h b/regint.h
index 9d69e2d25e..0593fa2cc1 100644
--- a/regint.h
+++ b/regint.h
@@ -91,7 +91,7 @@
#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */
#define DEFAULT_PARSE_DEPTH_LIMIT 4096
-#define OPT_EXACT_MAXLEN 24
+#define OPT_EXACT_MAXLEN 24 /* This must be smaller than ONIG_CHAR_TABLE_SIZE. */
/* check config */
#if defined(USE_PERL_SUBEXP_CALL) || defined(USE_CAPITAL_P_NAMED_GROUP)