Mercurial > hg > octave-jordi
changeset 19450:e5a78897be9e
Allow empty comma-separated lists in cell { } constructor (bug #43113).
* pt-cell.cc: Skip empty rows, where number of columns == 0, during
construction of cell. Use octave_idx_type for indexing into cell array
rather than int. Resize constructed cell array down to the number of
non-empty rows at the end of construction.
* parser.tst: Add tests for null row behavior.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 31 Dec 2014 10:40:18 -0800 |
parents | 7934b56c8b7b |
children | 05eb8eaf63d3 |
files | libinterp/parse-tree/pt-cell.cc test/parser.tst |
diffstat | 2 files changed, 20 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-cell.cc +++ b/libinterp/parse-tree/pt-cell.cc @@ -44,7 +44,7 @@ Cell val; - int i = 0; + octave_idx_type i = 0; for (iterator p = begin (); p != end (); p++) { @@ -65,10 +65,15 @@ { octave_idx_type this_nc = row.length (); - if (nc != this_nc) + if (this_nc != nc) { - ::error ("number of columns must match"); - return retval; + if (this_nc == 0) + continue; // blank line + else + { + ::error ("number of columns must match"); + return retval; + } } } @@ -78,6 +83,8 @@ i++; } + if (i < nr) + val.resize (dim_vector (i, nc)); // there were blank rows retval = val; return retval;
--- a/test/parser.tst +++ b/test/parser.tst @@ -19,6 +19,7 @@ ## Tests for parser problems belong in this file. ## We need many more tests here! +## Test cell construction operator {} %!assert ({1 2 {3 4}}, {1,2,{3,4}}) %!assert ({1, 2 {3 4}}, {1,2,{3,4}}) %!assert ({1 2, {3 4}}, {1,2,{3,4}}) @@ -28,6 +29,14 @@ %!assert ({1 2,{3,4}}, {1,2,{3,4}}) %!assert ({1,2,{3 4}}, {1,2,{3,4}}) +## bug #43113 using null comma-separated list in constructor +%!test +%! z = cell (1,2,3,0,5); +%! assert ({1, z{:}, 2}, {1, 2}); +%! assert ({1; z{:}; 2}, {1; 2}); +%! assert ({1 2; z{:}; 3 4}, {1, 2; 3 4}); +%! assert ({1 2; 5 z{:} 6; 3 4}, {1, 2; 5 6; 3 4}); + ## Tests for operator precedence as documented in section 8.8 of manual ## There are 13 levels of precedence from "parentheses and indexing" (highest) ## down to "statement operators" (lowest).