1
0
Fork 0

Additional enhancements.

This commit is contained in:
curt 1998-09-24 15:22:17 +00:00
parent af80c5e018
commit 605ad52197
2 changed files with 82 additions and 2 deletions

View file

@ -33,6 +33,15 @@ fg_gzifstream::fg_gzifstream( const string& name, int io_mode )
open( name, io_mode ); open( name, io_mode );
} }
//-----------------------------------------------------------------------------
//
// Attach a stream to an already opened file descriptor.
//
fg_gzifstream::fg_gzifstream( int fd, int io_mode )
: gzstream( fd, io_mode )
{
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Open a possibly gzipped file for reading. // Open a possibly gzipped file for reading.
@ -51,7 +60,8 @@ fg_gzifstream::open( const string& name, int io_mode )
if ( s.substr( s.length() - 3, 3 ) == ".gz" ) if ( s.substr( s.length() - 3, 3 ) == ".gz" )
{ {
// remove ".gz" suffix // remove ".gz" suffix
s.erase( s.length() - 3, 3 ); s.replace( s.length() - 3, 3, "" );
// s.erase( s.length() - 3, 3 );
} }
else else
{ {
@ -106,14 +116,68 @@ fg_gzifstream::eat_comments()
} }
// skip to end of line. // skip to end of line.
while ( gzstream.get(c) && c != '\n' ) while ( gzstream.get(c) && (c != '\n' && c != '\r') )
; ;
} }
return gzstream; return gzstream;
} }
//
// Manipulators
//
istream&
skipeol( istream& in )
{
char c = 0;
// skip to end of line.
while ( in.get(c) && (c != '\n' && c != '\r') )
;
// \r\n ?
return in;
}
istream&
skipws( istream& in )
{
char c;
while ( in.get(c) )
{
if ( ! isspace( c ) )
{
// put pack the non-space character
in.putback(c);
break;
}
}
return in;
}
istream&
skipcomment( istream& in )
{
while ( in )
{
// skip whitespace
in >> skipws;
char c;
if ( in.get( c ) && c != '#' )
{
// not a comment
in.putback(c);
break;
}
in >> skipeol;
}
return in;
}
// $Log$ // $Log$
// Revision 1.2 1998/09/24 15:22:17 curt
// Additional enhancements.
//
// Revision 1.1 1998/09/01 19:06:29 curt // Revision 1.1 1998/09/01 19:06:29 curt
// Initial revision. // Initial revision.
// //

View file

@ -50,6 +50,9 @@ public:
fg_gzifstream( const string& name, fg_gzifstream( const string& name,
int io_mode = ios::in|ios::binary ); int io_mode = ios::in|ios::binary );
//
fg_gzifstream( int fd, int io_mode = ios::in|ios::binary );
// Attempt to open a file with and without ".gz" extension. // Attempt to open a file with and without ".gz" extension.
void open( const string& name, void open( const string& name,
int io_mode = ios::in|ios::binary ); int io_mode = ios::in|ios::binary );
@ -86,9 +89,22 @@ private:
fg_gzifstream( const fg_gzifstream& ); fg_gzifstream( const fg_gzifstream& );
}; };
// istream manipulator that skips to end of line.
istream& skipeol( istream& in );
// istream manipulator that skips over white space.
istream& skipws( istream& in );
// istream manipulator that skips comments and white space.
// A comment starts with '#'.
istream& skipcomment( istream& in );
#endif /* _FGSTREAM_HXX */ #endif /* _FGSTREAM_HXX */
// $Log$ // $Log$
// Revision 1.2 1998/09/24 15:22:18 curt
// Additional enhancements.
//
// Revision 1.1 1998/09/01 19:06:29 curt // Revision 1.1 1998/09/01 19:06:29 curt
// Initial revision. // Initial revision.
// //