Mercurial > hg > octave-nkf
changeset 20419:eae5e4d58740 stable
strread.m: properly process format repeat counter, add tests
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Wed, 20 May 2015 22:40:11 +0200 |
parents | f638a61af5a8 |
children | 6af35d4f1ba4 |
files | scripts/io/strread.m |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/io/strread.m +++ b/scripts/io/strread.m @@ -703,6 +703,9 @@ lastline = ... min (num_words_per_line * format_repeat_count + m - 1, numel (words)); data = words(m:num_words_per_line:lastline); + if (num_lines > format_repeat_count) + num_lines = format_repeat_count; + endif endif ## Map to format @@ -879,6 +882,18 @@ %! a = strread ("a b c, d e, , f", "%s", "delimiter", ","); %! assert (a, {"a b c"; "d e"; ""; "f"}); +%! ## Format repeat counters w & w/o trailing EOL even within partly read files +%!test +%! [a, b] = strread ("10 a 20 b\n 30 c 40", "%d %s", 4); +%! assert (a, int32 ([10; 20; 30; 40])); +%! assert (b, {"a"; "b"; "c"}); +%! [a, b] = strread ("10 a 20 b\n 30 c 40\n", "%d %s", 4); +%! assert (a, int32 ([10; 20; 30; 40])); +%! assert (b, {"a"; "b"; "c"; ""}); +%! [a, b] = strread ("10 a 20 b\n 30 c 40", "%d %s", 1); +%! assert (a, int32 (10)); +%! assert (b, {"a"}); + %!test %! ## Bug #33536 %! [a, b, c] = strread ("1,,2", "%s%s%s", "delimiter", ","); @@ -1040,7 +1055,7 @@ %! assert (b, [2; 5; 8]); %! assert (c, [3; 6; 9]); -## Test #3 bug #42609 +## Test #4 bug #42609 %!test %! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", '%f %f\n%f'); %! assert (a, [1;4;7]);