Skip to content

Commit

Permalink
Introduce PCRE2_SUBSTITUTE_MATCH_ONLY
Browse files Browse the repository at this point in the history
  • Loading branch information
cohomology committed Jan 15, 2020
1 parent 46f3237 commit fb11ec9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/pcre2.h.in
Expand Up @@ -183,6 +183,7 @@ pcre2_jit_match() ignores the latter since it bypasses all sanity checks). */
#define PCRE2_COPY_MATCHED_SUBJECT 0x00004000u
#define PCRE2_SUBSTITUTE_LITERAL 0x00008000u /* pcre2_substitute() only */
#define PCRE2_SUBSTITUTE_MATCHED 0x00010000u /* pcre2_substitute() only */
#define PCRE2_SUBSTITUTE_MATCH_ONLY 0x00020000u /* pcre2_substitute() only */

/* Options for pcre2_pattern_convert(). */

Expand Down
15 changes: 10 additions & 5 deletions src/pcre2_substitute.c
Expand Up @@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
(PCRE2_SUBSTITUTE_EXTENDED|PCRE2_SUBSTITUTE_GLOBAL| \
PCRE2_SUBSTITUTE_LITERAL|PCRE2_SUBSTITUTE_MATCHED| \
PCRE2_SUBSTITUTE_OVERFLOW_LENGTH|PCRE2_SUBSTITUTE_UNKNOWN_UNSET| \
PCRE2_SUBSTITUTE_UNSET_EMPTY)
PCRE2_SUBSTITUTE_UNSET_EMPTY|PCRE2_SUBSTITUTE_MATCH_ONLY)



Expand Down Expand Up @@ -320,7 +320,10 @@ if (start_offset > length)
rc = PCRE2_ERROR_BADOFFSET;
goto EXIT;
}
CHECKMEMCPY(subject, start_offset);
else if ((suboptions & PCRE2_SUBSTITUTE_MATCH_ONLY) == 0)
{
CHECKMEMCPY(subject, start_offset);
}

/* Loop for global substituting. If PCRE2_SUBSTITUTE_MATCHED is set, the first
match is taken from the match_data that was passed in. */
Expand Down Expand Up @@ -904,9 +907,11 @@ do
} while ((suboptions & PCRE2_SUBSTITUTE_GLOBAL) != 0); /* Repeat "do" loop */

/* Copy the rest of the subject. */

fraglength = length - start_offset;
CHECKMEMCPY(subject + start_offset, fraglength);
if ((suboptions & PCRE2_SUBSTITUTE_MATCH_ONLY) == 0)
{
fraglength = length - start_offset;
CHECKMEMCPY(subject + start_offset, fraglength);
}
temp[0] = 0;
CHECKMEMCPY(temp , 1);

Expand Down

0 comments on commit fb11ec9

Please sign in to comment.