# HG changeset patch # User jwe # Date 1201554479 0 # Node ID b9df9abdffbbc7f4b1d7b5c7787c1c7a03d0a83b # Parent fe4a43e1d1d38bafc10032e6a6041bdbb3fdbfee [project @ 2008-01-28 21:07:58 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2008-01-28 John W. Eaton + + * oct-stream.cc (BEGIN_CHAR_CLASS_CONVERSION): Handle width properly. + (OCTAVE_SCAN) [__GNUG__ && ! CXX_ISO_COMPLIANT_LIBRARY]: + Delete special case. + 2008-01-25 David Bateman * DLD-FUNCTIONS/rand.cc (Frandp): Relax relative error on randp diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- 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 @@ -1340,8 +1334,6 @@ return is; } -#endif - template 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 (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 (c); \ + } \ \ - if (elt->type == '[') \ - { \ - while (is && (c = is.get ()) != EOF \ - && char_class.find (c) != NPOS) \ - buf << static_cast (c); \ - } \ - else \ - { \ - while (is && (c = is.get ()) != EOF \ - && char_class.find (c) == NPOS) \ - buf << static_cast (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)