Skip to content

Commit ff82e51

Browse files
author
Pavol Droba
committed
- added more character-comparison predicates (is_less, is_not_greater)
- added range version of lexicographical_compare - Fixed some copyright years [SVN r32478]
1 parent f50dd24 commit ff82e51

6 files changed

Lines changed: 202 additions & 8 deletions

File tree

include/boost/algorithm/string/compare.hpp

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Boost string_algo library compare.hpp header file -------------------------//
22

3-
// Copyright Pavol Droba 2002-2003. Use, modification and
3+
// Copyright Pavol Droba 2002-2006. Use, modification and
44
// distribution is subject to the Boost Software License, Version
55
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
66
// http://www.boost.org/LICENSE_1_0.txt)
@@ -37,7 +37,7 @@ namespace boost {
3737
Compare two operands for equality
3838
*/
3939
template< typename T1, typename T2 >
40-
bool operator ()( const T1& Arg1, const T2& Arg2 ) const
40+
bool operator()( const T1& Arg1, const T2& Arg2 ) const
4141
{
4242
return Arg1==Arg2;
4343
}
@@ -62,7 +62,7 @@ namespace boost {
6262
Compare two operands. Case is ignored.
6363
*/
6464
template< typename T1, typename T2 >
65-
bool operator ()( const T1& Arg1, const T2& Arg2 ) const
65+
bool operator()( const T1& Arg1, const T2& Arg2 ) const
6666
{
6767
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
6868
return std::toupper(Arg1)==std::toupper(Arg2);
@@ -75,11 +75,122 @@ namespace boost {
7575
std::locale m_Loc;
7676
};
7777

78+
// is_less functor -----------------------------------------------//
79+
80+
//! is_less functor
81+
/*!
82+
Convenient version of standard std::less. Operation is templated, therefore it is
83+
not required to specify the exact types upon the construction
84+
*/
85+
struct is_less
86+
{
87+
//! Functor operation
88+
/*!
89+
Compare two operands using > operator
90+
*/
91+
template< typename T1, typename T2 >
92+
bool operator()( const T1& Arg1, const T2& Arg2 ) const
93+
{
94+
return Arg1<Arg2;
95+
}
96+
};
97+
98+
99+
//! case insensitive version of is_less
100+
/*!
101+
Case insensitive comparison predicate. Comparison is done using
102+
specified locales.
103+
*/
104+
struct is_iless
105+
{
106+
//! Constructor
107+
/*!
108+
\param Loc locales used for comparison
109+
*/
110+
is_iless( const std::locale& Loc=std::locale() ) :
111+
m_Loc( Loc ) {}
112+
113+
//! Function operator
114+
/*!
115+
Compare two operands. Case is ignored.
116+
*/
117+
template< typename T1, typename T2 >
118+
bool operator()( const T1& Arg1, const T2& Arg2 ) const
119+
{
120+
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
121+
return std::toupper(Arg1)<std::toupper(Arg2);
122+
#else
123+
return std::toupper(Arg1,m_Loc)<std::toupper(Arg2,m_Loc);
124+
#endif
125+
}
126+
127+
private:
128+
std::locale m_Loc;
129+
};
130+
131+
// is_not_greater functor -----------------------------------------------//
132+
133+
//! is_not_greater functor
134+
/*!
135+
Convenient version of standard std::not_greater_to. Operation is templated, therefore it is
136+
not required to specify the exact types upon the construction
137+
*/
138+
struct is_not_greater
139+
{
140+
//! Functor operation
141+
/*!
142+
Compare two operands using > operator
143+
*/
144+
template< typename T1, typename T2 >
145+
bool operator()( const T1& Arg1, const T2& Arg2 ) const
146+
{
147+
return Arg1>=Arg2;
148+
}
149+
};
150+
151+
152+
//! case insensitive version of is_not_greater
153+
/*!
154+
Case insensitive comparison predicate. Comparison is done using
155+
specified locales.
156+
*/
157+
struct is_not_igreater
158+
{
159+
//! Constructor
160+
/*!
161+
\param Loc locales used for comparison
162+
*/
163+
is_not_igreater( const std::locale& Loc=std::locale() ) :
164+
m_Loc( Loc ) {}
165+
166+
//! Function operator
167+
/*!
168+
Compare two operands. Case is ignored.
169+
*/
170+
template< typename T1, typename T2 >
171+
bool operator()( const T1& Arg1, const T2& Arg2 ) const
172+
{
173+
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
174+
return std::toupper(Arg1)>=std::toupper(Arg2);
175+
#else
176+
return std::toupper(Arg1,m_Loc)>=std::toupper(Arg2,m_Loc);
177+
#endif
178+
}
179+
180+
private:
181+
std::locale m_Loc;
182+
};
183+
184+
78185
} // namespace algorithm
79186

80187
// pull names to the boost namespace
81188
using algorithm::is_equal;
82189
using algorithm::is_iequal;
190+
using algorithm::is_less;
191+
using algorithm::is_iless;
192+
using algorithm::is_not_greater;
193+
using algorithm::is_not_igreater;
83194

84195
} // namespace boost
85196

include/boost/algorithm/string/detail/finder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Boost string_algo library finder.hpp header file ---------------------------//
22

3-
// Copyright Pavol Droba 2002-2003. Use, modification and
3+
// Copyright Pavol Droba 2002-2006. Use, modification and
44
// distribution is subject to the Boost Software License, Version
55
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
66
// http://www.boost.org/LICENSE_1_0.txt)

include/boost/algorithm/string/erase.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Boost string_algo library erase.hpp header file ---------------------------//
22

3-
// Copyright Pavol Droba 2002-2003. Use, modification and
3+
// Copyright Pavol Droba 2002-2006. Use, modification and
44
// distribution is subject to the Boost Software License, Version
55
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
66
// http://www.boost.org/LICENSE_1_0.txt)

include/boost/algorithm/string/finder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Boost string_algo library finder.hpp header file ---------------------------//
22

3-
// Copyright Pavol Droba 2002-2003. Use, modification and
3+
// Copyright Pavol Droba 2002-2006. Use, modification and
44
// distribution is subject to the Boost Software License, Version
55
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
66
// http://www.boost.org/LICENSE_1_0.txt)

include/boost/algorithm/string/predicate.hpp

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace boost {
307307
return equals(Input, Test, is_equal());
308308
}
309309

310-
//! 'Equals' predicate ( casa insensitive )
310+
//! 'Equals' predicate ( case insensitive )
311311
/*!
312312
This predicate holds when the test container is equal to the
313313
input container i.e. all elements in both containers are same.
@@ -331,6 +331,87 @@ namespace boost {
331331
return equals(Input, Test, is_iequal(Loc));
332332
}
333333

334+
// lexicographical_compare predicate -----------------------------//
335+
336+
//! Lexicographical compare predicate
337+
/*!
338+
This predicate is an overload of std::lexicographical_compare
339+
for range arguments
340+
341+
It check whether the first argument is lexicographically less
342+
then the second one.
343+
344+
If the optional predicate is specified, it is used for character-wise
345+
comparison
346+
347+
\param Arg1 First argument
348+
\param Arg2 Second argument
349+
\param Pred Comparison predicate
350+
\return The result of the test
351+
352+
\note This function provides the strong exception-safety guarantee
353+
*/
354+
template<typename Range1T, typename Range2T, typename PredicateT>
355+
inline bool lexicographical_compare(
356+
const Range1T& Arg1,
357+
const Range2T& Arg2,
358+
PredicateT Pred)
359+
{
360+
return std::lexicographical_compare(
361+
begin(Arg1),
362+
end(Arg1),
363+
begin(Arg2),
364+
end(Arg2),
365+
Pred);
366+
}
367+
368+
//! Lexicographical compare predicate
369+
/*!
370+
\overload
371+
*/
372+
template<typename Range1T, typename Range2T>
373+
inline bool lexicographical_compare(
374+
const Range1T& Arg1,
375+
const Range2T& Arg2)
376+
{
377+
return std::lexicographical_compare(
378+
begin(Arg1),
379+
end(Arg1),
380+
begin(Arg2),
381+
end(Arg2),
382+
is_less());
383+
}
384+
385+
//! Lexicographical compare predicate (case-insensitive)
386+
/*!
387+
This predicate is an overload of std::lexicographical_compare
388+
for range arguments.
389+
It check whether the first argument is lexicographically less
390+
then the second one.
391+
Elements are compared case insensitively
392+
393+
394+
\param Arg1 First argument
395+
\param Arg2 Second argument
396+
\param Pred Comparison predicate
397+
\return The result of the test
398+
399+
\note This function provides the strong exception-safety guarantee
400+
*/
401+
template<typename Range1T, typename Range2T>
402+
inline bool ilexicographical_compare(
403+
const Range1T& Arg1,
404+
const Range2T& Arg2)
405+
{
406+
return std::lexicographical_compare(
407+
begin(Arg1),
408+
end(Arg1),
409+
begin(Arg2),
410+
end(Arg2),
411+
is_iless());
412+
}
413+
414+
334415
// all predicate -----------------------------------------------//
335416

336417
//! 'All' predicate
@@ -374,6 +455,8 @@ namespace boost {
374455
using algorithm::equals;
375456
using algorithm::iequals;
376457
using algorithm::all;
458+
using algorithm::lexicographical_compare;
459+
using algorithm::ilexicographical_compare;
377460

378461
} // namespace boost
379462

include/boost/algorithm/string/replace.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Boost string_algo library replace.hpp header file ---------------------------//
22

3-
// Copyright Pavol Droba 2002-2003. Use, modification and
3+
// Copyright Pavol Droba 2002-2006. Use, modification and
44
// distribution is subject to the Boost Software License, Version
55
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
66
// http://www.boost.org/LICENSE_1_0.txt)

0 commit comments

Comments
 (0)