diff --git a/include/boost/algorithm/string/compare.hpp b/include/boost/algorithm/string/compare.hpp index 6961792..6e6e07d 100644 --- a/include/boost/algorithm/string/compare.hpp +++ b/include/boost/algorithm/string/compare.hpp @@ -1,6 +1,6 @@ // Boost string_algo library compare.hpp header file -------------------------// -// Copyright Pavol Droba 2002-2003. Use, modification and +// Copyright Pavol Droba 2002-2006. Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -37,7 +37,7 @@ namespace boost { Compare two operands for equality */ template< typename T1, typename T2 > - bool operator ()( const T1& Arg1, const T2& Arg2 ) const + bool operator()( const T1& Arg1, const T2& Arg2 ) const { return Arg1==Arg2; } @@ -62,7 +62,7 @@ namespace boost { Compare two operands. Case is ignored. */ template< typename T1, typename T2 > - bool operator ()( const T1& Arg1, const T2& Arg2 ) const + bool operator()( const T1& Arg1, const T2& Arg2 ) const { #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) return std::toupper(Arg1)==std::toupper(Arg2); @@ -75,11 +75,122 @@ namespace boost { std::locale m_Loc; }; + // is_less functor -----------------------------------------------// + + //! is_less functor + /*! + Convenient version of standard std::less. Operation is templated, therefore it is + not required to specify the exact types upon the construction + */ + struct is_less + { + //! Functor operation + /*! + Compare two operands using > operator + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + return Arg1 + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) + return std::toupper(Arg1) operator + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + return Arg1>=Arg2; + } + }; + + + //! case insensitive version of is_not_greater + /*! + Case insensitive comparison predicate. Comparison is done using + specified locales. + */ + struct is_not_igreater + { + //! Constructor + /*! + \param Loc locales used for comparison + */ + is_not_igreater( const std::locale& Loc=std::locale() ) : + m_Loc( Loc ) {} + + //! Function operator + /*! + Compare two operands. Case is ignored. + */ + template< typename T1, typename T2 > + bool operator()( const T1& Arg1, const T2& Arg2 ) const + { + #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) + return std::toupper(Arg1)>=std::toupper(Arg2); + #else + return std::toupper(Arg1,m_Loc)>=std::toupper(Arg2,m_Loc); + #endif + } + + private: + std::locale m_Loc; + }; + + } // namespace algorithm // pull names to the boost namespace using algorithm::is_equal; using algorithm::is_iequal; + using algorithm::is_less; + using algorithm::is_iless; + using algorithm::is_not_greater; + using algorithm::is_not_igreater; } // namespace boost diff --git a/include/boost/algorithm/string/detail/finder.hpp b/include/boost/algorithm/string/detail/finder.hpp index 4dc2fe7..8d107f1 100644 --- a/include/boost/algorithm/string/detail/finder.hpp +++ b/include/boost/algorithm/string/detail/finder.hpp @@ -1,6 +1,6 @@ // Boost string_algo library finder.hpp header file ---------------------------// -// Copyright Pavol Droba 2002-2003. Use, modification and +// Copyright Pavol Droba 2002-2006. Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) diff --git a/include/boost/algorithm/string/erase.hpp b/include/boost/algorithm/string/erase.hpp index 0915e72..c005b69 100644 --- a/include/boost/algorithm/string/erase.hpp +++ b/include/boost/algorithm/string/erase.hpp @@ -1,6 +1,6 @@ // Boost string_algo library erase.hpp header file ---------------------------// -// Copyright Pavol Droba 2002-2003. Use, modification and +// Copyright Pavol Droba 2002-2006. Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) diff --git a/include/boost/algorithm/string/finder.hpp b/include/boost/algorithm/string/finder.hpp index 8ed21a7..6a64369 100644 --- a/include/boost/algorithm/string/finder.hpp +++ b/include/boost/algorithm/string/finder.hpp @@ -1,6 +1,6 @@ // Boost string_algo library finder.hpp header file ---------------------------// -// Copyright Pavol Droba 2002-2003. Use, modification and +// Copyright Pavol Droba 2002-2006. Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) diff --git a/include/boost/algorithm/string/predicate.hpp b/include/boost/algorithm/string/predicate.hpp index 98dae62..2f3b3f8 100644 --- a/include/boost/algorithm/string/predicate.hpp +++ b/include/boost/algorithm/string/predicate.hpp @@ -307,7 +307,7 @@ namespace boost { return equals(Input, Test, is_equal()); } - //! 'Equals' predicate ( casa insensitive ) + //! 'Equals' predicate ( case insensitive ) /*! This predicate holds when the test container is equal to the input container i.e. all elements in both containers are same. @@ -331,6 +331,87 @@ namespace boost { return equals(Input, Test, is_iequal(Loc)); } +// lexicographical_compare predicate -----------------------------// + + //! Lexicographical compare predicate + /*! + This predicate is an overload of std::lexicographical_compare + for range arguments + + It check whether the first argument is lexicographically less + then the second one. + + If the optional predicate is specified, it is used for character-wise + comparison + + \param Arg1 First argument + \param Arg2 Second argument + \param Pred Comparison predicate + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template + inline bool lexicographical_compare( + const Range1T& Arg1, + const Range2T& Arg2, + PredicateT Pred) + { + return std::lexicographical_compare( + begin(Arg1), + end(Arg1), + begin(Arg2), + end(Arg2), + Pred); + } + + //! Lexicographical compare predicate + /*! + \overload + */ + template + inline bool lexicographical_compare( + const Range1T& Arg1, + const Range2T& Arg2) + { + return std::lexicographical_compare( + begin(Arg1), + end(Arg1), + begin(Arg2), + end(Arg2), + is_less()); + } + + //! Lexicographical compare predicate (case-insensitive) + /*! + This predicate is an overload of std::lexicographical_compare + for range arguments. + It check whether the first argument is lexicographically less + then the second one. + Elements are compared case insensitively + + + \param Arg1 First argument + \param Arg2 Second argument + \param Pred Comparison predicate + \return The result of the test + + \note This function provides the strong exception-safety guarantee + */ + template + inline bool ilexicographical_compare( + const Range1T& Arg1, + const Range2T& Arg2) + { + return std::lexicographical_compare( + begin(Arg1), + end(Arg1), + begin(Arg2), + end(Arg2), + is_iless()); + } + + // all predicate -----------------------------------------------// //! 'All' predicate @@ -374,6 +455,8 @@ namespace boost { using algorithm::equals; using algorithm::iequals; using algorithm::all; + using algorithm::lexicographical_compare; + using algorithm::ilexicographical_compare; } // namespace boost diff --git a/include/boost/algorithm/string/replace.hpp b/include/boost/algorithm/string/replace.hpp index 3a5df1f..1017d0e 100644 --- a/include/boost/algorithm/string/replace.hpp +++ b/include/boost/algorithm/string/replace.hpp @@ -1,6 +1,6 @@ // Boost string_algo library replace.hpp header file ---------------------------// -// Copyright Pavol Droba 2002-2003. Use, modification and +// Copyright Pavol Droba 2002-2006. Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt)