comparison scripts/general/num2str.m @ 20195: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
comparison
equal deleted inserted replaced
20193:88efded31037 20195:ea5fdb2ae637
113 else 113 else
114 ## Logical input 114 ## Logical input
115 fmt = "%3d"; 115 fmt = "%3d";
116 endif 116 endif
117 endif 117 endif
118 fmt = [deblank(repmat(fmt, 1, columns(x))), "\n"]; 118 fmt = do_string_escapes (fmt); # required now that '\n' is interpreted.
119 fmt = [deblank(repmat (fmt, 1, columns (x))), "\n"];
119 nd = ndims (x); 120 nd = ndims (x);
120 tmp = sprintf (fmt, permute (x, [2, 1, 3:nd])); 121 tmp = sprintf (fmt, permute (x, [2, 1, 3:nd]));
121 retval = strtrim (char (ostrsplit (tmp(1:end-1), "\n"))); 122 retval = strtrim (char (ostrsplit (tmp(1:end-1), "\n")));
122 else # Complex matrix input 123 else # Complex matrix input
123 if (nargin == 2) 124 if (nargin == 2)
202 ## FIXME: Integers greater than bitmax() should be masked to show just 203 ## FIXME: Integers greater than bitmax() should be masked to show just
203 ## 16 digits of precision. 204 ## 16 digits of precision.
204 %!xtest 205 %!xtest
205 %! assert (num2str (1e23), "100000000000000000000000"); 206 %! assert (num2str (1e23), "100000000000000000000000");
206 207
208 ## Test for bug #44864, extra rows generated from newlines in format
209 %!assert (rows (num2str (magic (3), '%3d %3d %3d\n')), 3)
210
207 %!error num2str () 211 %!error num2str ()
208 %!error num2str (1, 2, 3) 212 %!error num2str (1, 2, 3)
209 %!error <X must be a numeric> num2str ({1}) 213 %!error <X must be a numeric> num2str ({1})
210 %!error <PRECISION must be a scalar integer> num2str (1, {1}) 214 %!error <PRECISION must be a scalar integer> num2str (1, {1})
211 %!error <PRECISION must be a scalar integer> num2str (1, ones (2)) 215 %!error <PRECISION must be a scalar integer> num2str (1, ones (2))