1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : class basic_cstring comparisons implementation
13 // ***************************************************************************
15 #ifndef BOOST_TEST_UTILS_BASIC_CSTRING_COMPARE_HPP
16 #define BOOST_TEST_UTILS_BASIC_CSTRING_COMPARE_HPP
19 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
25 #include <boost/test/detail/suppress_warnings.hpp>
27 //____________________________________________________________________________//
29 # if defined(BOOST_NO_STDC_NAMESPACE) && !BOOST_WORKAROUND(__BORLANDC__, <= 0x570)
30 namespace std { using ::toupper; }
37 // ************************************************************************** //
38 // ************** case_ins_compare ************** //
39 // ************************************************************************** //
46 static bool eq( CharT c1, CharT c2 ) { return (std::toupper)( c1 ) == (std::toupper)( c2 ); }
47 static bool lt( CharT c1, CharT c2 ) { return (std::toupper)( c1 ) < (std::toupper)( c2 ); }
49 static int compare( CharT const* s1, CharT const* s2, std::size_t n )
51 for( std::size_t i = 0; i < n; ++i ) {
52 if( !eq( s1[i], s2[i] ) )
53 return lt( s1[i], s2[i] ) ? -1 : 1;
59 } // namespace ut_detail
61 // ************************************************************************** //
62 // ************** case_ins_eq ************** //
63 // ************************************************************************** //
67 case_ins_eq( basic_cstring<CharT> x, basic_cstring<CharT> y )
69 return x.size() == y.size() && ut_detail::case_ins<CharT>::compare( x.begin(), y.begin(), x.size() ) == 0;
72 //____________________________________________________________________________//
74 // ************************************************************************** //
75 // ************** case_ins_less ************** //
76 // ************************************************************************** //
79 class case_ins_less : public std::binary_function<basic_cstring<CharT>,basic_cstring<CharT>,bool>
82 bool operator()( basic_cstring<CharT> x, basic_cstring<CharT> y ) const
84 return x.size() != y.size()
86 : ut_detail::case_ins<CharT>::compare( x.begin(), y.begin(), x.size() ) < 0;
90 //____________________________________________________________________________//
92 // ************************************************************************** //
93 // ************** operators <,> ************** //
94 // ************************************************************************** //
98 operator <( boost::unit_test::basic_cstring<CharT> const& x,
99 boost::unit_test::basic_cstring<CharT> const& y )
101 typedef typename boost::unit_test::basic_cstring<CharT>::traits_type traits_type;
102 return x.size() != y.size()
103 ? x.size() < y.size()
104 : traits_type::compare( x.begin(), y.begin(), x.size() ) < 0;
107 //____________________________________________________________________________//
109 template<class CharT>
111 operator <=( boost::unit_test::basic_cstring<CharT> const& x,
112 boost::unit_test::basic_cstring<CharT> const& y )
117 //____________________________________________________________________________//
119 template<class CharT>
121 operator >( boost::unit_test::basic_cstring<CharT> const& x,
122 boost::unit_test::basic_cstring<CharT> const& y )
127 //____________________________________________________________________________//
129 template<class CharT>
131 operator >=( boost::unit_test::basic_cstring<CharT> const& x,
132 boost::unit_test::basic_cstring<CharT> const& y )
137 //____________________________________________________________________________//
139 } // namespace unit_test
143 //____________________________________________________________________________//
145 #include <boost/test/detail/enable_warnings.hpp>
147 #endif // BOOST_TEST_BASIC_CSTRING_COMPARE_HPP_071894GER