1 | // Boost string_algo library compare.hpp header file -------------------------//
|
---|
2 |
|
---|
3 | // Copyright Pavol Droba 2002-2003. Use, modification and
|
---|
4 | // distribution is subject to the Boost Software License, Version
|
---|
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
6 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
7 |
|
---|
8 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
9 |
|
---|
10 | #ifndef BOOST_STRING_COMPARE_HPP
|
---|
11 | #define BOOST_STRING_COMPARE_HPP
|
---|
12 |
|
---|
13 | #include <boost/algorithm/string/config.hpp>
|
---|
14 | #include <locale>
|
---|
15 |
|
---|
16 | /*! \file
|
---|
17 | Defines element comparison predicates. Many algorithms in this library can
|
---|
18 | take an additional argument with a predicate used to compare elements.
|
---|
19 | This makes it possible, for instance, to have case insensitive versions
|
---|
20 | of the algorithms.
|
---|
21 | */
|
---|
22 |
|
---|
23 | namespace boost {
|
---|
24 | namespace algorithm {
|
---|
25 |
|
---|
26 | // is_equal functor -----------------------------------------------//
|
---|
27 |
|
---|
28 | //! is_equal functor
|
---|
29 | /*!
|
---|
30 | Standard STL equal_to only handle comparison between arguments
|
---|
31 | of the same type. This is a less restrictive version which wraps operator ==.
|
---|
32 | */
|
---|
33 | struct is_equal
|
---|
34 | {
|
---|
35 | //! Function operator
|
---|
36 | /*!
|
---|
37 | Compare two operands for equality
|
---|
38 | */
|
---|
39 | template< typename T1, typename T2 >
|
---|
40 | bool operator ()( const T1& Arg1, const T2& Arg2 ) const
|
---|
41 | {
|
---|
42 | return Arg1==Arg2;
|
---|
43 | }
|
---|
44 | };
|
---|
45 |
|
---|
46 | //! case insensitive version of is_equal
|
---|
47 | /*!
|
---|
48 | Case insensitive comparison predicate. Comparison is done using
|
---|
49 | specified locales.
|
---|
50 | */
|
---|
51 | struct is_iequal
|
---|
52 | {
|
---|
53 | //! Constructor
|
---|
54 | /*!
|
---|
55 | \param Loc locales used for comparison
|
---|
56 | */
|
---|
57 | is_iequal( const std::locale& Loc=std::locale() ) :
|
---|
58 | m_Loc( Loc ) {}
|
---|
59 |
|
---|
60 | //! Function operator
|
---|
61 | /*!
|
---|
62 | Compare two operands. Case is ignored.
|
---|
63 | */
|
---|
64 | template< typename T1, typename T2 >
|
---|
65 | bool operator ()( const T1& Arg1, const T2& Arg2 ) const
|
---|
66 | {
|
---|
67 | #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
---|
68 | return std::toupper(Arg1)==std::toupper(Arg2);
|
---|
69 | #else
|
---|
70 | return std::toupper(Arg1,m_Loc)==std::toupper(Arg2,m_Loc);
|
---|
71 | #endif
|
---|
72 | }
|
---|
73 |
|
---|
74 | private:
|
---|
75 | std::locale m_Loc;
|
---|
76 | };
|
---|
77 |
|
---|
78 | } // namespace algorithm
|
---|
79 |
|
---|
80 | // pull names to the boost namespace
|
---|
81 | using algorithm::is_equal;
|
---|
82 | using algorithm::is_iequal;
|
---|
83 |
|
---|
84 | } // namespace boost
|
---|
85 |
|
---|
86 |
|
---|
87 | #endif // BOOST_STRING_COMPARE_HPP
|
---|