diff src/oct-stream.cc @ 6767:a6c8000f113e

[project @ 2007-06-28 19:42:42 by jwe]
author jwe
date Thu, 28 Jun 2007 19:42:42 +0000
parents c3cd7d14fc5e
children c40c71200c65
line wrap: on
line diff
--- a/src/oct-stream.cc
+++ b/src/oct-stream.cc
@@ -1047,12 +1047,9 @@
 
 #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg)
 
-// FIXME -- this needs to be fixed to handle formats which
-// specify a maximum width.
-
 template <class T>
 std::istream&
-octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr)
+octave_scan_1 (std::istream& is, const scanf_format_elt& fmt, T* valptr)
 {
   T& ref = *valptr;
 
@@ -1108,6 +1105,30 @@
   return is;
 }
 
+template <class T>
+std::istream&
+octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr)
+{
+  if (fmt.width)
+    {
+      // Limit input to fmt.width characters by reading into a
+      // temporary stringstream buffer.
+
+      std::string tmp;
+
+      is.width (fmt.width);
+      is >> tmp;
+
+      std::istringstream ss (tmp);
+
+      octave_scan_1 (ss, fmt, valptr);
+    }
+  else
+    octave_scan_1 (is, fmt, valptr);
+
+  return is;
+}
+
 // Note that this specialization is only used for reading characters, not 
 // character strings. See BEGIN_S_CONVERSION for details.