修复pcre2_compile中参数顺序错误,支持utf8的替换,俄语不区分大小写测试通过。

This commit is contained in:
zhengchao
2019-06-03 13:00:27 +08:00
parent ace31ae24a
commit 044d512184
2 changed files with 55 additions and 7 deletions

View File

@@ -192,15 +192,15 @@ size_t replace_string(const char * in, size_t in_sz, const struct replace_rule *
{
assert(strlen(zone->find) != 0);
int error;
PCRE2_SIZE erroffset;
int error=0;
PCRE2_SIZE erroffset=0;
const PCRE2_SPTR pattern = (PCRE2_SPTR)zone->find;
const PCRE2_SPTR subject = (PCRE2_SPTR)in;
const PCRE2_SPTR replacement = (PCRE2_SPTR)zone->replace_with;
pcre2_code *re = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, 0, &error, &erroffset, 0);
if (re == 0)
pcre2_code *re = pcre2_compile(pattern, strlen(zone->find), PCRE2_UTF, &error, &erroffset, 0);
if (!re)
return -1;
pcre2_jit_compile(re, PCRE2_JIT_COMPLETE);
@@ -211,7 +211,11 @@ size_t replace_string(const char * in, size_t in_sz, const struct replace_rule *
not_enough_mem_retry:
out_buffer = (PCRE2_UCHAR*)malloc(sizeof(PCRE2_UCHAR)*outbuff_size);
outlen = outbuff_size;
int rc = pcre2_substitute(re, subject, in_sz, 0, PCRE2_SUBSTITUTE_GLOBAL | PCRE2_SUBSTITUTE_EXTENDED | PCRE2_SUBSTITUTE_OVERFLOW_LENGTH, 0, 0, replacement, PCRE2_ZERO_TERMINATED, out_buffer, &outlen);
int rc = pcre2_substitute(re, subject, in_sz, 0,
PCRE2_SUBSTITUTE_GLOBAL | PCRE2_SUBSTITUTE_EXTENDED | PCRE2_SUBSTITUTE_OVERFLOW_LENGTH,
0, 0, //pcre2_match_data *match_data, pcre2_match_context
replacement, strlen(zone->replace_with),
out_buffer, &outlen);
if(outlen>outbuff_size)
{
outbuff_size=outlen;