Mercurial > hg > octave-nkf
diff src/oct-stream.cc @ 7426:b9df9abdffbb
[project @ 2008-01-28 21:07:58 by jwe]
author | jwe |
---|---|
date | Mon, 28 Jan 2008 21:07:59 +0000 |
parents | fab9bc33b949 |
children | 65f0a8ced9d2 |
line wrap: on
line diff
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -1040,12 +1040,6 @@ return do_gets (max_len, err, false, who); } -#if defined (__GNUG__) && ! defined (CXX_ISO_COMPLIANT_LIBRARY) - -#define OCTAVE_SCAN(is, fmt, arg) is.scan ((fmt).text, arg) - -#else - #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg) template <class T> @@ -1340,8 +1334,6 @@ return is; } -#endif - template <class T> void do_scanf_conv (std::istream& is, const scanf_format_elt& fmt, @@ -1548,45 +1540,37 @@ \ do \ { \ - if (width) \ - { \ - char *tbuf = new char[width+1]; \ + if (! width) \ + width = INT_MAX; + + std::ostringstream buf; \ + \ + std::string char_class = elt->char_class; \ \ - OCTAVE_SCAN (is, *elt, tbuf); \ + int c = EOF; \ \ - tbuf[width] = '\0'; \ - tmp = tbuf; \ - delete [] tbuf; \ + if (elt->type == '[') \ + { \ + int chars_read = 0; \ + while (is && chars_read++ < width && (c = is.get ()) != EOF \ + && char_class.find (c) != NPOS) \ + buf << static_cast<char> (c); \ } \ else \ { \ - std::ostringstream buf; \ - \ - std::string char_class = elt->char_class; \ - \ - int c = EOF; \ + int chars_read = 0; \ + while (is && chars_read++ < width && (c = is.get ()) != EOF \ + && char_class.find (c) == NPOS) \ + buf << static_cast<char> (c); \ + } \ \ - if (elt->type == '[') \ - { \ - while (is && (c = is.get ()) != EOF \ - && char_class.find (c) != NPOS) \ - buf << static_cast<char> (c); \ - } \ - else \ - { \ - while (is && (c = is.get ()) != EOF \ - && char_class.find (c) == NPOS) \ - buf << static_cast<char> (c); \ - } \ + if (width == INT_MAX && c != EOF) \ + is.putback (c); \ \ - if (c != EOF) \ - is.putback (c); \ + tmp = buf.str (); \ \ - tmp = buf.str (); \ - \ - if (tmp.empty ()) \ - is.setstate (std::ios::failbit); \ - } \ + if (tmp.empty ()) \ + is.setstate (std::ios::failbit); \ } \ while (0)