Mercurial > hg > octave-nkf
diff scripts/general/num2str.m @ 20405:ea5fdb2ae637
num2str.m: Correctly parse newlines in single-quoted format strings (bug #44684).
* num2str.m: Use do_string_escapes on format specification before any further
processing.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 07 May 2015 22:04:10 +0200 |
parents | 7503499a252b |
children | f357e076776f |
line wrap: on
line diff
--- a/scripts/general/num2str.m +++ b/scripts/general/num2str.m @@ -115,7 +115,8 @@ fmt = "%3d"; endif endif - fmt = [deblank(repmat(fmt, 1, columns(x))), "\n"]; + fmt = do_string_escapes (fmt); # required now that '\n' is interpreted. + fmt = [deblank(repmat (fmt, 1, columns (x))), "\n"]; nd = ndims (x); tmp = sprintf (fmt, permute (x, [2, 1, 3:nd])); retval = strtrim (char (ostrsplit (tmp(1:end-1), "\n"))); @@ -204,6 +205,9 @@ %!xtest %! assert (num2str (1e23), "100000000000000000000000"); +## Test for bug #44864, extra rows generated from newlines in format +%!assert (rows (num2str (magic (3), '%3d %3d %3d\n')), 3) + %!error num2str () %!error num2str (1, 2, 3) %!error <X must be a numeric> num2str ({1})