Mercurial > hg > octave-lyh
diff src/oct-stream.cc @ 4051:b79da8779a0e
[project @ 2002-08-17 19:38:32 by jwe]
author | jwe |
---|---|
date | Sat, 17 Aug 2002 19:38:33 +0000 |
parents | 47972b28e85e |
children | e0e95e9aad7b |
line wrap: on
line diff
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -28,12 +28,12 @@ #include <cstring> #include <iomanip> -#include <strstream> #include <fstream> #include <string> #include "lo-ieee.h" #include "lo-mappers.h" +#include "lo-sstream.h" #include "lo-utils.h" #include "str-vec.h" @@ -166,7 +166,7 @@ have_more = true; if (! buf) - buf = new std::ostrstream (); + buf = new OSSTREAM (); if (s[i] == '%') { @@ -241,25 +241,22 @@ { if (buf) { - *buf << std::ends; - - char *text = buf->str (); - - if (text) + *buf << OSSTREAM_ENDS; + + std::string text = OSSTREAM_STR (*buf); + + OSSTREAM_FREEZE (*buf); + + if (! text.empty ()) { - if (*text) - { - scanf_format_elt *elt - = new scanf_format_elt (text, width, discard, type, - modifier, char_class); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } - - delete [] text; + scanf_format_elt *elt + = new scanf_format_elt (text.c_str (), width, discard, type, + modifier, char_class); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; } delete buf; @@ -594,7 +591,7 @@ if (! buf) { - buf = new std::ostrstream (); + buf = new OSSTREAM (); empty_buf = true; } @@ -662,25 +659,22 @@ { if (buf) { - *buf << std::ends; - - char *text = buf->str (); - - if (text) + *buf << OSSTREAM_ENDS; + + std::string text = OSSTREAM_STR (*buf); + + OSSTREAM_FREEZE (*buf); + + if (! text.empty ()) { - if (*text) - { - printf_format_elt *elt - = new printf_format_elt (text, args, fw, prec, flags, - type, modifier); - - if (num_elts == list.length ()) - list.resize (2 * num_elts); - - list(num_elts++) = elt; - } - - delete [] text; + printf_format_elt *elt + = new printf_format_elt (text.c_str (), args, fw, prec, flags, + type, modifier); + + if (num_elts == list.length ()) + list.resize (2 * num_elts); + + list(num_elts++) = elt; } delete buf; @@ -941,9 +935,7 @@ { std::istream& is = *isp; - // XXX FIXME XXX -- this should probably be converted to use - // sstream when that is available. - std::ostrstream buf; + OSSTREAM buf; int c = 0; int char_count = 0; @@ -985,10 +977,9 @@ } else { - buf << std::ends; - char *tmp = buf.str (); - retval = tmp; - delete [] tmp; + buf << OSSTREAM_ENDS; + retval = OSSTREAM_STR (buf); + OSSTREAM_FREEZE (buf); } } else @@ -1229,38 +1220,42 @@ \ int width = elt->width ? elt->width : 1; \ \ - char *tmp = new char[width + 1]; \ + char *tbuf = new char[width + 1]; \ \ int c = EOF; \ int n = 0; \ \ while (is && n < width && (c = is.get ()) != EOF) \ - tmp[n++] = (char) c; \ + tbuf[n++] = (char) c; \ + \ + tbuf[n] = '\0'; \ \ - tmp[n] = '\0' + std::string tmp = tbuf; \ + \ + delete [] tbuf // For a `%s' format, skip initial whitespace and then read until the // next whitespace character. #define BEGIN_S_CONVERSION() \ int width = elt->width; \ \ - char *tmp = 0; \ + std::string tmp; \ \ do \ { \ if (width) \ { \ - tmp = new char [width+1]; \ + char *tbuf = new char [width+1]; \ + \ + OCTAVE_SCAN (is, *elt, tbuf); \ \ - OCTAVE_SCAN (is, *elt, tmp); \ - \ - tmp[width] = '\0'; \ + tbuf[width] = '\0'; \ + tmp = tbuf; \ + delete [] tbuf; \ } \ else \ { \ - std::string buf; \ - is >> std::ws >> buf; \ - tmp = strsave (buf.c_str()); \ + is >> std::ws >> tmp; \ } \ } \ while (0) @@ -1269,21 +1264,23 @@ #define BEGIN_CHAR_CLASS_CONVERSION() \ int width = elt->width; \ \ - char *tmp = 0; \ + std::string tmp; \ \ do \ { \ if (width) \ { \ - tmp = new char[width+1]; \ + char *tbuf = new char[width+1]; \ + \ + OCTAVE_SCAN (is, *elt, tbuf); \ \ - OCTAVE_SCAN (is, *elt, tmp); \ - \ - tmp[width] = '\0'; \ + tbuf[width] = '\0'; \ + tmp = tbuf; \ + delete [] tbuf; \ } \ else \ { \ - std::ostrstream buf; \ + OSSTREAM buf; \ \ std::string char_class = elt->char_class; \ \ @@ -1305,11 +1302,11 @@ if (c != EOF) \ is.putback (c); \ \ - buf << std::ends; \ + buf << OSSTREAM_ENDS; \ + tmp = OSSTREAM_STR (buf); \ + OSSTREAM_FREEZE (buf); \ \ - tmp = buf.str (); \ - \ - if (strlen (tmp) == 0) \ + if (tmp.empty ()) \ is.setstate (std::ios::failbit); \ } \ } \ @@ -1318,7 +1315,7 @@ #define FINISH_CHARACTER_CONVERSION() \ do \ { \ - width = strlen (tmp); \ + width = tmp.length (); \ \ if (is) \ { \ @@ -1351,8 +1348,6 @@ } \ } \ } \ - \ - delete [] tmp; \ } \ while (0) @@ -1818,8 +1813,6 @@ if (! discard) retval = tmp; - delete [] tmp; - if (! is) quit = true; @@ -1834,8 +1827,6 @@ if (! discard) retval = tmp; - delete [] tmp; - if (! is) quit = true; } @@ -1848,8 +1839,6 @@ if (! discard) retval = tmp; - delete [] tmp; - if (! is) quit = true; } @@ -3133,7 +3122,7 @@ // XXX FIXME XXX -- this should probably be converted to use sstream // when that is available. - std::ostrstream buf; + OSSTREAM buf; buf << "\n" << " number mode arch name\n" @@ -3162,13 +3151,11 @@ } } - buf << "\n" << std::ends; - - char *tmp = buf.str (); - - retval = tmp; - - delete [] tmp; + buf << "\n" << OSSTREAM_ENDS; + + retval = OSSTREAM_STR (buf); + + OSSTREAM_FREEZE (buf); return retval; }