228int forcecasereset = 0;
229uint32_t ovector_count;
230uint32_t goptions = 0;
235BOOL use_existing_match;
236BOOL replacement_only;
237#ifdef SUPPORT_UNICODE
245PCRE2_SIZE buff_offset, buff_length, lengthleft, fraglength;
253lengthleft = buff_length = *blength;
255ovecsave[0] = ovecsave[1] = ovecsave[2] =
PCRE2_UNSET;
266if (replacement ==
NULL)
273repend = replacement + rlength;
289if (match_data ==
NULL)
293 gcontext = (mcontext ==
NULL)?
296 match_data = internal_match_data =
301else if (use_existing_match)
306 int pairs = (code->top_bracket + 1 < match_data->oveccount)?
307 code->top_bracket + 1 : match_data->oveccount;
313 internal_match_data->heapframes =
NULL;
314 internal_match_data->heapframes_size = 0;
315 match_data = internal_match_data;
328scb.ovector = ovector;
345#ifdef SUPPORT_UNICODE
348 rc =
PRIV(
valid_utf)(replacement, rlength, &(match_data->startchar));
351 match_data->leftchar = 0;
364if (start_offset > length)
366 match_data->leftchar = 0;
373if (!replacement_only)
CHECKMEMCPY(subject, start_offset);
382 uint32_t ptrstackptr = 0;
384 if (use_existing_match)
387 use_existing_match =
FALSE;
390 match_data, mcontext);
392#ifdef SUPPORT_UNICODE
406 if (goptions == 0 || start_offset >= length)
break;
413 save_start = start_offset++;
414 if (subject[start_offset-1] ==
CHAR_CR &&
417 start_offset < length &&
418 subject[start_offset] ==
CHAR_LF)
423 else if ((code->overall_options &
PCRE2_UTF) != 0)
425#if PCRE2_CODE_UNIT_WIDTH == 8
426 while (start_offset < length && (subject[start_offset] & 0xc0) == 0x80)
428#elif PCRE2_CODE_UNIT_WIDTH == 16
429 while (start_offset < length &&
430 (subject[start_offset] & 0xfc00) == 0xdc00)
438 fraglength = start_offset - save_start;
439 if (!replacement_only)
CHECKMEMCPY(subject + save_start, fraglength);
447 if (ovector[1] < ovector[0] || ovector[0] < start_offset)
461 if (ovecsave[0] == ovector[0] && ovecsave[1] == ovector[1])
463 if (ovector[0] == ovector[1] && ovecsave[2] != start_offset)
466 ovecsave[2] = start_offset;
486 if (rc == 0) rc = ovector_count;
487 fraglength = ovector[0] - start_offset;
488 if (!replacement_only)
CHECKMEMCPY(subject + start_offset, fraglength);
489 scb.output_offsets[0] = buff_offset;
515 if (ptrstackptr == 0)
break;
516 repend = ptrstack[--ptrstackptr];
517 ptr = ptrstack[--ptrstackptr];
527 escaped_literal =
FALSE;
539 uint32_t special = 0;
550 if (++
ptr >= repend)
goto BAD;
560 if (++
ptr >= repend)
goto BAD;
567 if (++
ptr >= repend)
goto BAD;
575 while (++
ptr < repend)
586 if (group > code->top_bracket)
607 if (
n > 32)
goto BAD;
608 if (++
ptr >= repend)
break;
611 if (
n == 0)
goto BAD;
631 rc = find_text_end(code, &
ptr, repend, special ==
CHAR_MINUS);
632 if (rc != 0)
goto PTREXIT;
638 rc = find_text_end(code, &
ptr, repend,
TRUE);
639 if (rc != 0)
goto PTREXIT;
667 while (*mark != 0) mark++;
668 fraglength = mark - mark_start;
694 group = code->top_bracket + 1;
698 if (rc < 0)
goto PTREXIT;
699 for (entry = first; entry <=
last; entry += rc)
701 uint32_t ng =
GET2(entry, 0);
702 if (ng < ovector_count)
704 if (group < 0) group = ng;
716 if (group < 0) group =
GET2(first, 0);
748 if (rc == 0)
goto LITERAL_SUBSTITUTE;
749 text2_start = text1_start;
750 text2_end = text1_end;
754 ptrstack[ptrstackptr++] =
ptr;
755 ptrstack[ptrstackptr++] = repend;
773 subptr = subject + ovector[group*2];
774 subptrend = subject + ovector[group*2 + 1];
778 while (subptr < subptrend)
783#ifdef SUPPORT_UNICODE
796 )[
ch/8] & (1u << (
ch%8))) == 0)
799 forcecase = forcecasereset;
802#ifdef SUPPORT_UNICODE
824 if (
ptr < repend - 1)
switch (
ptr[1])
827 forcecase = forcecasereset = -1;
838 forcecase = forcecasereset = 1;
854 code->overall_options, code->extra_options,
FALSE,
NULL);
855 if (errorcode != 0)
goto BADESCAPE;
860 forcecase = forcecasereset = 0;
864 escaped_literal =
TRUE;
885#ifdef SUPPORT_UNICODE
898 )[
ch/8] & (1u << (
ch%8))) == 0)
901 forcecase = forcecasereset;
904#ifdef SUPPORT_UNICODE
919 if (!overflowed && mcontext !=
NULL && mcontext->substitute_callout !=
NULL)
921 scb.subscount = subs;
922 scb.output_offsets[1] = buff_offset;
923 rc = mcontext->substitute_callout(&scb, mcontext->substitute_callout_data);
930 PCRE2_SIZE newlength = scb.output_offsets[1] - scb.output_offsets[0];
931 PCRE2_SIZE oldlength = ovector[1] - ovector[0];
933 buff_offset -= newlength;
934 lengthleft += newlength;
935 if (!replacement_only)
CHECKMEMCPY(subject + ovector[0], oldlength);
948 ovecsave[0] = ovector[0];
949 ovecsave[1] = ovector[1];
950 ovecsave[2] = start_offset;
952 goptions = (ovector[0] != ovector[1] || ovector[0] > start_offset)? 0 :
954 start_offset = ovector[1];
960if (!replacement_only)
962 fraglength = length - start_offset;
976 *blength = buff_length + extra_needed;
985 *blength = buff_offset - 1;
990 else match_data->rc = rc;