diff options
author | zherczeg <zherczeg@6239d852-aaf2-0410-a92c-79f79f948069> | 2017-05-24 15:22:03 +0000 |
---|---|---|
committer | zherczeg <zherczeg@6239d852-aaf2-0410-a92c-79f79f948069> | 2017-05-24 15:22:03 +0000 |
commit | 7374c677789f87d071ce9d9237369d05044f25cf (patch) | |
tree | 9bc3741c5c94efdb8aa45c4a2e5e1bb7cfec7349 /src/pcre2_convert.c | |
parent | 292895b249c9e24dd537f17b7859f9a77c5faef8 (diff) | |
download | pcre2-7374c677789f87d071ce9d9237369d05044f25cf.tar.gz |
Support the general case of starstar in glob conversion.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@803 6239d852-aaf2-0410-a92c-79f79f948069
Diffstat (limited to 'src/pcre2_convert.c')
-rw-r--r-- | src/pcre2_convert.c | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/src/pcre2_convert.c b/src/pcre2_convert.c index 1d055f8..ea99556 100644 --- a/src/pcre2_convert.c +++ b/src/pcre2_convert.c @@ -616,7 +616,9 @@ prev_c = 0; if (*pattern == CHAR_RIGHT_SQUARE_BRACKET) { - convert_glob_write(out, CHAR_RIGHT_SQUARE_BRACKET); + out->out_str[0] = CHAR_BACKSLASH; + out->out_str[1] = CHAR_RIGHT_SQUARE_BRACKET; + convert_glob_write_str(out, 2); has_prev_c = TRUE; prev_c = CHAR_RIGHT_SQUARE_BRACKET; pattern++; @@ -777,8 +779,8 @@ BOOL no_wildsep = (options & PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR) != 0; BOOL no_starstar = (options & PCRE2_CONVERT_GLOB_NO_STARSTAR) != 0; BOOL in_atomic = FALSE; BOOL after_starstar = FALSE; -BOOL with_escape, is_start; -int result, len; +BOOL with_escape, is_start, after_separator; +int result; (void)utf; /* Avoid compiler warning. */ @@ -840,11 +842,7 @@ while (pattern < pattern_end) if (!no_starstar && pattern < pattern_end && *pattern == CHAR_ASTERISK) { - if (!is_start && pattern[-2] != separator) - { - result = PCRE2_ERROR_CONVERT_SYNTAX; - break; - } + after_separator = is_start || (pattern[-2] == separator); do pattern++; while (pattern < pattern_end && *pattern == CHAR_ASTERISK); @@ -855,27 +853,16 @@ while (pattern < pattern_end) break; } - if (escape != 0 && *pattern == escape) - { - pattern++; - if (pattern >= pattern_end) - { - result = PCRE2_ERROR_CONVERT_SYNTAX; - break; - } - } - - if (*pattern != separator) - { - result = PCRE2_ERROR_CONVERT_SYNTAX; - break; - } - - pattern++; after_starstar = TRUE; + if (after_separator && escape != 0 && *pattern == escape && + pattern + 1 < pattern_end && pattern[1] == separator) + pattern++; + if (is_start) { + if (*pattern != separator) continue; + out.out_str[0] = CHAR_LEFT_PARENTHESIS; out.out_str[1] = CHAR_QUESTION_MARK; out.out_str[2] = CHAR_COLON; @@ -886,32 +873,39 @@ while (pattern < pattern_end) convert_glob_print_separator(&out, separator, with_escape); convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); + + pattern++; continue; } convert_glob_print_commit(&out); + if (!after_separator || *pattern != separator) + { + out.out_str[0] = CHAR_DOT; + out.out_str[1] = CHAR_ASTERISK; + out.out_str[2] = CHAR_QUESTION_MARK; + convert_glob_write_str(&out, 3); + continue; + } + out.out_str[0] = CHAR_LEFT_PARENTHESIS; out.out_str[1] = CHAR_QUESTION_MARK; out.out_str[2] = CHAR_COLON; out.out_str[3] = CHAR_DOT; out.out_str[4] = CHAR_ASTERISK; out.out_str[5] = CHAR_QUESTION_MARK; - len = 6; - if (with_escape) - { - out.out_str[6] = CHAR_BACKSLASH; - len = 7; - } + convert_glob_write_str(&out, 6); - convert_glob_write_str(&out, len); + convert_glob_print_separator(&out, separator, with_escape); - out.out_str[0] = (uint8_t) separator; - out.out_str[1] = CHAR_RIGHT_PARENTHESIS; + out.out_str[0] = CHAR_RIGHT_PARENTHESIS; + out.out_str[1] = CHAR_QUESTION_MARK; out.out_str[2] = CHAR_QUESTION_MARK; - out.out_str[3] = CHAR_QUESTION_MARK; - convert_glob_write_str(&out, 4); + convert_glob_write_str(&out, 3); + + pattern++; continue; } |