Mercurial > octave
changeset 22724:611794516332 stable
Fix regexp handling of beginning/end word match for double-quoted pattern strings (bug #49451).
* regexp.cc (do_regexp_ptn_string_escapes): Add additional function input
"bool is_sq_str". If is_sq_str, replace '\b' with backspace, otherwise leave
alone.
* regexp.cc (octregexp, octregexprep): Pass both single and double quoted pattern
strings through 'do_regexp_ptn_string_escapes' so that Matlab beginning/end word match
patterns can be replaced by their PCRCE equivalent.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 04 Nov 2016 08:14:44 -0700 |
parents | 766b0163b3b7 |
children | 37e53505e2eb |
files | libinterp/corefcn/regexp.cc |
diffstat | 1 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/regexp.cc Thu Nov 03 14:17:37 2016 -0700 +++ b/libinterp/corefcn/regexp.cc Fri Nov 04 08:14:44 2016 -0700 @@ -50,7 +50,7 @@ // is different from those used in the *printf functions. static std::string -do_regexp_ptn_string_escapes (const std::string& s) +do_regexp_ptn_string_escapes (const std::string& s, bool is_sq_str) { std::string retval; @@ -67,7 +67,14 @@ switch (s[++j]) { case 'b': // backspace - retval[i] = '\b'; + if (is_sq_str) + retval[i] = '\b'; + else + { + // Pass escape sequence through + retval[i] = '\\'; + retval[++i] = 'b'; + } break; // Translate \< and \> to PCRE word boundary @@ -335,9 +342,8 @@ std::string pattern = args(1).string_value (); - // Matlab compatibility. - if (args(1).is_sq_string ()) - pattern = do_regexp_ptn_string_escapes (pattern); + // Rewrite pattern for PCRE + pattern = do_regexp_ptn_string_escapes (pattern, args(1).is_sq_string ()); octave::regexp::opts options; options.case_insensitive (case_insensitive); @@ -1297,9 +1303,8 @@ std::string pattern = args(1).string_value (); - // Matlab compatibility. - if (args(1).is_sq_string ()) - pattern = do_regexp_ptn_string_escapes (pattern); + // Rewrite pattern for PCRE + pattern = do_regexp_ptn_string_escapes (pattern, args(1).is_sq_string ()); std::string replacement = args(2).string_value ();