@@ -3711,30 +3711,38 @@ CREATING A NEW STRING WITH SUBSTITUTIONS
37113711
37123712 If match_data is not NULL and PCRE2_SUBSTITUTE_MATCHED is not set, the
37133713 provided block is used for all calls to pcre2_match(), and its contents
3714- afterwards are the result of the final call. For global changes, this
3714+ afterwards are the result of the final call made internally by
3715+ pcre2_substitute() to the matching function. For global changes, this
37153716 will always be a no-match error. The contents of the ovector within the
37163717 match data block may or may not have been changed.
37173718
3718- As well as the usual options for pcre2_match(), a number of additional
3719- options can be set in the options argument of pcre2_substitute(). One
3720- such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external
3721- match_data block must be provided, and it must have already been used
3722- for an external call to pcre2_match() (or pcre2_jit_match()) with the
3723- same pattern, subject, effective subject length, start offset, and
3724- match option arguments (substitute-specific options can be added to the
3725- options argument). If any of these parameters is changed, pcre2_substi-
3726- tute() returns an error. The data in the match_data block (return code,
3727- offset vector) is used for the first substitution instead of calling
3728- pcre2_match() from within pcre2_substitute(). This allows an applica-
3729- tion to check for a match before choosing to substitute, without having
3730- to repeat the match.
3731-
3732- The contents of the externally supplied match data block are not
3733- changed when PCRE2_SUBSTITUTE_MATCHED is set. If PCRE2_SUBSTI-
3734- TUTE_GLOBAL is also set, pcre2_match() is called after the first sub-
3735- stitution to check for further matches, but this is done using an in-
3736- ternally obtained match data block, thus always leaving the external
3737- block unchanged.
3719+ As well as the usual options for pcre2_match(), a number of additional
3720+ options can be set in the options argument of pcre2_substitute(). One
3721+ such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external
3722+ match_data block must be provided, and it must have already been used
3723+ for an external call to pcre2_match() (or pcre2_jit_match()) with the
3724+ same pattern, subject pointer, effective subject length, start offset,
3725+ and match option arguments (substitute-specific options can be added to
3726+ the options argument). If any of these parameters is changed,
3727+ pcre2_substitute() returns an error. The data in the match_data block
3728+ (return code, offset vector) is used for the first substitution instead
3729+ of calling pcre2_match() from within pcre2_substitute(). This allows an
3730+ application to check for a match before choosing to substitute, without
3731+ having to repeat the match.
3732+
3733+ If the contents of the subject buffer are mutated in between
3734+ pcre2_match() and a call to pcre2_substitute() with PCRE2_SUBSTI-
3735+ TUTE_MATCHED, the behaviour is unsafe; in particular, in this case,
3736+ PCRE2 is unable to ensure that the offsets in the ovector point to the
3737+ start of characters (with UTF-encoded input).
3738+
3739+ The contents of the externally supplied match data block are not
3740+ changed when PCRE2_SUBSTITUTE_MATCHED is set, and so the match block is
3741+ permitted for use in another call using PCRE2_SUBSTITUTE_MATCHED. If
3742+ PCRE2_SUBSTITUTE_GLOBAL is also set, pcre2_match() is called after the
3743+ first substitution to check for furthe matches, but this is done using
3744+ an internally obtained match data block, thus always leaving the exter-
3745+ nal block unchanged.
37383746
37393747 The code argument is not used for matching before the first substitu-
37403748 tion when PCRE2_SUBSTITUTE_MATCHED is set, but it must be provided,
0 commit comments