source: NonGTP/Boost/boost/test/utils/basic_cstring/compare.hpp @ 857

Revision 857, 4.9 KB checked in by igarcia, 19 years ago (diff)
Line 
1//  (C) Copyright Gennadiy Rozental 2004-2005.
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: compare.hpp,v $
9//
10//  Version     : $Revision: 1.5 $
11//
12//  Description : class basic_cstring comparisons implementation
13// ***************************************************************************
14
15#ifndef  BOOST_TEST_BASIC_CSTRING_COMPARE_HPP_071894GER
16#define  BOOST_TEST_BASIC_CSTRING_COMPARE_HPP_071894GER
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) && !BOOST_WORKAROUND(__GNUC__, < 3)
30namespace std { using ::toupper; }
31# endif
32
33namespace boost {
34
35namespace unit_test {
36
37// ************************************************************************** //
38// **************                case_ins_compare              ************** //
39// ************************************************************************** //
40
41namespace ut_detail {
42
43template<class CharT>
44struct 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
65template<class CharT>
66inline bool
67case_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
78template<class CharT>
79class case_ins_less : public std::binary_function<basic_cstring<CharT>,basic_cstring<CharT>,bool>
80{
81public:
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// **************                  operator <                  ************** //
94// ************************************************************************** //
95
96template<class CharT>
97inline bool
98operator <( 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} // namespace unit_test
108
109} // namespace boost
110
111//____________________________________________________________________________//
112
113#include <boost/test/detail/enable_warnings.hpp>
114
115// ***************************************************************************
116//  Revision History :
117// 
118//  $Log: compare.hpp,v $
119//  Revision 1.5  2005/02/20 08:27:09  rogeeff
120//  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
121//
122//  Revision 1.4  2005/02/01 06:40:08  rogeeff
123//  copyright update
124//  old log entries removed
125//  minor stilistic changes
126//  depricated tools removed
127//
128//  Revision 1.3  2005/01/31 20:07:21  rogeeff
129//  Sunpro CC 5.3 workarounds
130//
131//  Revision 1.2  2005/01/22 19:22:13  rogeeff
132//  implementation moved into headers section to eliminate dependency of included/minimal component on src directory
133//
134//  Revision 1.1  2005/01/22 18:21:40  rogeeff
135//  moved sharable staff into utils
136//
137// ***************************************************************************
138
139#endif // BOOST_TEST_BASIC_CSTRING_COMPARE_HPP_071894GER
Note: See TracBrowser for help on using the repository browser.