diff options
author | ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069> | 2014-11-11 16:51:07 +0000 |
---|---|---|
committer | ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069> | 2014-11-11 16:51:07 +0000 |
commit | 78bf9ce77125f21369990121ce4f8ee56b061654 (patch) | |
tree | 69f571c972630bb97763132e6a560161b4910990 /src/pcre2_substitute.c | |
parent | b0203c3ee3c9e3f9ad2ad26797c574ce2b264d22 (diff) | |
download | pcre2-78bf9ce77125f21369990121ce4f8ee56b061654.tar.gz |
Substitute code update and documentation.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@143 6239d852-aaf2-0410-a92c-79f79f948069
Diffstat (limited to 'src/pcre2_substitute.c')
-rw-r--r-- | src/pcre2_substitute.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/pcre2_substitute.c b/src/pcre2_substitute.c index 1100c93..341a9a9 100644 --- a/src/pcre2_substitute.c +++ b/src/pcre2_substitute.c @@ -67,8 +67,8 @@ Arguments: buffer where to put the substituted string blength points to length of buffer; updated to length of string -Returns: > 0 number of substitutions made - < 0 an error code, including PCRE2_ERROR_NOMATCH if no match +Returns: >= 0 number of substitutions made + < 0 an error code PCRE2_ERROR_BADREPLACEMENT means invalid use of $ */ @@ -78,8 +78,8 @@ pcre2_substitute(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, pcre2_match_context *mcontext, PCRE2_SPTR replacement, PCRE2_SIZE rlength, PCRE2_UCHAR *buffer, PCRE2_SIZE *blength) { -int rc = 0; -int subs = 0; +int rc; +int subs; uint32_t ovector_count; uint32_t goptions = 0; BOOL match_data_created = FALSE; @@ -91,7 +91,7 @@ PCRE2_SIZE *ovector; if ((options & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0) return PCRE2_ERROR_BADOPTION; - + /* If no match data block is provided, create one. */ if (match_data == NULL) @@ -106,6 +106,21 @@ if (match_data == NULL) ovector = pcre2_get_ovector_pointer(match_data); ovector_count = pcre2_get_ovector_count(match_data); +/* Check UTF replacement string if necessary. */ + +#ifdef SUPPORT_UNICODE +if ((code->overall_options & PCRE2_UTF) != 0 && + (options & PCRE2_NO_UTF_CHECK) == 0) + { + rc = PRIV(valid_utf)(replacement, rlength, &(match_data->rightchar)); + if (rc != 0) + { + match_data->leftchar = 0; + goto EXIT; + } + } +#endif /* SUPPORT_UNICODE */ + /* Notice the global option and remove it from the options that are passed to pcre2_match(). */ @@ -129,6 +144,7 @@ lengthleft = *blength - start_offset; /* Loop for global substituting. */ +subs = 0; do { PCRE2_SIZE i; @@ -273,6 +289,7 @@ buffer[buff_offset] = 0; EXIT: if (match_data_created) pcre2_match_data_free(match_data); + else match_data->rc = rc; return rc; NOROOM: |