File indexing completed on 2025-01-18 09:52:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_UTILS_BASIC_CSTRING_COMPARE_HPP
0016 #define BOOST_TEST_UTILS_BASIC_CSTRING_COMPARE_HPP
0017
0018
0019 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
0020
0021
0022 #include <functional>
0023 #include <cctype>
0024
0025 #include <boost/test/detail/suppress_warnings.hpp>
0026
0027
0028
0029 # if defined(BOOST_NO_STDC_NAMESPACE) && !BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x570)
0030 namespace std { using ::toupper; }
0031 # endif
0032
0033 namespace boost {
0034
0035 namespace unit_test {
0036
0037
0038
0039
0040
0041 namespace ut_detail {
0042
0043 template<class CharT>
0044 struct case_ins
0045 {
0046 static bool eq( CharT c1, CharT c2 ) { return (std::toupper)( c1 ) == (std::toupper)( c2 ); }
0047 static bool lt( CharT c1, CharT c2 ) { return (std::toupper)( c1 ) < (std::toupper)( c2 ); }
0048
0049 static int compare( CharT const* s1, CharT const* s2, std::size_t n )
0050 {
0051 for( std::size_t i = 0; i < n; ++i ) {
0052 if( !eq( s1[i], s2[i] ) )
0053 return lt( s1[i], s2[i] ) ? -1 : 1;
0054 }
0055 return 0;
0056 }
0057 };
0058
0059 }
0060
0061
0062
0063
0064
0065 template<class CharT>
0066 inline bool
0067 case_ins_eq( basic_cstring<CharT> x, basic_cstring<CharT> y )
0068 {
0069 return x.size() == y.size() && ut_detail::case_ins<CharT>::compare( x.begin(), y.begin(), x.size() ) == 0;
0070 }
0071
0072
0073
0074
0075
0076
0077
0078 template<class CharT>
0079 class case_ins_less
0080 {
0081 public:
0082 typedef bool result_type;
0083 typedef basic_cstring<CharT> first_argument_type;
0084 typedef basic_cstring<CharT> second_argument_type;
0085
0086 bool operator()( basic_cstring<CharT> x, basic_cstring<CharT> y ) const
0087 {
0088 return x.size() != y.size()
0089 ? x.size() < y.size()
0090 : ut_detail::case_ins<CharT>::compare( x.begin(), y.begin(), x.size() ) < 0;
0091 }
0092 };
0093
0094
0095
0096
0097
0098
0099
0100 template<class CharT>
0101 inline bool
0102 operator <( boost::unit_test::basic_cstring<CharT> const& x,
0103 boost::unit_test::basic_cstring<CharT> const& y )
0104 {
0105 typedef typename boost::unit_test::basic_cstring<CharT>::traits_type traits_type;
0106 return x.size() != y.size()
0107 ? x.size() < y.size()
0108 : traits_type::compare( x.begin(), y.begin(), x.size() ) < 0;
0109 }
0110
0111
0112
0113 template<class CharT>
0114 inline bool
0115 operator <=( boost::unit_test::basic_cstring<CharT> const& x,
0116 boost::unit_test::basic_cstring<CharT> const& y )
0117 {
0118 return !(y < x);
0119 }
0120
0121
0122
0123 template<class CharT>
0124 inline bool
0125 operator >( boost::unit_test::basic_cstring<CharT> const& x,
0126 boost::unit_test::basic_cstring<CharT> const& y )
0127 {
0128 return y < x;
0129 }
0130
0131
0132
0133 template<class CharT>
0134 inline bool
0135 operator >=( boost::unit_test::basic_cstring<CharT> const& x,
0136 boost::unit_test::basic_cstring<CharT> const& y )
0137 {
0138 return !(x < y);
0139 }
0140
0141
0142
0143 }
0144
0145 }
0146
0147
0148
0149 #include <boost/test/detail/enable_warnings.hpp>
0150
0151 #endif