openModeller  Version 1.4.0
ignorecase_traits.hh
Go to the documentation of this file.
00001 #ifndef _ICSTRING_HH
00002 #define _ICSTRING_HH
00003 
00004 #include <string>
00005 #include <cctype>    // for std::toupper in this file and std::size_t in the .cpp
00006 
00007 #include <openmodeller/os_specific.hh>
00008 #include <openmodeller/om_defs.hh>
00009 
00010 // Define a char_traits struct to make strings case insensitive.
00011 // Taken from Josuttis.
00012 struct dllexp ignorecase_traits : std::char_traits<char>
00013 {
00014   static inline bool eq( const char& c1, const char& c2 ) {
00015     return std::toupper(c1)==std::toupper(c2);
00016   }
00017   static inline bool lt( const char& c1, const char& c2 ) {
00018     return std::toupper(c1)<std::toupper(c2);
00019   }
00020   static int compare(const char* s1, const char* s2, std::size_t n);
00021   static const char* find( const char* s,std::size_t n, const char& c );
00022 };
00023 
00024 class icstring : public std::basic_string< char, ignorecase_traits > {
00025 public:
00026   
00027   inline
00028   icstring() :
00029     std::basic_string<char,ignorecase_traits>()
00030   {}
00031 
00032   inline
00033   icstring( const std::string & rhs ) :
00034     std::basic_string<char,ignorecase_traits>( rhs.c_str() )
00035   {}
00036   
00037   inline
00038   icstring( const char* chrs ) :
00039     std::basic_string<char,ignorecase_traits>( chrs )
00040   {}
00041 
00042   inline operator std::string() const {
00043     return std::string( this->c_str() );
00044   }
00045 };
00046 
00047 
00048 
00049 #endif