Mercurial > hg > octave-lyh
diff src/oct-stream.cc @ 5338:c4b55d47122e
[project @ 2005-05-05 17:28:51 by jwe]
author | jwe |
---|---|
date | Thu, 05 May 2005 17:28:51 +0000 |
parents | 4f5faf0fd322 |
children | df230b7df93c |
line wrap: on
line diff
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -1469,7 +1469,7 @@ delete [] tbuf // For a `%s' format, skip initial whitespace and then read until the -// next whitespace character. +// next whitespace character or until WIDTH characters have been read. #define BEGIN_S_CONVERSION() \ int width = elt->width; \ \ @@ -1478,19 +1478,46 @@ do \ { \ if (width) \ - { \ - char *tbuf = new char [width+1]; \ + { \ + char *tbuf = new char [width+1]; \ + \ + int c = EOF; \ + \ + int n = 0; \ + \ + while (is && (c = is.get ()) != EOF) \ + { \ + if (! isspace (c)) \ + { \ + tbuf[n++] = static_cast<char> (c); \ + break; \ + } \ + } \ \ - OCTAVE_SCAN (is, *elt, tbuf); \ + while (is && n < width && (c = is.get ()) != EOF) \ + { \ + if (isspace (c)) \ + { \ + is.putback (c); \ + break; \ + } \ + else \ + tbuf[n++] = static_cast<char> (c); \ + } \ \ - tbuf[width] = '\0'; \ + tbuf[n] = '\0'; \ + \ + if (n > 0 && c == EOF) \ + is.clear (); \ + \ tmp = tbuf; \ + \ delete [] tbuf; \ - } \ + } \ else \ - { \ - is >> std::ws >> tmp; \ - } \ + { \ + is >> std::ws >> tmp; \ + } \ } \ while (0)