From: stephan b. <sg...@us...> - 2004-12-25 18:58:58
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17795/src/System Modified Files: Mime.cpp Log Message: Added i/ostream operators for MimeType. Fixed mimeType() to return an empty string on an invalid (empty) type. Index: Mime.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Mime.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Mime.cpp 25 Dec 2004 18:08:03 -0000 1.8 +++ Mime.cpp 25 Dec 2004 18:58:49 -0000 1.9 @@ -110,6 +110,36 @@ { return lhs.mimeType() == rhs; } + +std::ostream & operator<<( std::ostream & os, const MimeType & m ) +{ + return os << m.mimeType(); +} + +std::istream & operator>>( std::istream & is, MimeType & m ) +{ + std::string buff; + // the following loop is so this func will work regardless + // of is' skipws flag... + char c; + while(1) + { + if( ! is.get(c) ) + { + return is; + } + if( std::isspace( c ) ) break; + buff += c; + } + MimeType tmp( buff ); + if( tmp.subType().empty() || tmp.mediaType().empty() ) + { + is.setstate( std::ios::failbit ); + return is; + } + m = tmp; + return is; +} MimeTypeDb::MimeTypeDb() |