Sierra Toolkit  Version of the Day
string_case_compare.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 
10 #ifndef stk_util_string_case_compare_hpp
11 #define stk_util_string_case_compare_hpp
12 
13 #include <strings.h>
14 #include <string>
15 #include <functional>
16 
17 namespace stk_classic {
18 
23 //----------------------------------------------------------------------
24 
26 inline
27 bool equal_case( const char * lhs , const char * rhs )
28 { return strcasecmp( lhs , rhs ) == 0 ; }
29 
31 inline
32 bool not_equal_case( const char * lhs , const char * rhs )
33 { return strcasecmp( lhs , rhs ) != 0 ; }
34 
36 inline
37 bool less_case( const char * lhs , const char * rhs )
38 { return strcasecmp( lhs , rhs ) < 0 ; }
39 
41 inline
42 bool less_equal_case( const char * lhs , const char * rhs )
43 { return strcasecmp( lhs , rhs ) <= 0 ; }
44 
46 inline
47 bool greater_case( const char * lhs , const char * rhs )
48 { return strcasecmp( lhs , rhs ) > 0 ; }
49 
51 inline
52 bool greater_equal_case( const char * lhs , const char * rhs )
53 { return strcasecmp( lhs , rhs ) >= 0 ; }
54 
55 //----------------------------------------------------------------------
56 
58 inline
59 bool equal_case( const std::string & lhs , const std::string & rhs )
60 { return strcasecmp( lhs.c_str() , rhs.c_str() ) == 0 ; }
61 
63 inline
64 bool not_equal_case( const std::string & lhs , const std::string & rhs )
65 { return strcasecmp( lhs.c_str() , rhs.c_str() ) != 0 ; }
66 
68 inline
69 bool less_case( const std::string & lhs , const std::string & rhs )
70 { return strcasecmp( lhs.c_str() , rhs.c_str() ) < 0 ; }
71 
73 inline
74 bool less_equal_case( const std::string & lhs , const std::string & rhs )
75 { return strcasecmp( lhs.c_str() , rhs.c_str() ) <= 0 ; }
76 
78 inline
79 bool greater_case( const std::string & lhs , const std::string & rhs )
80 { return strcasecmp( lhs.c_str() , rhs.c_str() ) > 0 ; }
81 
83 inline
84 bool greater_equal_case( const std::string & lhs , const std::string & rhs )
85 { return strcasecmp( lhs.c_str() , rhs.c_str() ) >= 0 ; }
86 
87 //----------------------------------------------------------------------
88 
90 struct EqualCase : public std::binary_function<std::string,std::string,bool> {
92  bool operator()( const std::string & lhs , const std::string & rhs ) const
93  { return equal_case( lhs , rhs ); }
94 };
95 
97 struct NotEqualCase : public std::binary_function<std::string,std::string,bool> {
99  bool operator()( const std::string & lhs , const std::string & rhs ) const
100  { return not_equal_case( lhs , rhs ); }
101 };
102 
104 struct LessCase : public std::binary_function<std::string,std::string,bool> {
106  bool operator()( const std::string & lhs , const std::string & rhs ) const
107  { return less_case( lhs , rhs ); }
108 };
109 
111 struct LessEqualCase : public std::binary_function<std::string,std::string,bool> {
113  bool operator()( const std::string & lhs , const std::string & rhs ) const
114  { return less_equal_case( lhs , rhs ); }
115 };
116 
118 struct GreaterCase : public std::binary_function<std::string,std::string,bool> {
120  bool operator()( const std::string & lhs , const std::string & rhs ) const
121  { return greater_case( lhs , rhs ); }
122 };
123 
125 struct GreaterEqualCase : public std::binary_function<std::string,std::string,bool> {
127  bool operator()( const std::string & lhs , const std::string & rhs ) const
128  { return greater_equal_case( lhs , rhs ); }
129 };
130 
131 //----------------------------------------------------------------------
132 
135 } // namespace stk_classic
136 
137 #endif /* stk_util_string_case_compare_hpp */
138 
Case-insensitive less-than-or-equal-to compare binary function object.
bool greater_equal_case(const char *lhs, const char *rhs)
Case-insensitive greater-than-or-equal-to compare.
bool greater_case(const char *lhs, const char *rhs)
Case-insensitive greater-than compare.
Case-insensitive less-than compare binary function object.
Case-insensitive equality compare binary function object.
bool not_equal_case(const char *lhs, const char *rhs)
Case-insensitive inequality compare.
bool operator()(const std::string &lhs, const std::string &rhs) const
Case-insensitive greater-than-or-equal-to compare binary function object.
Case-insensitive greater-than-or-equal-to compare binary function object.
Case-insensitive inequality compare binary function object.
bool less_equal_case(const char *lhs, const char *rhs)
Case-insensitive less-than-or-equal-to compare.
bool operator()(const std::string &lhs, const std::string &rhs) const
Case-insensitive inequality compare binary function object.
Case-insensitive greater-than compare binary function object.
bool less_case(const char *lhs, const char *rhs)
Case-insensitive less-than compare.
bool operator()(const std::string &lhs, const std::string &rhs) const
Case-insensitive less-than-or-equal-to compare binary function object.
Sierra Toolkit.
bool equal_case(const char *lhs, const char *rhs)
Case-insensitive equality compare.
bool operator()(const std::string &lhs, const std::string &rhs) const
Case-insensitive equality compare binary function object.
bool operator()(const std::string &lhs, const std::string &rhs) const
Case-insensitive greater-than compare binary function object.
bool operator()(const std::string &lhs, const std::string &rhs) const
Case-insensitive less-than compare binary function object.