From f2b36b324956d6908d2c45d0a3e9f53127a05cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Tue, 14 Dec 2004 20:21:21 +0000 Subject: [PATCH] bugfix, now it works for empty lines --- mrw/stdext.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mrw/stdext.cpp b/mrw/stdext.cpp index 2936dd9..65775ed 100644 --- a/mrw/stdext.cpp +++ b/mrw/stdext.cpp @@ -9,6 +9,9 @@ @license LGPL, see file COPYING $Log$ + Revision 1.2 2004/12/14 20:21:21 marc + bugfix, now it works for empty lines + Revision 1.1 2004/10/13 11:18:33 marc getline reads a whole line from a stream @@ -18,15 +21,8 @@ #include std::string mrw::getline(std::istream& is, char d) { - char buf[255]; - char c; std::string s; - do { - if (is && is.get(buf, 255, d)) { - s += buf; - if (is.get(c) && c!=d) s+=c; - } - } while (is.good() && !is.eof() && c!=d); + mrw::getline(is, s, d); return s; } @@ -35,8 +31,9 @@ std::istream& mrw::getline(std::istream& is, std::string& s, char d) { char c; s.clear(); do { - if (is && is.get(buf, 255, d)) { - s += buf; + if (is) { + if (is.get(buf, 255, d)) s += buf; + is.clear(); // is.get fails if line is empty if (is.get(c) && c!=d) s+=c; } } while (is.good() && !is.eof() && c!=d);