Mercurial > octave
diff libinterp/corefcn/file-io.cc @ 28182:56349d9ca566
Fix textscan when literal and delimiter might be the same character (bug #58008).
* file-io.cc (Ftextscan): Add BIST test for bug #58008.
* oct-stream.cc (textscan::read_format_once): Skip delimiters at beginning of
text before trying to match new fmt element. However, if fmt element is a
literal which begins with a delimiter character, don't skip, because text
must match exactly.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 28 Mar 2020 15:59:47 -0700 |
parents | 9cb04a9e81ec |
children | abcff237241f |
line wrap: on
line diff
--- a/libinterp/corefcn/file-io.cc Fri Mar 27 13:13:09 2020 -0700 +++ b/libinterp/corefcn/file-io.cc Sat Mar 28 15:59:47 2020 -0700 @@ -2285,6 +2285,14 @@ %! obs = textscan (str, "%q", "delimiter", ","); %! assert (obs, { { "a,b"; "c" } }); +%!test <*58008> +%! txt = sprintf ('literal_other_1_1;literal_other_1_2\nliteral_other_2_1;literal_other_2_2\nliteral_other_3_1;literal_other_3_2'); +%! nm1 = textscan (txt, 'literal%s literal%s', 'Delimiter', ';'); +%! assert (nm1{1}, {"_other_1_1" ; "_other_2_1" ; "_other_3_1"}); +%! assert (nm1{2}, {"_other_1_2" ; "_other_2_2" ; "_other_3_2"}); +%! nm2 = textscan (txt, 'literal%s;literal%s', 'Delimiter', ';'); +%! assert (nm1, nm2); + */ // These tests have end-comment sequences, so can't just be in a comment #if 0