Mercurial > octave-nkf
comparison libinterp/corefcn/regexp.cc @ 20325:b6a59cc96bfa
Process backslashes in regexprep replacement strings in Matlab compatible fashion (bug #45407).
* NEWS: Announce change. Backslashed escaped ordinary characters are now
replaced by the character itself with no emitted warning.
* regexp.cc (do_regexp_rep_string_escapes): Change default case statement to
silently convert unrecognized escaped character to the bare character itself.
Pass the special sequences of '$' and '\' through since these must be handled
by lo-regexp.cc.
* regexp.cc (Fregexprep): Add BIST tests for new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 29 Jun 2015 08:56:22 -0700 |
parents | a9574e3c6e9e |
children | 1a0a433c8263 |
comparison
equal
deleted
inserted
replaced
20324:13ede127ec9a | 20325:b6a59cc96bfa |
---|---|
243 retval[i] = tmpi; | 243 retval[i] = tmpi; |
244 j = k - 1; | 244 j = k - 1; |
245 break; | 245 break; |
246 } | 246 } |
247 | 247 |
248 default: // pass escape sequence through | 248 // Both dollar sign (for capture buffer) and backslash are |
249 retval[i] = '\\'; | 249 // passed through with their escape backslash. The processing |
250 retval[++i] = s[j]; | 250 // for these must occur during the actual replacement operation |
251 // in lo-regexp.cc. | |
252 case '$': // pass dollar sign through with escape | |
253 retval[i] = '\\'; retval[++i] = '$'; | |
254 break; | |
255 | |
256 case '\\': // pass backslash through with escape | |
257 retval[i] = '\\'; retval[++i] = '\\'; | |
258 break; | |
259 | |
260 default: // convert escaped character to unescaped char | |
261 retval[i] = s[j]; | |
251 break; | 262 break; |
252 } | 263 } |
253 } | 264 } |
254 else | 265 else |
255 { | 266 { |
1149 %! assert (a, {"oo"}); | 1160 %! assert (a, {"oo"}); |
1150 %! assert (b, {"f", " bar"}); | 1161 %! assert (b, {"f", " bar"}); |
1151 | 1162 |
1152 %!assert (regexp ("\n", '\n'), 1); | 1163 %!assert (regexp ("\n", '\n'), 1); |
1153 %!assert (regexp ("\n", "\n"), 1); | 1164 %!assert (regexp ("\n", "\n"), 1); |
1165 | |
1166 %!test # Bug #45407, escape sequences are silently converted | |
1167 %! assert (regexprep ('s', 's', 'x\.y'), 'x.y'); | |
1168 %! assert (regexprep ('s', '(s)', 'x\$1y'), 'x$1y'); | |
1169 %! assert (regexprep ('s', '(s)', 'x\\$1y'), 'x\sy'); | |
1170 | |
1154 */ | 1171 */ |
1155 | 1172 |
1156 DEFUN (regexpi, args, nargout, | 1173 DEFUN (regexpi, args, nargout, |
1157 "-*- texinfo -*-\n\ | 1174 "-*- texinfo -*-\n\ |
1158 @deftypefn {Built-in Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat})\n\ | 1175 @deftypefn {Built-in Function} {[@var{s}, @var{e}, @var{te}, @var{m}, @var{t}, @var{nm}, @var{sp}] =} regexpi (@var{str}, @var{pat})\n\ |