Mercurial > hg > octave-nkf
changeset 14675:757f729fd41d
skip leading whitespace for scanf %i format
* oct-stream.cc (octave_scan_1<T>): Skip leading whitespace for %i
format.
* test_io.m: New tests for scanf.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 May 2012 13:36:24 -0400 |
parents | d95e719ef108 |
children | 9fa8955ea79d a543ed02e673 0b0569667939 |
files | src/oct-stream.cc test/test_io.m |
diffstat | 2 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -1107,9 +1107,12 @@ case 'i': { - int c1 = is.get (); - - if (! is.eof ()) + int c1 = EOF; + + while (is && (c1 = is.get ()) != EOF && isspace (c1)) + /* skip whitespace */; + + if (c1 != EOF) { if (c1 == '0') {
--- a/test/test_io.m +++ b/test/test_io.m @@ -250,6 +250,12 @@ %!assert (sscanf (['ab'; 'cd'], '%s'), 'acbd') +%!assert (sscanf ('02:08:30', '%i:%i:%i'), [2; 0]); +%!assert (sscanf ('02:08:30', '%d:%d:%d'), [2; 8; 30]); + +%!assert (sscanf ('0177 08', '%i'), [127; 0; 8]); +%!assert (sscanf ('0177 08', '%d'), [177; 8]); + %!test %! [val, count, msg, pos] = sscanf ("3I2", "%f"); %! assert (val, 3);