string_case_compare.hpp

00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #ifndef stk_util_string_case_compare_hpp
00011 #define stk_util_string_case_compare_hpp
00012 
00013 #include <strings.h>
00014 #include <string>
00015 #include <functional>
00016 
00017 namespace stk {
00018 
00023 //----------------------------------------------------------------------
00024 
00026 inline
00027 bool equal_case( const char * lhs , const char * rhs )
00028 { return strcasecmp( lhs , rhs ) == 0 ; }
00029 
00031 inline
00032 bool not_equal_case( const char * lhs , const char * rhs )
00033 { return strcasecmp( lhs , rhs ) != 0 ; }
00034 
00036 inline
00037 bool less_case( const char * lhs , const char * rhs )
00038 { return strcasecmp( lhs , rhs ) < 0 ; }
00039 
00041 inline
00042 bool less_equal_case( const char * lhs , const char * rhs )
00043 { return strcasecmp( lhs , rhs ) <= 0 ; }
00044 
00046 inline
00047 bool greater_case( const char * lhs , const char * rhs )
00048 { return strcasecmp( lhs , rhs ) > 0 ; }
00049 
00051 inline
00052 bool greater_equal_case( const char * lhs , const char * rhs )
00053 { return strcasecmp( lhs , rhs ) >= 0 ; }
00054 
00055 //----------------------------------------------------------------------
00056 
00058 inline
00059 bool equal_case( const std::string & lhs , const std::string & rhs )
00060 { return strcasecmp( lhs.c_str() , rhs.c_str() ) == 0 ; }
00061 
00063 inline
00064 bool not_equal_case( const std::string & lhs , const std::string & rhs )
00065 { return strcasecmp( lhs.c_str() , rhs.c_str() ) != 0 ; }
00066 
00068 inline
00069 bool less_case( const std::string & lhs , const std::string & rhs )
00070 { return strcasecmp( lhs.c_str() , rhs.c_str() ) < 0 ; }
00071 
00073 inline
00074 bool less_equal_case( const std::string & lhs , const std::string & rhs )
00075 { return strcasecmp( lhs.c_str() , rhs.c_str() ) <= 0 ; }
00076 
00078 inline
00079 bool greater_case( const std::string & lhs , const std::string & rhs )
00080 { return strcasecmp( lhs.c_str() , rhs.c_str() ) > 0 ; }
00081 
00083 inline
00084 bool greater_equal_case( const std::string & lhs , const std::string & rhs )
00085 { return strcasecmp( lhs.c_str() , rhs.c_str() ) >= 0 ; }
00086 
00087 //----------------------------------------------------------------------
00088 
00090 struct EqualCase : public std::binary_function<std::string,std::string,bool> {
00092   bool operator()( const std::string & lhs , const std::string & rhs ) const
00093     { return equal_case( lhs , rhs ); }
00094 };
00095 
00097 struct NotEqualCase : public std::binary_function<std::string,std::string,bool> {
00099   bool operator()( const std::string & lhs , const std::string & rhs ) const
00100     { return not_equal_case( lhs , rhs ); }
00101 };
00102 
00104 struct LessCase : public std::binary_function<std::string,std::string,bool> {
00106   bool operator()( const std::string & lhs , const std::string & rhs ) const
00107     { return less_case( lhs , rhs ); }
00108 };
00109 
00111 struct LessEqualCase : public std::binary_function<std::string,std::string,bool> {
00113   bool operator()( const std::string & lhs , const std::string & rhs ) const
00114     { return less_equal_case( lhs , rhs ); }
00115 };
00116 
00118 struct GreaterCase : public std::binary_function<std::string,std::string,bool> {
00120   bool operator()( const std::string & lhs , const std::string & rhs ) const
00121     { return greater_case( lhs , rhs ); }
00122 };
00123 
00125 struct GreaterEqualCase : public std::binary_function<std::string,std::string,bool> {
00127   bool operator()( const std::string & lhs , const std::string & rhs ) const
00128     { return greater_equal_case( lhs , rhs ); }
00129 };
00130 
00131 //----------------------------------------------------------------------
00132 
00135 } // namespace stk
00136 
00137 #endif /* stk_util_string_case_compare_hpp */
00138 

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7