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(BOOST_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 // ************************************************************************** //
82 typedef bool result_type;
83 typedef basic_cstring<CharT> first_argument_type;
84 typedef basic_cstring<CharT> second_argument_type;
86 bool operator()( basic_cstring<CharT> x, basic_cstring<CharT> y ) const
88 return x.size() != y.size()
90 : ut_detail::case_ins<CharT>::compare( x.begin(), y.begin(), x.size() ) < 0;
94 //____________________________________________________________________________//
96 // ************************************************************************** //
97 // ************** operators <,> ************** //
98 // ************************************************************************** //
100 template<class CharT>
102 operator <( boost::unit_test::basic_cstring<CharT> const& x,
103 boost::unit_test::basic_cstring<CharT> const& y )
105 typedef typename boost::unit_test::basic_cstring<CharT>::traits_type traits_type;
106 return x.size() != y.size()
107 ? x.size() < y.size()
108 : traits_type::compare( x.begin(), y.begin(), x.size() ) < 0;
111 //____________________________________________________________________________//
113 template<class CharT>
115 operator <=( boost::unit_test::basic_cstring<CharT> const& x,
116 boost::unit_test::basic_cstring<CharT> const& y )
121 //____________________________________________________________________________//
123 template<class CharT>
125 operator >( boost::unit_test::basic_cstring<CharT> const& x,
126 boost::unit_test::basic_cstring<CharT> const& y )
131 //____________________________________________________________________________//
133 template<class CharT>
135 operator >=( boost::unit_test::basic_cstring<CharT> const& x,
136 boost::unit_test::basic_cstring<CharT> const& y )
141 //____________________________________________________________________________//
143 } // namespace unit_test
147 //____________________________________________________________________________//
149 #include <boost/test/detail/enable_warnings.hpp>
151 #endif // BOOST_TEST_BASIC_CSTRING_COMPARE_HPP_071894GER