changeset 7426:b9df9abdffbb

[project @ 2008-01-28 21:07:58 by jwe]
author jwe
date Mon, 28 Jan 2008 21:07:59 +0000
parents fe4a43e1d1d3
children 65f0a8ced9d2
files src/ChangeLog src/oct-stream.cc
diffstat 2 files changed, 29 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Jan 28 09:13:01 2008 +0000
+++ b/src/ChangeLog	Mon Jan 28 21:07:59 2008 +0000
@@ -1,3 +1,9 @@
+2008-01-28  John W. Eaton  <jwe@octave.org>
+
+	* 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  <dbateman@free.fr>
 
 	* DLD-FUNCTIONS/rand.cc (Frandp): Relax relative error on randp
--- a/src/oct-stream.cc	Mon Jan 28 09:13:01 2008 +0000
+++ b/src/oct-stream.cc	Mon Jan 28 21:07:59 2008 +0000
@@ -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)