Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:55:53

0001 //  Boost string_algo library compare.hpp header file  -------------------------//
0002 
0003 //  Copyright Pavol Droba 2002-2006.
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org/ for updates, documentation, and revision history.
0010 
0011 #ifndef BOOST_STRING_COMPARE_HPP
0012 #define BOOST_STRING_COMPARE_HPP
0013 
0014 #include <boost/algorithm/string/config.hpp>
0015 #include <locale>
0016 
0017 /*! \file
0018     Defines element comparison predicates. Many algorithms in this library can
0019     take an additional argument with a predicate used to compare elements.
0020     This makes it possible, for instance, to have case insensitive versions
0021     of the algorithms.
0022 */
0023 
0024 namespace boost {
0025     namespace algorithm {
0026 
0027         //  is_equal functor  -----------------------------------------------//
0028 
0029         //! is_equal functor
0030         /*!
0031             Standard STL equal_to only handle comparison between arguments
0032             of the same type. This is a less restrictive version which wraps operator ==.
0033         */
0034         struct is_equal
0035         {
0036             //! Function operator
0037             /*!
0038                 Compare two operands for equality
0039             */
0040             template< typename T1, typename T2 >
0041                 bool operator()( const T1& Arg1, const T2& Arg2 ) const
0042             {
0043                 return Arg1==Arg2;
0044             }
0045         };
0046 
0047         //! case insensitive version of is_equal
0048         /*!
0049             Case insensitive comparison predicate. Comparison is done using
0050             specified locales.
0051         */
0052         struct is_iequal
0053         {
0054             //! Constructor
0055             /*!
0056                 \param Loc locales used for comparison
0057             */
0058             is_iequal( const std::locale& Loc=std::locale() ) :
0059                 m_Loc( Loc ) {}
0060 
0061             //! Function operator
0062             /*!
0063                 Compare two operands. Case is ignored.
0064             */
0065             template< typename T1, typename T2 >
0066                 bool operator()( const T1& Arg1, const T2& Arg2 ) const
0067             {
0068                 #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
0069                     return std::toupper(Arg1)==std::toupper(Arg2);
0070                 #else
0071                     return std::toupper<T1>(Arg1,m_Loc)==std::toupper<T2>(Arg2,m_Loc);
0072                 #endif
0073             }
0074 
0075         private:
0076             std::locale m_Loc;
0077         };
0078 
0079         //  is_less functor  -----------------------------------------------//
0080 
0081         //! is_less functor
0082         /*!
0083             Convenient version of standard std::less. Operation is templated, therefore it is 
0084             not required to specify the exact types upon the construction
0085          */
0086         struct is_less
0087         {
0088             //! Functor operation
0089             /*!
0090                 Compare two operands using > operator
0091              */
0092             template< typename T1, typename T2 >
0093                 bool operator()( const T1& Arg1, const T2& Arg2 ) const
0094             {
0095                 return Arg1<Arg2;
0096             }
0097         };
0098 
0099 
0100         //! case insensitive version of is_less
0101         /*!
0102             Case insensitive comparison predicate. Comparison is done using
0103             specified locales.
0104         */
0105         struct is_iless
0106         {
0107             //! Constructor
0108             /*!
0109                 \param Loc locales used for comparison
0110             */
0111             is_iless( const std::locale& Loc=std::locale() ) :
0112                 m_Loc( Loc ) {}
0113 
0114             //! Function operator
0115             /*!
0116                 Compare two operands. Case is ignored.
0117             */
0118             template< typename T1, typename T2 >
0119                 bool operator()( const T1& Arg1, const T2& Arg2 ) const
0120             {
0121                 #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
0122                     return std::toupper(Arg1)<std::toupper(Arg2);
0123                 #else
0124                     return std::toupper<T1>(Arg1,m_Loc)<std::toupper<T2>(Arg2,m_Loc);
0125                 #endif
0126             }
0127 
0128         private:
0129             std::locale m_Loc;
0130         };
0131 
0132         //  is_not_greater functor  -----------------------------------------------//
0133 
0134         //! is_not_greater functor
0135         /*!
0136             Convenient version of standard std::not_greater_to. Operation is templated, therefore it is 
0137             not required to specify the exact types upon the construction
0138          */
0139         struct is_not_greater
0140         {
0141             //! Functor operation
0142             /*!
0143                 Compare two operands using > operator
0144              */
0145             template< typename T1, typename T2 >
0146                 bool operator()( const T1& Arg1, const T2& Arg2 ) const
0147             {
0148                 return Arg1<=Arg2;
0149             }
0150         };
0151 
0152 
0153         //! case insensitive version of is_not_greater
0154         /*!
0155             Case insensitive comparison predicate. Comparison is done using
0156             specified locales.
0157         */
0158         struct is_not_igreater
0159         {
0160             //! Constructor
0161             /*!
0162                 \param Loc locales used for comparison
0163             */
0164             is_not_igreater( const std::locale& Loc=std::locale() ) :
0165                 m_Loc( Loc ) {}
0166 
0167             //! Function operator
0168             /*!
0169                 Compare two operands. Case is ignored.
0170             */
0171             template< typename T1, typename T2 >
0172                 bool operator()( const T1& Arg1, const T2& Arg2 ) const
0173             {
0174                 #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
0175                     return std::toupper(Arg1)<=std::toupper(Arg2);
0176                 #else
0177                     return std::toupper<T1>(Arg1,m_Loc)<=std::toupper<T2>(Arg2,m_Loc);
0178                 #endif
0179             }
0180 
0181         private:
0182             std::locale m_Loc;
0183         };
0184 
0185 
0186     } // namespace algorithm
0187 
0188     // pull names to the boost namespace
0189     using algorithm::is_equal;
0190     using algorithm::is_iequal;
0191     using algorithm::is_less;
0192     using algorithm::is_iless;
0193     using algorithm::is_not_greater;
0194     using algorithm::is_not_igreater;
0195 
0196 } // namespace boost
0197 
0198 
0199 #endif  // BOOST_STRING_COMPARE_HPP