]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/include/boost/test/utils/basic_cstring/compare.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / include / boost / test / utils / basic_cstring / compare.hpp
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)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 // File : $RCSfile$
9 //
10 // Version : $Revision$
11 //
12 // Description : class basic_cstring comparisons implementation
13 // ***************************************************************************
14
15 #ifndef BOOST_TEST_UTILS_BASIC_CSTRING_COMPARE_HPP
16 #define BOOST_TEST_UTILS_BASIC_CSTRING_COMPARE_HPP
17
18 // Boost.Test
19 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
20
21 // STL
22 #include <functional>
23 #include <cctype>
24
25 #include <boost/test/detail/suppress_warnings.hpp>
26
27 //____________________________________________________________________________//
28
29 # if defined(BOOST_NO_STDC_NAMESPACE) && !BOOST_WORKAROUND(__BORLANDC__, <= 0x570)
30 namespace std { using ::toupper; }
31 # endif
32
33 namespace boost {
34
35 namespace unit_test {
36
37 // ************************************************************************** //
38 // ************** case_ins_compare ************** //
39 // ************************************************************************** //
40
41 namespace ut_detail {
42
43 template<class CharT>
44 struct case_ins
45 {
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 ); }
48
49 static int compare( CharT const* s1, CharT const* s2, std::size_t n )
50 {
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;
54 }
55 return 0;
56 }
57 };
58
59 } // namespace ut_detail
60
61 // ************************************************************************** //
62 // ************** case_ins_eq ************** //
63 // ************************************************************************** //
64
65 template<class CharT>
66 inline bool
67 case_ins_eq( basic_cstring<CharT> x, basic_cstring<CharT> y )
68 {
69 return x.size() == y.size() && ut_detail::case_ins<CharT>::compare( x.begin(), y.begin(), x.size() ) == 0;
70 }
71
72 //____________________________________________________________________________//
73
74 // ************************************************************************** //
75 // ************** case_ins_less ************** //
76 // ************************************************************************** //
77
78 template<class CharT>
79 class case_ins_less : public std::binary_function<basic_cstring<CharT>,basic_cstring<CharT>,bool>
80 {
81 public:
82 bool operator()( basic_cstring<CharT> x, basic_cstring<CharT> y ) const
83 {
84 return x.size() != y.size()
85 ? x.size() < y.size()
86 : ut_detail::case_ins<CharT>::compare( x.begin(), y.begin(), x.size() ) < 0;
87 }
88 };
89
90 //____________________________________________________________________________//
91
92 // ************************************************************************** //
93 // ************** operators <,> ************** //
94 // ************************************************************************** //
95
96 template<class CharT>
97 inline bool
98 operator <( boost::unit_test::basic_cstring<CharT> const& x,
99 boost::unit_test::basic_cstring<CharT> const& y )
100 {
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;
105 }
106
107 //____________________________________________________________________________//
108
109 template<class CharT>
110 inline bool
111 operator <=( boost::unit_test::basic_cstring<CharT> const& x,
112 boost::unit_test::basic_cstring<CharT> const& y )
113 {
114 return !(y < x);
115 }
116
117 //____________________________________________________________________________//
118
119 template<class CharT>
120 inline bool
121 operator >( boost::unit_test::basic_cstring<CharT> const& x,
122 boost::unit_test::basic_cstring<CharT> const& y )
123 {
124 return y < x;
125 }
126
127 //____________________________________________________________________________//
128
129 template<class CharT>
130 inline bool
131 operator >=( boost::unit_test::basic_cstring<CharT> const& x,
132 boost::unit_test::basic_cstring<CharT> const& y )
133 {
134 return !(x < y);
135 }
136
137 //____________________________________________________________________________//
138
139 } // namespace unit_test
140
141 } // namespace boost
142
143 //____________________________________________________________________________//
144
145 #include <boost/test/detail/enable_warnings.hpp>
146
147 #endif // BOOST_TEST_BASIC_CSTRING_COMPARE_HPP_071894GER