#ifndef __MIMETYPE_H #define __MIMETYPE_H #include #include #include #include #include "CrawlerExportable.hpp" class MIMEType { protected: std::string m_type; std::string m_subtype; public: MIMEType( ) : m_type( "" ), m_subtype( "" ) { } MIMEType( const std::string _type, const std::string _subtype ) : m_type( _type ), m_subtype( _subtype ) { } MIMEType( const MIMEType &m ) : m_type( m.m_type ), m_subtype( m.m_subtype ) { } MIMEType( const char *s ) { const char *pos; if( ( pos = strchr( s, '/' ) ) == NULL ) { *this = Null; } else { m_type = std::string( s, 0, pos - s ); m_subtype = std::string( s, pos - s + 1, strlen( s ) - ( pos - s + 1 ) ); } } MIMEType& operator=( const MIMEType &m ) { if( this != &m ) { this->m_type = m.m_type; this->m_subtype = m.m_subtype; } return *this; } const std::string type( ) const { return m_type; } const std::string subtype( ) const { return m_subtype; } std::string str( ) const { std::ostringstream os; os << *this; return os.str( ); } static CRAWLER_DLL_VISIBLE MIMEType Null; bool operator!=( const MIMEType &other ) const { return( str( ) != other.str( ) ); } bool operator==( const MIMEType &other ) const { return( str( ) == other.str( ) ); } bool operator<( const MIMEType &other ) const { return( str( ) < other.str( ) ); } template< typename CharT, typename TraitsT > friend std::basic_ostream< CharT, TraitsT >& operator<<( std::basic_ostream&s, const MIMEType& m ); }; template< typename CharT, typename TraitsT > inline std::basic_ostream< CharT, TraitsT >& operator<<( std::basic_ostream< CharT, TraitsT > &s, const MIMEType &m ) { if( m.type( ).empty( ) ) { return s; } s << m.type( ) << "/" << m.subtype( ); return s; } #endif