diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2023-11-20 20:10:50 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2023-11-20 20:10:50 +0100 |
commit | 35e13e4c9637f5bf7bef6039c8c813207780a174 (patch) | |
tree | f2ea0b1aa455bb2552ffe8a7bb083f24e86d1f34 /src/regexec.c | |
parent | db6f38bc1b73930f1da954525464cf1986f43a28 (diff) |
New upstream version 6.9.9upstream/6.9.9upstream
Diffstat (limited to 'src/regexec.c')
-rw-r--r-- | src/regexec.c | 76 |
1 files changed, 47 insertions, 29 deletions
diff --git a/src/regexec.c b/src/regexec.c index cb8e620..496da3b 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -180,19 +180,7 @@ typedef struct { } MatchArg; -#if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH) - -/* arguments type */ -typedef enum { - ARG_SPECIAL = -1, - ARG_NON = 0, - ARG_RELADDR = 1, - ARG_ABSADDR = 2, - ARG_LENGTH = 3, - ARG_MEMNUM = 4, - ARG_OPTION = 5, - ARG_MODE = 6 -} OpArgType; +#if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH) || defined(ONIG_DEBUG_STATISTICS) typedef struct { short int opcode; @@ -299,6 +287,22 @@ static OpInfoType OpInfo[] = { { -1, ""} }; +#endif + +#if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH) + +/* arguments type */ +typedef enum { + ARG_SPECIAL = -1, + ARG_NON = 0, + ARG_RELADDR = 1, + ARG_ABSADDR = 2, + ARG_LENGTH = 3, + ARG_MEMNUM = 4, + ARG_OPTION = 5, + ARG_MODE = 6 +} OpArgType; + static char* op2name(int opcode) { @@ -2808,7 +2812,7 @@ typedef struct { #define MATCH_COUNTER_OUT(title) do {\ int i;\ - fprintf(DBGFP, "%s (%ld): retry limit: %8lu, subexp_call: %8lu\n", (title), (sstart - str), retry_in_match_counter, msa->subexp_call_in_search_counter); \ + fprintf(DBGFP, "%s (%ld): retry limit: %8lu/%8lu, subexp_call: %8lu\n", (title), (sstart - str), retry_in_match_counter, retry_limit_in_match, msa->subexp_call_in_search_counter); \ fprintf(DBGFP, " ");\ for (i = 0; i < MAX_SUBEXP_CALL_COUNTERS; i++) {\ fprintf(DBGFP, " %6lu", subexp_call_counters[i]);\ @@ -3038,39 +3042,43 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, BYTECODE_INTERPRETER_START { CASE_OP(END) + if (OPTON_MATCH_WHOLE_STRING(options)) { + if (! ON_STR_END(s)) goto fail; + } + n = (int )(s - sstart); if (n == 0 && OPTON_FIND_NOT_EMPTY(options)) { best_len = ONIG_MISMATCH; goto fail; /* for retry */ } - if (n > best_len) { #ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE - if (OPTON_FIND_LONGEST(options)) { + if (OPTON_FIND_LONGEST(options)) { + if (n > best_len) { if (n > msa->best_len) { + best_len = n; msa->best_len = n; msa->best_s = (UChar* )sstart; - if (s >= in_right_range) { - best_len = msa->best_len; /* end of find */ - } } else { if (s >= in_right_range && msa->best_s == sstart) { - best_len = msa->best_len; /* end of find */ + goto op_end_out; } else { - SOP_OUT; goto fail; /* for retry */ } } } else { - best_len = n; + goto fail; /* for retry */ } -#else + } + else { best_len = n; -#endif } +#else + best_len = n; +#endif /* set region */ region = msa->region; @@ -3135,14 +3143,14 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, #endif } /* if (region) */ - SOP_OUT; - if (OPTON_CALLBACK_EACH_MATCH(options) && IS_NOT_NULL(CallbackEachMatch)) { i = CallbackEachMatch(str, end, sstart, region, msa->mp->callout_user_data); - if (i < 0) MATCH_AT_ERROR_RETURN(i); - + if (i < 0) { + SOP_OUT; + MATCH_AT_ERROR_RETURN(i); + } #ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE if (! OPTON_FIND_LONGEST(options)) #endif @@ -3151,7 +3159,13 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, goto fail; } +#ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE + if (OPTON_FIND_LONGEST(options)) goto fail; +#endif + + op_end_out: /* default behavior: return first-matching result. */ + SOP_OUT; goto match_at_end; CASE_OP(STR_1) @@ -4398,6 +4412,11 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, #endif CASE_OP(FINISH) +#ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE + if (OPTON_FIND_LONGEST(options)) { + best_len = ONIG_MISMATCH; + } +#endif goto match_at_end; #ifdef ONIG_DEBUG_STATISTICS @@ -5455,7 +5474,6 @@ search_in_range(regex_t* reg, const UChar* str, const UChar* end, else goto finish; /* error */ \ } - /* anchor optimize: resume search range */ if (reg->anchor != 0 && str < end) { UChar *min_semi_end, *max_semi_end; |