IOStream.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013
00014
00015 #include "zypp/base/IOStream.h"
00016
00017 using std::endl;
00018
00020 namespace zypp
00021 {
00022
00023 namespace iostr
00024 {
00025
00026
00027
00028
00029
00030
00031 std::string getline( std::istream & str )
00032 {
00033 static const unsigned tmpBuffLen = 1024;
00034 static char tmpBuff[tmpBuffLen];
00035 std::string ret;
00036 do {
00037 str.clear();
00038 str.getline( tmpBuff, tmpBuffLen );
00039 ret += tmpBuff;
00040 } while( str.rdstate() == std::ios::failbit );
00041
00042 return ret;
00043 }
00044
00046
00047
00048
00050
00052
00053
00054
00055
00056 EachLine::EachLine( std::istream & str_r, unsigned lineNo_r )
00057 : _str( str_r )
00058 , _lineStart( -1 )
00059 , _lineNo( lineNo_r )
00060 , _valid( true )
00061 {
00062 next();
00063 }
00064
00066
00067
00068
00069
00070 bool EachLine::next()
00071 {
00072 if ( ! _valid )
00073 {
00074 return false;
00075 }
00076
00077 if ( ! _str )
00078 {
00079 _line.clear();
00080 return(_valid = false);
00081 }
00082
00083 _lineStart = _str.tellg();
00084 _line = iostr::getline( _str );
00085 ++_lineNo;
00086 if ( _str.fail() || _str.bad() )
00087 {
00088 _line.clear();
00089 return(_valid = false);
00090 }
00091 return(_valid = true);
00092 }
00093
00095 }
00098 }