mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-25 12:01:39 +02:00
Compare commits
32 Commits
boost-1.33
...
boost-1.34
Author | SHA1 | Date | |
---|---|---|---|
664a47265b | |||
1a02969303 | |||
6309379618 | |||
37581bac55 | |||
a71a4ed5b1 | |||
c509c3fbad | |||
d8683f2498 | |||
7c0101aa51 | |||
6f3e85528f | |||
8af639b7cf | |||
d9bc7e800b | |||
b4ed9beb90 | |||
bd974bb945 | |||
24b55c67f7 | |||
603223fd3d | |||
131484606f | |||
20d22a8fc8 | |||
134a106ae9 | |||
0bcbe2afc6 | |||
b7a3fa2c73 | |||
a731e950f2 | |||
66794c89f6 | |||
9b62648970 | |||
3766cbbe5c | |||
e2b9172f5d | |||
fa01964a1f | |||
ff82e5135c | |||
f50dd248cc | |||
dd11014682 | |||
d9ebe5da13 | |||
e2d5feeb06 | |||
45949a9316 |
@ -20,6 +20,7 @@
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/find.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/erase.hpp>
|
||||
#include <boost/algorithm/string/classification.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,12 +62,12 @@ 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);
|
||||
#else
|
||||
return std::toupper(Arg1,m_Loc)==std::toupper(Arg2,m_Loc);
|
||||
return std::toupper<T1>(Arg1,m_Loc)==std::toupper<T2>(Arg2,m_Loc);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -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<Arg2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! case insensitive version of is_less
|
||||
/*!
|
||||
Case insensitive comparison predicate. Comparison is done using
|
||||
specified locales.
|
||||
*/
|
||||
struct is_iless
|
||||
{
|
||||
//! Constructor
|
||||
/*!
|
||||
\param Loc locales used for comparison
|
||||
*/
|
||||
is_iless( 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<T1>(Arg1,m_Loc)<std::toupper<T2>(Arg2,m_Loc);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
std::locale m_Loc;
|
||||
};
|
||||
|
||||
// is_not_greater functor -----------------------------------------------//
|
||||
|
||||
//! is_not_greater functor
|
||||
/*!
|
||||
Convenient version of standard std::not_greater_to. Operation is templated, therefore it is
|
||||
not required to specify the exact types upon the construction
|
||||
*/
|
||||
struct is_not_greater
|
||||
{
|
||||
//! Functor operation
|
||||
/*!
|
||||
Compare two operands using > 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<T1>(Arg1,m_Loc)<=std::toupper<T2>(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
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace boost {
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::tolower( Ch);
|
||||
#else
|
||||
return std::tolower( Ch, m_Loc );
|
||||
return std::tolower<CharT>( Ch, m_Loc );
|
||||
#endif
|
||||
}
|
||||
private:
|
||||
@ -53,7 +53,7 @@ namespace boost {
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::toupper( Ch);
|
||||
#else
|
||||
return std::toupper( Ch, m_Loc );
|
||||
return std::toupper<CharT>( Ch, m_Loc );
|
||||
#endif
|
||||
}
|
||||
private:
|
||||
|
@ -46,7 +46,7 @@ namespace boost {
|
||||
return std::use_facet< std::ctype<CharT> >(m_Locale).is( m_Type, Ch );
|
||||
}
|
||||
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x582) && !defined(_USE_OLD_RW_STL)
|
||||
template<>
|
||||
bool operator()( char const Ch ) const
|
||||
{
|
||||
|
@ -26,20 +26,17 @@ namespace boost {
|
||||
template<
|
||||
typename OutputIteratorT,
|
||||
typename InputT,
|
||||
typename FinderT,
|
||||
typename FormatterT,
|
||||
typename FindResultT >
|
||||
inline OutputIteratorT find_format_copy_impl(
|
||||
OutputIteratorT Output,
|
||||
const InputT& Input,
|
||||
FinderT Finder,
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult )
|
||||
{
|
||||
return find_format_copy_impl2(
|
||||
Output,
|
||||
Input,
|
||||
Finder,
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
@ -48,14 +45,12 @@ namespace boost {
|
||||
template<
|
||||
typename OutputIteratorT,
|
||||
typename InputT,
|
||||
typename FinderT,
|
||||
typename FormatterT,
|
||||
typename FindResultT,
|
||||
typename FormatResultT >
|
||||
inline OutputIteratorT find_format_copy_impl2(
|
||||
OutputIteratorT Output,
|
||||
const InputT& Input,
|
||||
FinderT Finder,
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult,
|
||||
const FormatResultT& FormatResult )
|
||||
@ -91,18 +86,15 @@ namespace boost {
|
||||
|
||||
template<
|
||||
typename InputT,
|
||||
typename FinderT,
|
||||
typename FormatterT,
|
||||
typename FindResultT >
|
||||
inline InputT find_format_copy_impl(
|
||||
const InputT& Input,
|
||||
FinderT Finder,
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult)
|
||||
{
|
||||
return find_format_copy_impl2(
|
||||
Input,
|
||||
Finder,
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
@ -110,13 +102,11 @@ namespace boost {
|
||||
|
||||
template<
|
||||
typename InputT,
|
||||
typename FinderT,
|
||||
typename FormatterT,
|
||||
typename FindResultT,
|
||||
typename FormatResultT >
|
||||
inline InputT find_format_copy_impl2(
|
||||
const InputT& Input,
|
||||
FinderT Finder,
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult,
|
||||
const FormatResultT& FormatResult)
|
||||
@ -151,18 +141,15 @@ namespace boost {
|
||||
|
||||
template<
|
||||
typename InputT,
|
||||
typename FinderT,
|
||||
typename FormatterT,
|
||||
typename FindResultT >
|
||||
inline void find_format_impl(
|
||||
InputT& Input,
|
||||
FinderT Finder,
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult)
|
||||
{
|
||||
find_format_impl2(
|
||||
Input,
|
||||
Finder,
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
@ -170,13 +157,11 @@ namespace boost {
|
||||
|
||||
template<
|
||||
typename InputT,
|
||||
typename FinderT,
|
||||
typename FormatterT,
|
||||
typename FindResultT,
|
||||
typename FormatResultT >
|
||||
inline void find_format_impl2(
|
||||
InputT& Input,
|
||||
FinderT,
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult,
|
||||
const FormatResultT& FormatResult)
|
||||
|
@ -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)
|
||||
@ -90,7 +90,7 @@ namespace boost {
|
||||
|
||||
// find last functor -----------------------------------------------//
|
||||
|
||||
// find the last match a subsequnce in the sequence ( functor )
|
||||
// find the last match a subseqeunce in the sequence ( functor )
|
||||
/*
|
||||
Returns a pair <begin,end> marking the subsequence in the sequence.
|
||||
If the find fails, returns <End,End>
|
||||
@ -200,7 +200,7 @@ namespace boost {
|
||||
|
||||
// find n-th functor -----------------------------------------------//
|
||||
|
||||
// find the n-th match of a subsequnce in the sequence ( functor )
|
||||
// find the n-th match of a subsequence in the sequence ( functor )
|
||||
/*
|
||||
Returns a pair <begin,end> marking the subsequence in the sequence.
|
||||
If the find fails, returns <End,End>
|
||||
@ -212,12 +212,15 @@ namespace boost {
|
||||
typedef first_finderF<
|
||||
search_iterator_type,
|
||||
PredicateT> first_finder_type;
|
||||
typedef last_finderF<
|
||||
search_iterator_type,
|
||||
PredicateT> last_finder_type;
|
||||
|
||||
// Construction
|
||||
template< typename SearchT >
|
||||
nth_finderF(
|
||||
const SearchT& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
PredicateT Comp) :
|
||||
m_Search(begin(Search), end(Search)),
|
||||
m_Nth(Nth),
|
||||
@ -225,7 +228,7 @@ namespace boost {
|
||||
nth_finderF(
|
||||
search_iterator_type SearchBegin,
|
||||
search_iterator_type SearchEnd,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
PredicateT Comp) :
|
||||
m_Search(SearchBegin, SearchEnd),
|
||||
m_Nth(Nth),
|
||||
@ -237,6 +240,26 @@ namespace boost {
|
||||
operator()(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
if(m_Nth>=0)
|
||||
{
|
||||
return find_forward(Begin, End, m_Nth);
|
||||
}
|
||||
else
|
||||
{
|
||||
return find_backward(Begin, End, -m_Nth);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
// Implementation helpers
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_forward(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
@ -245,13 +268,13 @@ namespace boost {
|
||||
if( boost::empty(m_Search) )
|
||||
return result_type( End, End );
|
||||
|
||||
// Instantiate find funtor
|
||||
// Instantiate find functor
|
||||
first_finder_type first_finder(
|
||||
m_Search.begin(), m_Search.end(), m_Comp );
|
||||
|
||||
result_type M( Begin, Begin );
|
||||
|
||||
for( unsigned int n=0; n<=m_Nth; ++n )
|
||||
for( unsigned int n=0; n<=N; ++n )
|
||||
{
|
||||
// find next match
|
||||
M=first_finder( end(M), End );
|
||||
@ -266,14 +289,179 @@ namespace boost {
|
||||
return M;
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_backward(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
// Sanity check
|
||||
if( boost::empty(m_Search) )
|
||||
return result_type( End, End );
|
||||
|
||||
// Instantiate find functor
|
||||
last_finder_type last_finder(
|
||||
m_Search.begin(), m_Search.end(), m_Comp );
|
||||
|
||||
result_type M( End, End );
|
||||
|
||||
for( unsigned int n=1; n<=N; ++n )
|
||||
{
|
||||
// find next match
|
||||
M=last_finder( Begin, begin(M) );
|
||||
|
||||
if ( !M )
|
||||
{
|
||||
// Subsequence not found, return
|
||||
return M;
|
||||
}
|
||||
}
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
iterator_range<search_iterator_type> m_Search;
|
||||
unsigned int m_Nth;
|
||||
int m_Nth;
|
||||
PredicateT m_Comp;
|
||||
};
|
||||
|
||||
// find head/tail implementation helpers ---------------------------//
|
||||
|
||||
template<typename ForwardIteratorT>
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_head_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::forward_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=Begin;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<N && It!=End; ++Index,++It ) {};
|
||||
|
||||
return result_type( Begin, It );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_head_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::random_access_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) )
|
||||
return result_type( Begin, End );
|
||||
|
||||
return result_type(Begin,Begin+N);
|
||||
}
|
||||
|
||||
// Find head implementation
|
||||
template<typename ForwardIteratorT>
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_head_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N )
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return find_head_impl( Begin, End, N, category() );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::forward_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
unsigned int Index=0;
|
||||
input_iterator_type It=Begin;
|
||||
input_iterator_type It2=Begin;
|
||||
|
||||
// Advance It2 by N increments
|
||||
for( Index=0; Index<N && It2!=End; ++Index,++It2 ) {};
|
||||
|
||||
// Advance It, It2 to the end
|
||||
for(; It2!=End; ++It,++It2 ) {};
|
||||
|
||||
return result_type( It, It2 );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::bidirectional_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=End;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<N && It!=Begin; ++Index,--It ) {};
|
||||
|
||||
return result_type( It, End );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N,
|
||||
std::random_access_iterator_tag )
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) )
|
||||
return result_type( Begin, End );
|
||||
|
||||
return result_type( End-N, End );
|
||||
}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
find_tail_impl(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
unsigned int N )
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return find_tail_impl( Begin, End, N, category() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// find head functor -----------------------------------------------//
|
||||
|
||||
|
||||
// find a head in the sequence ( functor )
|
||||
/*
|
||||
This functor find a head of the specified range. For
|
||||
@ -283,7 +471,7 @@ namespace boost {
|
||||
struct head_finderF
|
||||
{
|
||||
// Construction
|
||||
head_finderF( unsigned int N ) : m_N(N) {}
|
||||
head_finderF( int N ) : m_N(N) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
@ -292,54 +480,26 @@ namespace boost {
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
if(m_N>=0)
|
||||
{
|
||||
return find_head_impl( Begin, End, m_N );
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator_range<ForwardIteratorT> Res=
|
||||
find_tail_impl( Begin, End, -m_N );
|
||||
|
||||
return findit( Begin, End, category() );
|
||||
return make_iterator_range(Begin, Res.begin());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Find operation implementation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
findit(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
std::forward_iterator_tag ) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=Begin;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<m_N && It!=End; ++Index,++It ) {};
|
||||
|
||||
return result_type( Begin, It );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
findit(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
std::random_access_iterator_tag ) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < m_N ) )
|
||||
return result_type( Begin, End );
|
||||
|
||||
return result_type(Begin,Begin+m_N);
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int m_N;
|
||||
int m_N;
|
||||
};
|
||||
|
||||
// find tail functor -----------------------------------------------//
|
||||
|
||||
|
||||
// find a tail in the sequence ( functor )
|
||||
/*
|
||||
This functor find a tail of the specified range. For
|
||||
@ -349,7 +509,7 @@ namespace boost {
|
||||
struct tail_finderF
|
||||
{
|
||||
// Construction
|
||||
tail_finderF( unsigned int N ) : m_N(N) {}
|
||||
tail_finderF( int N ) : m_N(N) {}
|
||||
|
||||
// Operation
|
||||
template< typename ForwardIteratorT >
|
||||
@ -358,74 +518,21 @@ namespace boost {
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
if(m_N>=0)
|
||||
{
|
||||
return find_tail_impl( Begin, End, m_N );
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator_range<ForwardIteratorT> Res=
|
||||
find_head_impl( Begin, End, -m_N );
|
||||
|
||||
return findit( Begin, End, category() );
|
||||
return make_iterator_range(Res.end(), End);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Find operation implementation
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
findit(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
std::forward_iterator_tag ) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
unsigned int Index=0;
|
||||
input_iterator_type It=Begin;
|
||||
input_iterator_type It2=Begin;
|
||||
|
||||
// Advance It2 by N incremets
|
||||
for( Index=0; Index<m_N && It2!=End; ++Index,++It2 ) {};
|
||||
|
||||
// Advance It, It2 to the end
|
||||
for(; It2!=End; ++It,++It2 ) {};
|
||||
|
||||
return result_type( It, It2 );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
findit(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
std::bidirectional_iterator_tag ) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=End;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<m_N && It!=Begin; ++Index,--It ) {};
|
||||
|
||||
return result_type( It, End );
|
||||
}
|
||||
|
||||
template< typename ForwardIteratorT >
|
||||
iterator_range<ForwardIteratorT>
|
||||
findit(
|
||||
ForwardIteratorT Begin,
|
||||
ForwardIteratorT End,
|
||||
std::random_access_iterator_tag ) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < m_N ) )
|
||||
return result_type( Begin, End );
|
||||
|
||||
return result_type( End-m_N, End );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
unsigned int m_N;
|
||||
int m_N;
|
||||
};
|
||||
|
||||
// find token functor -----------------------------------------------//
|
||||
@ -475,7 +582,7 @@ namespace boost {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Advance by one possition
|
||||
// Advance by one position
|
||||
++It2;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
@ -387,6 +387,7 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
a modified copy of the input
|
||||
|
||||
@ -400,7 +401,7 @@ namespace boost {
|
||||
OutputIteratorT Output,
|
||||
const Range1T& Input,
|
||||
const Range2T& Search,
|
||||
unsigned int Nth )
|
||||
int Nth )
|
||||
{
|
||||
return find_format_copy(
|
||||
Output,
|
||||
@ -417,7 +418,7 @@ namespace boost {
|
||||
inline SequenceT erase_nth_copy(
|
||||
const SequenceT& Input,
|
||||
const RangeT& Search,
|
||||
unsigned int Nth )
|
||||
int Nth )
|
||||
{
|
||||
return find_format_copy(
|
||||
Input,
|
||||
@ -433,12 +434,13 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
*/
|
||||
template<typename SequenceT, typename RangeT>
|
||||
inline void erase_nth(
|
||||
SequenceT& Input,
|
||||
const RangeT& Search,
|
||||
unsigned int Nth )
|
||||
int Nth )
|
||||
{
|
||||
find_format(
|
||||
Input,
|
||||
@ -459,6 +461,7 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
a modified copy of the input
|
||||
@ -473,7 +476,7 @@ namespace boost {
|
||||
OutputIteratorT Output,
|
||||
const Range1T& Input,
|
||||
const Range2T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -491,7 +494,7 @@ namespace boost {
|
||||
inline SequenceT ierase_nth_copy(
|
||||
const SequenceT& Input,
|
||||
const RangeT& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -508,13 +511,14 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
*/
|
||||
template<typename SequenceT, typename RangeT>
|
||||
inline void ierase_nth(
|
||||
SequenceT& Input,
|
||||
const RangeT& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
find_format(
|
||||
@ -675,7 +679,9 @@ namespace boost {
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
\param N Length of the head.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
a modified copy of the input
|
||||
|
||||
@ -687,7 +693,7 @@ namespace boost {
|
||||
inline OutputIteratorT erase_head_copy(
|
||||
OutputIteratorT Output,
|
||||
const RangeT& Input,
|
||||
unsigned int N )
|
||||
int N )
|
||||
{
|
||||
return find_format_copy(
|
||||
Output,
|
||||
@ -703,7 +709,7 @@ namespace boost {
|
||||
template<typename SequenceT>
|
||||
inline SequenceT erase_head_copy(
|
||||
const SequenceT& Input,
|
||||
unsigned int N )
|
||||
int N )
|
||||
{
|
||||
return find_format_copy(
|
||||
Input,
|
||||
@ -719,11 +725,13 @@ namespace boost {
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
*/
|
||||
template<typename SequenceT>
|
||||
inline void erase_head(
|
||||
SequenceT& Input,
|
||||
unsigned int N )
|
||||
int N )
|
||||
{
|
||||
find_format(
|
||||
Input,
|
||||
@ -743,7 +751,9 @@ namespace boost {
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
\param N Length of the head.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
a modified copy of the input
|
||||
|
||||
@ -755,7 +765,7 @@ namespace boost {
|
||||
inline OutputIteratorT erase_tail_copy(
|
||||
OutputIteratorT Output,
|
||||
const RangeT& Input,
|
||||
unsigned int N )
|
||||
int N )
|
||||
{
|
||||
return find_format_copy(
|
||||
Output,
|
||||
@ -771,7 +781,7 @@ namespace boost {
|
||||
template<typename SequenceT>
|
||||
inline SequenceT erase_tail_copy(
|
||||
const SequenceT& Input,
|
||||
unsigned int N )
|
||||
int N )
|
||||
{
|
||||
return find_format_copy(
|
||||
Input,
|
||||
@ -787,11 +797,13 @@ namespace boost {
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
*/
|
||||
template<typename SequenceT>
|
||||
inline void erase_tail(
|
||||
SequenceT& Input,
|
||||
unsigned int N )
|
||||
int N )
|
||||
{
|
||||
find_format(
|
||||
Input,
|
||||
|
@ -176,6 +176,7 @@ namespace boost {
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index (zero-indexed) of the match to be found.
|
||||
For negative N, the matches are counted from the end of string.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
@ -188,7 +189,7 @@ namespace boost {
|
||||
find_nth(
|
||||
Range1T& Input,
|
||||
const Range2T& Search,
|
||||
unsigned int Nth)
|
||||
int Nth)
|
||||
{
|
||||
return nth_finder(Search,Nth)(
|
||||
begin(Input),end(Input));
|
||||
@ -196,12 +197,13 @@ namespace boost {
|
||||
|
||||
//! Find n-th algorithm ( case insensitive ).
|
||||
/*!
|
||||
Search for the n-th (zero-indexed) occurence of the substring in the
|
||||
Search for the n-th (zero-indexed) occurrence of the substring in the
|
||||
input. Searching is case insensitive.
|
||||
|
||||
\param Input A string which will be searched.
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index (zero-indexed) of the match to be found.
|
||||
\param Nth An index (zero-indexed) of the match to be found.
|
||||
For negative N, the matches are counted from the end of string.
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
@ -218,7 +220,7 @@ namespace boost {
|
||||
ifind_nth(
|
||||
Range1T& Input,
|
||||
const Range2T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const std::locale& Loc=std::locale())
|
||||
{
|
||||
return nth_finder(Search,Nth,is_iequal(Loc))(
|
||||
@ -235,6 +237,8 @@ namespace boost {
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c Range1T::iterator or
|
||||
@ -248,7 +252,7 @@ namespace boost {
|
||||
BOOST_STRING_TYPENAME range_result_iterator<RangeT>::type>
|
||||
find_head(
|
||||
RangeT& Input,
|
||||
unsigned int N)
|
||||
int N)
|
||||
{
|
||||
return head_finder(N)(
|
||||
begin(Input),end(Input));
|
||||
@ -263,7 +267,9 @@ namespace boost {
|
||||
to be the tail.
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the tail
|
||||
\param N Length of the tail.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\return
|
||||
An \c iterator_range delimiting the match.
|
||||
Returned iterator is either \c RangeT::iterator or
|
||||
@ -278,7 +284,7 @@ namespace boost {
|
||||
BOOST_STRING_TYPENAME range_result_iterator<RangeT>::type>
|
||||
find_tail(
|
||||
RangeT& Input,
|
||||
unsigned int N)
|
||||
int N)
|
||||
{
|
||||
return tail_finder(N)(
|
||||
begin(Input),end(Input));
|
||||
|
@ -71,7 +71,6 @@ namespace boost {
|
||||
return detail::find_format_copy_impl(
|
||||
Output,
|
||||
Input,
|
||||
Finder,
|
||||
Formatter,
|
||||
Finder( begin(Input), end(Input) ) );
|
||||
}
|
||||
@ -100,7 +99,6 @@ namespace boost {
|
||||
|
||||
return detail::find_format_copy_impl(
|
||||
Input,
|
||||
Finder,
|
||||
Formatter,
|
||||
Finder(begin(Input), end(Input)));
|
||||
}
|
||||
@ -134,7 +132,6 @@ namespace boost {
|
||||
|
||||
detail::find_format_impl(
|
||||
Input,
|
||||
Finder,
|
||||
Formatter,
|
||||
Finder(begin(Input), end(Input)));
|
||||
}
|
||||
|
@ -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)
|
||||
@ -132,7 +132,7 @@ namespace boost {
|
||||
is_equal>
|
||||
nth_finder(
|
||||
const ContainerT& Search,
|
||||
unsigned int Nth)
|
||||
int Nth)
|
||||
{
|
||||
return
|
||||
detail::nth_finderF<
|
||||
@ -150,7 +150,7 @@ namespace boost {
|
||||
PredicateT>
|
||||
nth_finder(
|
||||
const ContainerT& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
PredicateT Comp )
|
||||
{
|
||||
return
|
||||
@ -172,7 +172,7 @@ namespace boost {
|
||||
\return An instance of the \c head_finder object
|
||||
*/
|
||||
inline detail::head_finderF
|
||||
head_finder( unsigned int N )
|
||||
head_finder( int N )
|
||||
{
|
||||
return detail::head_finderF(N);
|
||||
}
|
||||
@ -189,7 +189,7 @@ namespace boost {
|
||||
\return An instance of the \c tail_finder object
|
||||
*/
|
||||
inline detail::tail_finderF
|
||||
tail_finder( unsigned int N )
|
||||
tail_finder( int N )
|
||||
{
|
||||
return detail::tail_finderF(N);
|
||||
}
|
||||
|
144
include/boost/algorithm/string/join.hpp
Normal file
144
include/boost/algorithm/string/join.hpp
Normal file
@ -0,0 +1,144 @@
|
||||
// Boost string_algo library join.hpp header file ---------------------------//
|
||||
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#ifndef BOOST_STRING_JOIN_HPP
|
||||
#define BOOST_STRING_JOIN_HPP
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <boost/algorithm/string/detail/sequence.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
|
||||
|
||||
/*! \file
|
||||
Defines join algorithm.
|
||||
|
||||
Join algorithm is a counterpart to split algorithms.
|
||||
It joins strings from a 'list' by adding user defined separator.
|
||||
Additionally there is a version that allows simple filtering
|
||||
by providing a predicate.
|
||||
*/
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
|
||||
// join --------------------------------------------------------------//
|
||||
|
||||
//! Join algorithm
|
||||
/*!
|
||||
This algorithm joins all strings in a 'list' into one long string.
|
||||
Segments are concatenated by given separator.
|
||||
|
||||
\param Input A container that holds the input strings. It must be a container-of-containers.
|
||||
\param Separator A string that will separate the joined segments.
|
||||
\return Concatenated string.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template< typename SequenceSequenceT, typename Range1T>
|
||||
inline typename range_value<SequenceSequenceT>::type
|
||||
join(
|
||||
const SequenceSequenceT& Input,
|
||||
Range1T& Separator)
|
||||
{
|
||||
// Define working types
|
||||
typedef typename range_value<SequenceSequenceT>::type ResultT;
|
||||
typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT;
|
||||
|
||||
// Parse input
|
||||
InputIteratorT itBegin=begin(Input);
|
||||
InputIteratorT itEnd=end(Input);
|
||||
|
||||
// Construct container to hold the result
|
||||
ResultT Result;
|
||||
|
||||
// Append first element
|
||||
if(itBegin!=itEnd)
|
||||
{
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
++itBegin;
|
||||
}
|
||||
|
||||
for(;itBegin!=itEnd; ++itBegin)
|
||||
{
|
||||
// Add separator
|
||||
detail::insert(Result, end(Result), Separator);
|
||||
// Add element
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
// join_if ----------------------------------------------------------//
|
||||
|
||||
//! Conditional join algorithm
|
||||
/*!
|
||||
This algorithm joins all strings in a 'list' into one long string.
|
||||
Segments are concatenated by given separator. Only segments that
|
||||
satisfy the predicate will be added to the result.
|
||||
|
||||
\param Input A container that holds the input strings. It must be a container-of-containers.
|
||||
\param Separator A string that will separate the joined segments.
|
||||
\param Pred A segment selection predicate
|
||||
\return Concatenated string.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template< typename SequenceSequenceT, typename Range1T, typename PredicateT>
|
||||
inline typename range_value<SequenceSequenceT>::type
|
||||
join_if(
|
||||
const SequenceSequenceT& Input,
|
||||
Range1T& Separator,
|
||||
PredicateT Pred)
|
||||
{
|
||||
// Define working types
|
||||
typedef typename range_value<SequenceSequenceT>::type ResultT;
|
||||
typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT;
|
||||
|
||||
// Parse input
|
||||
InputIteratorT itBegin=begin(Input);
|
||||
InputIteratorT itEnd=end(Input);
|
||||
|
||||
// Construct container to hold the result
|
||||
ResultT Result;
|
||||
|
||||
// Roll to the first element that will be added
|
||||
while(itBegin!=itEnd && !Pred(*itBegin)) ++itBegin;
|
||||
// Add this element
|
||||
if(itBegin!=itEnd)
|
||||
{
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
++itBegin;
|
||||
}
|
||||
|
||||
for(;itBegin!=itEnd; ++itBegin)
|
||||
{
|
||||
if(Pred(*itBegin))
|
||||
{
|
||||
// Add separator
|
||||
detail::insert(Result, end(Result), Separator);
|
||||
// Add element
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
} // namespace algorithm
|
||||
|
||||
// pull names to the boost namespace
|
||||
using algorithm::join;
|
||||
using algorithm::join_if;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_STRING_JOIN_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,86 @@ 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<typename Range1T, typename Range2T, typename PredicateT>
|
||||
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<typename Range1T, typename Range2T>
|
||||
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
|
||||
\return The result of the test
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<typename Range1T, typename Range2T>
|
||||
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 +454,8 @@ namespace boost {
|
||||
using algorithm::equals;
|
||||
using algorithm::iequals;
|
||||
using algorithm::all;
|
||||
using algorithm::lexicographical_compare;
|
||||
using algorithm::ilexicographical_compare;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
@ -474,6 +474,147 @@ namespace boost {
|
||||
regex_finder(Rx,Flags) );
|
||||
}
|
||||
|
||||
// join_if ------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
|
||||
//! Conditional join algorithm
|
||||
/*!
|
||||
This algorithm joins all strings in a 'list' into one long string.
|
||||
Segments are concatenated by given separator. Only segments that
|
||||
match the given regular expression will be added to the result
|
||||
|
||||
This is a specialization of join_if algorithm.
|
||||
|
||||
\param Input A container that holds the input strings. It must be a container-of-containers.
|
||||
\param Separator A string that will separate the joined segments.
|
||||
\param Rx A regular expression
|
||||
\param Flags Regex options
|
||||
\return Concatenated string.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<
|
||||
typename SequenceSequenceT,
|
||||
typename Range1T,
|
||||
typename CharT,
|
||||
typename RegexTraitsT >
|
||||
inline typename range_value<SequenceSequenceT>::type
|
||||
join_if(
|
||||
const SequenceSequenceT& Input,
|
||||
Range1T& Separator,
|
||||
const basic_regex<CharT, RegexTraitsT>& Rx,
|
||||
match_flag_type Flags=match_default )
|
||||
{
|
||||
// Define working types
|
||||
typedef typename range_value<SequenceSequenceT>::type ResultT;
|
||||
typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT;
|
||||
|
||||
// Parse input
|
||||
InputIteratorT itBegin=begin(Input);
|
||||
InputIteratorT itEnd=end(Input);
|
||||
|
||||
// Construct container to hold the result
|
||||
ResultT Result;
|
||||
|
||||
|
||||
// Roll to the first element that will be added
|
||||
while(
|
||||
itBegin!=itEnd &&
|
||||
!regex_match(begin(*itBegin), end(*itBegin), Rx, Flags)) ++itBegin;
|
||||
|
||||
// Add this element
|
||||
if(itBegin!=itEnd)
|
||||
{
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
++itBegin;
|
||||
}
|
||||
|
||||
for(;itBegin!=itEnd; ++itBegin)
|
||||
{
|
||||
if(regex_match(begin(*itBegin), end(*itBegin), Rx, Flags))
|
||||
{
|
||||
// Add separator
|
||||
detail::insert(Result, end(Result), Separator);
|
||||
// Add element
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
|
||||
//! Conditional join algorithm
|
||||
/*!
|
||||
This algorithm joins all strings in a 'list' into one long string.
|
||||
Segments are concatenated by given separator. Only segments that
|
||||
match the given regular expression will be added to the result
|
||||
|
||||
This is a specialization of join_if algorithm.
|
||||
|
||||
\param Input A container that holds the input strings. It must be a container-of-containers.
|
||||
\param Separator A string that will separate the joined segments.
|
||||
\param Rx A regular expression
|
||||
\param Flags Regex options
|
||||
\return Concatenated string.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template<
|
||||
typename SequenceSequenceT,
|
||||
typename Range1T,
|
||||
typename CharT,
|
||||
typename RegexTraitsT >
|
||||
inline typename range_value<SequenceSequenceT>::type
|
||||
join_if_regex(
|
||||
const SequenceSequenceT& Input,
|
||||
Range1T& Separator,
|
||||
const basic_regex<CharT, RegexTraitsT>& Rx,
|
||||
match_flag_type Flags=match_default )
|
||||
{
|
||||
// Define working types
|
||||
typedef typename range_value<SequenceSequenceT>::type ResultT;
|
||||
typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT;
|
||||
|
||||
// Parse input
|
||||
InputIteratorT itBegin=begin(Input);
|
||||
InputIteratorT itEnd=end(Input);
|
||||
|
||||
// Construct container to hold the result
|
||||
ResultT Result;
|
||||
|
||||
|
||||
// Roll to the first element that will be added
|
||||
while(
|
||||
itBegin!=itEnd &&
|
||||
!regex_match(begin(*itBegin), end(*itBegin), Rx, Flags)) ++itBegin;
|
||||
|
||||
// Add this element
|
||||
if(itBegin!=itEnd)
|
||||
{
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
++itBegin;
|
||||
}
|
||||
|
||||
for(;itBegin!=itEnd; ++itBegin)
|
||||
{
|
||||
if(regex_match(begin(*itBegin), end(*itBegin), Rx, Flags))
|
||||
{
|
||||
// Add separator
|
||||
detail::insert(Result, end(Result), Separator);
|
||||
// Add element
|
||||
detail::insert(Result, end(Result), *itBegin);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
|
||||
} // namespace algorithm
|
||||
|
||||
// pull names into the boost namespace
|
||||
@ -489,6 +630,14 @@ namespace boost {
|
||||
using algorithm::find_all_regex;
|
||||
using algorithm::split_regex;
|
||||
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
using algorithm::join_if;
|
||||
#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
using algorithm::join_if_regex;
|
||||
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
@ -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)
|
||||
@ -428,6 +428,7 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
\param Format A substitute string
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
a modified copy of the input
|
||||
@ -443,7 +444,7 @@ namespace boost {
|
||||
OutputIteratorT Output,
|
||||
const Range1T& Input,
|
||||
const Range2T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const Range3T& Format )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -461,7 +462,7 @@ namespace boost {
|
||||
inline SequenceT replace_nth_copy(
|
||||
const SequenceT& Input,
|
||||
const Range1T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const Range2T& Format )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -478,13 +479,14 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
\param Format A substitute string
|
||||
*/
|
||||
template<typename SequenceT, typename Range1T, typename Range2T>
|
||||
inline void replace_nth(
|
||||
SequenceT& Input,
|
||||
const Range1T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const Range2T& Format )
|
||||
{
|
||||
find_format(
|
||||
@ -507,6 +509,7 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
\param Format A substitute string
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
@ -523,7 +526,7 @@ namespace boost {
|
||||
OutputIteratorT Output,
|
||||
const Range1T& Input,
|
||||
const Range2T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const Range3T& Format,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
@ -542,7 +545,7 @@ namespace boost {
|
||||
inline SequenceT ireplace_nth_copy(
|
||||
const SequenceT& Input,
|
||||
const Range1T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const Range2T& Format,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
@ -561,6 +564,7 @@ namespace boost {
|
||||
\param Input An input string
|
||||
\param Search A substring to be searched for
|
||||
\param Nth An index of the match to be replaced. The index is 0-based.
|
||||
For negative N, matches are counted from the end of string.
|
||||
\param Format A substitute string
|
||||
\param Loc A locale used for case insensitive comparison
|
||||
*/
|
||||
@ -568,7 +572,7 @@ namespace boost {
|
||||
inline void ireplace_nth(
|
||||
SequenceT& Input,
|
||||
const Range1T& Search,
|
||||
unsigned int Nth,
|
||||
int Nth,
|
||||
const Range2T& Format,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
@ -745,7 +749,9 @@ namespace boost {
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
\param N Length of the head.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\param Format A substitute string
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
a modified copy of the input
|
||||
@ -759,7 +765,7 @@ namespace boost {
|
||||
inline OutputIteratorT replace_head_copy(
|
||||
OutputIteratorT Output,
|
||||
const Range1T& Input,
|
||||
unsigned int N,
|
||||
int N,
|
||||
const Range2T& Format )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -776,7 +782,7 @@ namespace boost {
|
||||
template<typename SequenceT, typename RangeT>
|
||||
inline SequenceT replace_head_copy(
|
||||
const SequenceT& Input,
|
||||
unsigned int N,
|
||||
int N,
|
||||
const RangeT& Format )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -793,13 +799,15 @@ namespace boost {
|
||||
considered to be the head. The input sequence is modified in-place.
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the head
|
||||
\param N Length of the head.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\param Format A substitute string
|
||||
*/
|
||||
template<typename SequenceT, typename RangeT>
|
||||
inline void replace_head(
|
||||
SequenceT& Input,
|
||||
unsigned int N,
|
||||
int N,
|
||||
const RangeT& Format )
|
||||
{
|
||||
find_format(
|
||||
@ -821,7 +829,9 @@ namespace boost {
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input string
|
||||
\param N Length of the tail
|
||||
\param N Length of the tail.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\param Format A substitute string
|
||||
\return An output iterator pointing just after the last inserted character or
|
||||
a modified copy of the input
|
||||
@ -835,7 +845,7 @@ namespace boost {
|
||||
inline OutputIteratorT replace_tail_copy(
|
||||
OutputIteratorT Output,
|
||||
const Range1T& Input,
|
||||
unsigned int N,
|
||||
int N,
|
||||
const Range2T& Format )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -852,7 +862,7 @@ namespace boost {
|
||||
template<typename SequenceT, typename RangeT>
|
||||
inline SequenceT replace_tail_copy(
|
||||
const SequenceT& Input,
|
||||
unsigned int N,
|
||||
int N,
|
||||
const RangeT& Format )
|
||||
{
|
||||
return find_format_copy(
|
||||
@ -869,13 +879,15 @@ namespace boost {
|
||||
considered to be the tail. The input sequence is modified in-place.
|
||||
|
||||
\param Input An input string
|
||||
\param N Length of the tail
|
||||
\param N Length of the tail.
|
||||
For N>=0, at most N characters are extracted.
|
||||
For N<0, size(Input)-|N| characters are extracted.
|
||||
\param Format A substitute string
|
||||
*/
|
||||
template<typename SequenceT, typename RangeT>
|
||||
inline void replace_tail(
|
||||
SequenceT& Input,
|
||||
unsigned int N,
|
||||
int N,
|
||||
const RangeT& Format )
|
||||
{
|
||||
find_format(
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Boost string_algo library find.hpp header file ---------------------------//
|
||||
// Boost string_algo library split.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)
|
||||
@ -55,7 +55,7 @@ namespace boost {
|
||||
|
||||
\note Prior content of the result will be overwritten.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
||||
inline SequenceSequenceT& find_all(
|
||||
@ -90,7 +90,7 @@ namespace boost {
|
||||
|
||||
\note Prior content of the result will be overwritten.
|
||||
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
\note This function provides the strong exception-safety guarantee
|
||||
*/
|
||||
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
||||
inline SequenceSequenceT& ifind_all(
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <boost/algorithm/string/yes_no_type.hpp>
|
||||
#include <slist>
|
||||
#include BOOST_SLIST_HEADER
|
||||
#include <boost/algorithm/string/sequence_traits.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
@ -35,7 +35,7 @@ means that all the elements are distinct and in increasing order, <i>decrea</i>s
|
||||
is the reverse, and <i>random</i> is produced by random_shuffle.
|
||||
<br>
|
||||
The program that created these tables is included in the distribution,
|
||||
under <a href=""../example/minmax_timer.cpp"">minmax_timer.cpp</a>
|
||||
under <a href="../example/minmax_timer.cpp">minmax_timer.cpp</a>
|
||||
<br>
|
||||
<center><table BORDER NOSAVE >
|
||||
<tr NOSAVE>
|
||||
|
@ -1,14 +0,0 @@
|
||||
# Boost.Minmax Library Example Jamfile
|
||||
#
|
||||
# Copyright (C) 2002--2004, Herve Bronnimann
|
||||
#
|
||||
# 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)
|
||||
#
|
||||
|
||||
subproject libs/algorithm/minmax/example ;
|
||||
|
||||
exe minmax_ex : minmax_ex.cpp ;
|
||||
exe minmax_timer : minmax_timer.cpp ;
|
||||
|
@ -56,7 +56,7 @@ be enough. The present library solves both problems.</p>
|
||||
<tt>minmax</tt>
|
||||
as straightforward extensions of the C++
|
||||
standard. As it returns a pair of <tt>const&</tt>, we must use the <a
|
||||
href=:../../tuple/index.html>Boost.tuple</a> library to construct such
|
||||
href=:../../../../tuple/index.html>Boost.tuple</a> library to construct such
|
||||
pairs. (Please note: the intent is not to fix the known defaults of
|
||||
<tt>std::min</tt>
|
||||
and <tt>std::max</tt>, but to add one more algorithms that combines both; see the
|
||||
@ -95,7 +95,7 @@ namespace boost {
|
||||
tuple<T const&, T const&> >
|
||||
minmax(const T& a, const T& b);
|
||||
|
||||
template <class T, class <a href="http://www.sgi.com/tech/stl/ BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class T, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
tuple<T const&, T const&> >
|
||||
minmax(const T& a, const T& b, BinaryPredicate comp);
|
||||
|
||||
@ -350,8 +350,7 @@ separation into two header files.</p>
|
||||
std::max.</b></h4>
|
||||
<p>I am aware of the problems with std::min and
|
||||
std::max, and all the debate that has been going on (please consult
|
||||
<a href="http://www.cuj.com/experts/1904/alexandr.htm?topic=experts&topic=experts">Alexandrescu's
|
||||
paper</a> and the links therein). But I don't see the purpose of this
|
||||
<a href="http://www.cuj.com/documents/s=7996/cujcexp1904alexandr/alexandr.htm">Alexandrescu's paper</a> and the links therein). But I don't see the purpose of this
|
||||
library as fixing something that is part of the C++ standard. I humbly
|
||||
think it's beyond the scope of this library. Rather, I am
|
||||
following the way of the standard in simply providing one more function
|
||||
|
@ -1,33 +0,0 @@
|
||||
# Boost.Minmax Library Test Jamfile
|
||||
#
|
||||
# Copyright (C) 2002--2004, Herve Bronnimann
|
||||
#
|
||||
# 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)
|
||||
#
|
||||
|
||||
subproject libs/algorithm/minmax/test ;
|
||||
|
||||
# bring in rules for testing
|
||||
import testing ;
|
||||
|
||||
# Make tests run by default.
|
||||
DEPENDS all : test ;
|
||||
|
||||
{
|
||||
test-suite algorithm/minmax
|
||||
: [ run
|
||||
minmax_element_test.cpp
|
||||
: :
|
||||
:
|
||||
: minmax_element
|
||||
]
|
||||
[ run
|
||||
minmax_test.cpp
|
||||
: :
|
||||
:
|
||||
: minmax
|
||||
]
|
||||
;
|
||||
}
|
@ -32,6 +32,7 @@ doxygen autodoc
|
||||
[ glob ../../../../boost/algorithm/string/predicate.hpp ]
|
||||
[ glob ../../../../boost/algorithm/string/split.hpp ]
|
||||
[ glob ../../../../boost/algorithm/string/erase.hpp ]
|
||||
[ glob ../../../../boost/algorithm/string/join.hpp ]
|
||||
[ glob ../../../../boost/algorithm/string/replace.hpp ]
|
||||
[ glob ../../../../boost/algorithm/string/find_format.hpp ]
|
||||
[ glob ../../../../boost/algorithm/string/formatter.hpp ]
|
||||
|
@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
|
||||
<section id="string_algo.concept" last-revision="$Date$">
|
||||
<title>Concepts</title>
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
|
||||
<section id="string_algo.credits" last-revision="$Date$">
|
||||
<title>Credits</title>
|
||||
<section id="string_algo.ack">
|
||||
|
@ -1,6 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<section id="string_algo.design" last-revision="$Date$">
|
||||
<title>Design Topics</title>
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<section id="string_algo.env" last-revision="$Date$">
|
||||
<title>Environment</title>
|
||||
<section>
|
||||
|
@ -1,38 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title> Concepts and External Concepts </title><meta http-equiv="Content-Type"content="text/html; charset=iso-8859-1"></head> <body><table ><tr ><td ><img src="../../../../boost.png" width="100%" border="0"></td><td ><h1 >Concepts and External Concepts</h1></td></tr></table><p >Generic programming in C++ is characterized by the use of function and class templates where
|
||||
the template parameter(s) must satisfy certain requirements.Often these
|
||||
requirements are so important that we give them a name: we call
|
||||
such a set of type requirements a <b>concept</b>. We say that a type <i>
|
||||
conforms to a concept</i> or that it <i>is a model of a concept</i> if it
|
||||
satisfies all of those requirements. The concept can be specified as a set
|
||||
of member functions with well-defined semantics
|
||||
and a set of nested typedefs with well-defined properties.</p><p >Often it much more flexible to provide free-standing functions and typedefs
|
||||
which provides the exact same semantics (but a different syntax) as
|
||||
specified
|
||||
by the concept. This allows generic code to treat different types <i> as if
|
||||
</i> they fulfilled the concept. In this case we say that the concept has
|
||||
been <b> externalized </b> or that the new requirements constitutes an <b>external
|
||||
concept </b>. We say that a type <i> conforms to an external concept </i>
|
||||
or that it <i> is a model of an external concept </i>. A concept may exist
|
||||
without a corresponding external concept and conversely.</p><p >Whenever a concept specifies a member function, the corresponding external
|
||||
concept
|
||||
must specify a free-standing function of the same name, same return type and
|
||||
the same argument list except there is an extra first argument which must
|
||||
be of the type (or a reference to that type) that is to fulfill the external
|
||||
concept. If the corresonding member function has any cv-qulifiers, the
|
||||
first argument must have the same cv-qualifiers. Whenever a concept
|
||||
specifies a nested typedef, the corresponding external concept
|
||||
specifies a <b>type-generator</b>, that is, a type with a nested typedef
|
||||
named <code>type</code>. The type-generator has the name as the nested typedef with
|
||||
<code>_of</code> appended.
|
||||
The converse relationship of an external concept and its corresponding concept
|
||||
also holds.</p><p ><b ><i >Example:</i></b></p><p >A type <code>T</code> fulfills the FooConcept if it
|
||||
has the follwing public members:</p><code> void T::foo( int ) const; <br>
|
||||
int T::bar(); <br>
|
||||
typedef <i>implementation defined </i> foo_type;</code><p >The corresponding external concept is the ExternalFooConcept.</p><p >A type <code>T</code> fullfills the ExternalFooConcept if these
|
||||
free-standing functions and type-generators exists:</p><code>void foo( const T&, int ); <br>
|
||||
int bar( T& ); <br>
|
||||
foo_type_of< T >::type;</code> <br> <br><hr size="1" ><h3 >Literature</h3><ul ><li > <a href="http://www.boost.org/more/generic_programming.html#type_generator" target="_self" >Type Generators</a> </li><li > <a href="http://www.boost.org/more/generic_programming.html#concept" target="_self" >Concepts</a> </li><li > <a href="http://www.sgi.com/tech/stl/stl_introduction.html" target="_self" >Concepts and SGI STL</a> </li></ul><hr size="1" ><p >© Thorsten Ottosen 2003-2004 (nesotto_AT_cs.auc.dk).
|
||||
Permission to copy, use, modify, sell and distribute this software is granted provided this copyright notice appears
|
||||
in all copies. This software is provided "as is" without express or implied warranty, and with no
|
||||
claim as to its suitability for any purpose.</p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></body></html>
|
||||
<!-- Copyright Dezide Aps 2003-2004 -->
|
@ -1,6 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<section id="string_algo.intro" last-revision="$Date$">
|
||||
<title>Introduction</title>
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<section id="string_algo.quickref" last-revision="$Date$">
|
||||
<title>Quick Reference</title>
|
||||
|
||||
@ -143,6 +149,16 @@
|
||||
<functionname>iequals()</functionname>
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><code>lexicographical_compare</code></entry>
|
||||
<entry>Check if a string is lexicographicaly less then another one</entry>
|
||||
<entry>
|
||||
<functionname>lexicographical_compare()</functionname>
|
||||
<sbr/>
|
||||
<functionname>ilexicographical_compare()</functionname>
|
||||
</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><code>all</code></entry>
|
||||
<entry>Check if all elements of a string satisfy the given predicate</entry>
|
||||
@ -430,6 +446,34 @@
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<table>
|
||||
<title>Join</title>
|
||||
<tgroup cols="3" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Algorithm name</entry>
|
||||
<entry>Description</entry>
|
||||
<entry>Functions</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>join</entry>
|
||||
<entry>Join all elements in a container into a single string</entry>
|
||||
<entry>
|
||||
<functionname>join</functionname>
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>join_if</entry>
|
||||
<entry>Join all elements in a container that satisfies the condition into a single string</entry>
|
||||
<entry>
|
||||
<functionname>join_if()</functionname>
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</section>
|
||||
<section>
|
||||
<title>Finders and Formatters</title>
|
||||
|
@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
|
||||
<section id="string_algo.rationale" last-revision="$Date$">
|
||||
<title>Rationale</title>
|
||||
|
||||
|
@ -1,7 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<section id="string_algo.release_notes" last-revision="$Date$">
|
||||
|
||||
<using-namespace name="boost"/>
|
||||
<using-namespace name="boost::algorithm"/>
|
||||
|
||||
<title>Release Notes</title>
|
||||
|
||||
<itemizedlist>
|
||||
@ -13,5 +23,23 @@
|
||||
<para><emphasis role="bold">1.33</emphasis></para>
|
||||
<para>Internal version of collection traits removed, library adapted to Boost.Range</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis role="bold">1.34</emphasis></para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<functionname>lexicographical_compare()</functionname>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<functionname>join()</functionname> and <functionname>join_if()</functionname>
|
||||
</listitem>
|
||||
<listitem>
|
||||
New comparison predicates <code>is_less</code>, <code>is_not_greater</code>
|
||||
</listitem>
|
||||
<listitem>
|
||||
Negative indexes support (like Perl) in various algorihtms
|
||||
(<code>*_head/tail</code>, <code>*_nth</code>).
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</section>
|
||||
|
@ -1,6 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<library name="String Algorithms" dirname="algorithm/string" xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||
id="string_algo" last-revision="$Date$">
|
||||
<libraryinfo>
|
||||
|
@ -1,6 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<section id="string_algo.usage" last-revision="$Date$">
|
||||
<title>Usage</title>
|
||||
|
||||
@ -206,7 +212,7 @@
|
||||
|
||||
As we can see, input of the <functionname>find_last()</functionname> algorithm can be also
|
||||
char[] because this type is supported by
|
||||
<ulink linkend="../../libs/range/doc/index.html">Boost.Range</ulink>.
|
||||
<ulink url="../../libs/range/index.html">Boost.Range</ulink>.
|
||||
|
||||
The following lines transform the result. Notice that
|
||||
<ulink url="../../libs/range/doc/utility_class.html"><code>boost::iterator_range</code></ulink> has familiar
|
||||
@ -283,9 +289,9 @@
|
||||
// aBC
|
||||
|
||||
typedef split_iterator<string::iterator> string_split_iterator;
|
||||
for(string_find_iterator It=
|
||||
for(string_split_iterator It=
|
||||
make_split_iterator(str1, first_finder("-*-", is_iequal()));
|
||||
It!=string_find_iterator();
|
||||
It!=string_split_iterator();
|
||||
++It)
|
||||
{
|
||||
cout << copy_range<std::string>(*It) << endl;
|
||||
|
@ -1,75 +0,0 @@
|
||||
# Boost string_algo library examples Jamfile ---------------------------------
|
||||
#
|
||||
# Copyright Pavol Droba 2002-2003. 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)
|
||||
#
|
||||
# See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
subproject libs/algorithm/string/example ;
|
||||
|
||||
exe conv_example
|
||||
:
|
||||
conv_example.cpp
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
||||
|
||||
exe predicate_example
|
||||
:
|
||||
predicate_example.cpp
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
||||
|
||||
exe find_example
|
||||
:
|
||||
find_example.cpp
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
||||
|
||||
exe replace_example
|
||||
:
|
||||
replace_example.cpp
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
||||
|
||||
exe rle_example
|
||||
:
|
||||
rle_example.cpp
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
||||
|
||||
exe trim_example
|
||||
:
|
||||
trim_example.cpp
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
||||
|
||||
exe regex_example
|
||||
:
|
||||
regex_example.cpp
|
||||
<lib>../../../regex/build/boost_regex
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
||||
|
||||
exe split_example
|
||||
:
|
||||
split_example.cpp
|
||||
:
|
||||
<include>$(BOOST_ROOT)
|
||||
:
|
||||
;
|
@ -1,9 +1,20 @@
|
||||
|
||||
<!-- Copyright (c) 2002-2006 Pavol Droba.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=../../../doc/html/string_algo.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../../../doc/html/string_algo.html">../../doc/html/string_algo.html</a>
|
||||
<a href="../../../doc/html/string_algo.html">../../doc/html/string_algo.html</a>
|
||||
<hr>
|
||||
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
@ -1,77 +0,0 @@
|
||||
# Boost string_algo library test suite Jamfile ----------------------------
|
||||
#
|
||||
# Copyright Pavol Droba 2002-2003. 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)
|
||||
#
|
||||
# See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
subproject libs/algorithm/string/test ;
|
||||
|
||||
# bring in rules for testing
|
||||
import testing ;
|
||||
|
||||
# Make tests run by default.
|
||||
DEPENDS all : test ;
|
||||
|
||||
{
|
||||
test-suite algorithm/string
|
||||
: [ run
|
||||
trim_test.cpp
|
||||
: :
|
||||
:
|
||||
std::locale-support
|
||||
std::facet-support
|
||||
: trim
|
||||
]
|
||||
[ run
|
||||
conv_test.cpp
|
||||
: :
|
||||
:
|
||||
std::locale-support
|
||||
std::facet-support
|
||||
: conv
|
||||
]
|
||||
[ run
|
||||
predicate_test.cpp
|
||||
: :
|
||||
:
|
||||
std::locale-support
|
||||
std::facet-support
|
||||
: predicate
|
||||
]
|
||||
[ run
|
||||
find_test.cpp
|
||||
: :
|
||||
:
|
||||
std::locale-support
|
||||
std::facet-support
|
||||
: find
|
||||
]
|
||||
[ run
|
||||
split_test.cpp
|
||||
: :
|
||||
:
|
||||
std::locale-support
|
||||
std::facet-support
|
||||
: split
|
||||
]
|
||||
[ run
|
||||
replace_test.cpp
|
||||
: :
|
||||
:
|
||||
std::locale-support
|
||||
std::facet-support
|
||||
: replace
|
||||
]
|
||||
[ run
|
||||
regex_test.cpp
|
||||
<lib>../../../regex/build/boost_regex
|
||||
: :
|
||||
:
|
||||
: regex
|
||||
]
|
||||
;
|
||||
}
|
||||
|
@ -40,6 +40,12 @@ test-suite algorithm/string
|
||||
:
|
||||
: split
|
||||
]
|
||||
[ run
|
||||
join_test.cpp
|
||||
: :
|
||||
:
|
||||
: join
|
||||
]
|
||||
[ run
|
||||
replace_test.cpp
|
||||
: :
|
||||
|
@ -93,16 +93,33 @@ void find_test()
|
||||
( (nc_result.begin()-str1.begin()) == 9) &&
|
||||
( (nc_result.end()-str1.begin()) == 12) );
|
||||
|
||||
nc_result=find_nth( str1, string("abc"), -1 );
|
||||
BOOST_CHECK(
|
||||
( (nc_result.begin()-str1.begin()) == 15) &&
|
||||
( (nc_result.end()-str1.begin()) == 18) );
|
||||
|
||||
|
||||
cv_result=find_nth( const_cast<const string&>(str1), str2, 1 );
|
||||
BOOST_CHECK(
|
||||
( (cv_result.begin()-str1.begin()) == 9) &&
|
||||
( (cv_result.end()-str1.begin()) == 12) );
|
||||
|
||||
cv_result=find_nth( const_cast<const string&>(str1), str2, -1 );
|
||||
BOOST_CHECK(
|
||||
( (cv_result.begin()-str1.begin()) == 15) &&
|
||||
( (cv_result.end()-str1.begin()) == 18) );
|
||||
|
||||
cv_result=ifind_nth( const_cast<const string&>(str1), "xxx", 1 );
|
||||
BOOST_CHECK(
|
||||
( (cv_result.begin()-str1.begin()) == 12) &&
|
||||
( (cv_result.end()-str1.begin()) == 15) );
|
||||
|
||||
cv_result=ifind_nth( const_cast<const string&>(str1), "xxx", 1 );
|
||||
BOOST_CHECK(
|
||||
( (cv_result.begin()-str1.begin()) == 12) &&
|
||||
( (cv_result.end()-str1.begin()) == 15) );
|
||||
|
||||
|
||||
ch_result=find_nth( pch1, "abc", 1 );
|
||||
BOOST_CHECK(( (ch_result.begin() - pch1 ) == 9) && ( (ch_result.end() - pch1 ) == 12 ) );
|
||||
|
||||
@ -114,6 +131,11 @@ void find_test()
|
||||
( (nc_result.begin()-str1.begin()) == 0) &&
|
||||
( (nc_result.end()-str1.begin()) == 6) );
|
||||
|
||||
nc_result=find_head( str1, -6 );
|
||||
BOOST_CHECK(
|
||||
( (nc_result.begin()-str1.begin()) == 0) &&
|
||||
( (str1.end()-nc_result.end()) == 6 ) );
|
||||
|
||||
cv_result=find_head( const_cast<const string&>(str1), 6 );
|
||||
BOOST_CHECK(
|
||||
( (cv_result.begin()-str1.begin()) == 0) &&
|
||||
@ -130,6 +152,12 @@ void find_test()
|
||||
( (nc_result.begin()-str1.begin()) == 15) &&
|
||||
( (nc_result.end()-str1.begin()) == 21) );
|
||||
|
||||
nc_result=find_tail( str1, -6 );
|
||||
BOOST_CHECK(
|
||||
( (nc_result.begin()-str1.begin()) == 6) &&
|
||||
( (nc_result.end()-str1.begin()) == 21) );
|
||||
|
||||
|
||||
cv_result=find_tail( const_cast<const string&>(str1), 6 );
|
||||
BOOST_CHECK(
|
||||
( (cv_result.begin()-str1.begin()) == 15) &&
|
||||
|
79
string/test/join_test.cpp
Normal file
79
string/test/join_test.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
// Boost string_algo library iterator_test.cpp file ---------------------------//
|
||||
|
||||
// Copyright Pavol Droba 2002-2003. 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)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
// equals predicate is used for result comparison
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
// Include unit test framework
|
||||
#include <boost/test/included/test_exec_monitor.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
bool is_not_empty(const std::string& str)
|
||||
{
|
||||
return !str.empty();
|
||||
}
|
||||
|
||||
void join_test()
|
||||
{
|
||||
// Prepare inputs
|
||||
vector<string> tokens1;
|
||||
tokens1.push_back("xx");
|
||||
tokens1.push_back("abc");
|
||||
tokens1.push_back("xx");
|
||||
|
||||
vector<string> tokens2;
|
||||
tokens2.push_back("");
|
||||
tokens2.push_back("xx");
|
||||
tokens2.push_back("abc");
|
||||
tokens2.push_back("");
|
||||
tokens2.push_back("abc");
|
||||
tokens2.push_back("xx");
|
||||
tokens2.push_back("");
|
||||
|
||||
vector<string> tokens3;
|
||||
tokens3.push_back("");
|
||||
tokens3.push_back("");
|
||||
tokens3.push_back("");
|
||||
|
||||
vector<string> empty_tokens;
|
||||
|
||||
vector<vector<int> > vtokens;
|
||||
for(unsigned int n=0; n<tokens2.size(); ++n)
|
||||
{
|
||||
vtokens.push_back(vector<int>(tokens2[n].begin(), tokens2[n].end()));
|
||||
}
|
||||
|
||||
BOOST_CHECK( equals(join(tokens1, "-"), "xx-abc-xx") );
|
||||
BOOST_CHECK( equals(join(tokens2, "-"), "-xx-abc--abc-xx-") );
|
||||
BOOST_CHECK( equals(join(vtokens, "-"), "-xx-abc--abc-xx-") );
|
||||
BOOST_CHECK( equals(join(empty_tokens, "-"), "") );
|
||||
|
||||
BOOST_CHECK( equals(join_if(tokens2, "-", is_not_empty), "xx-abc-abc-xx") );
|
||||
BOOST_CHECK( equals(join_if(empty_tokens, "-", is_not_empty), "") );
|
||||
BOOST_CHECK( equals(join_if(tokens3, "-", is_not_empty), "") );
|
||||
}
|
||||
|
||||
// test main
|
||||
int test_main( int, char*[] )
|
||||
{
|
||||
join_test();
|
||||
|
||||
return 0;
|
||||
}
|
@ -56,6 +56,14 @@ void predicate_test()
|
||||
BOOST_CHECK( iequals( "AbC", "abc" ) );
|
||||
BOOST_CHECK( !iequals( "aBc", "yyy" ) );
|
||||
|
||||
BOOST_CHECK( lexicographical_compare("abc", "abd") );
|
||||
BOOST_CHECK( !lexicographical_compare("abc", "abc") );
|
||||
BOOST_CHECK( lexicographical_compare("abc", "abd", is_less()) );
|
||||
|
||||
BOOST_CHECK( !ilexicographical_compare("aBD", "AbC") );
|
||||
BOOST_CHECK( ilexicographical_compare("aBc", "AbD") );
|
||||
BOOST_CHECK( lexicographical_compare("abC", "aBd", is_iless()) );
|
||||
|
||||
// multi-type comparison test
|
||||
BOOST_CHECK( starts_with( vec1, string("123") ) );
|
||||
BOOST_CHECK( ends_with( vec1, string("321") ) );
|
||||
@ -85,6 +93,7 @@ void predicate_test()
|
||||
BOOST_CHECK( ends_with( "123xxx321", "321" ) );
|
||||
BOOST_CHECK( contains( "123xxx321", "xxx" ) );
|
||||
BOOST_CHECK( equals( "123xxx321", "123xxx321" ) );
|
||||
|
||||
}
|
||||
|
||||
#define TEST_CLASS( Pred, YesInput, NoInput )\
|
||||
|
@ -8,7 +8,11 @@
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/algorithm/string/regex.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string/sequence_traits.hpp>
|
||||
// equals predicate is used for result comparison
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
|
||||
// Include unit test framework
|
||||
#include <boost/test/included/test_exec_monitor.hpp>
|
||||
@ -83,6 +87,23 @@ static void find_test()
|
||||
|
||||
}
|
||||
|
||||
static void join_test()
|
||||
{
|
||||
// Prepare inputs
|
||||
vector<string> tokens1;
|
||||
tokens1.push_back("xx");
|
||||
tokens1.push_back("abc");
|
||||
tokens1.push_back("xx");
|
||||
|
||||
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
BOOST_CHECK( equals(join_if(tokens1, "-", regex("x+")), "xx-xx") );
|
||||
BOOST_CHECK( equals(join_if(tokens1, "-", regex("[abc]+")), "abc") );
|
||||
#else
|
||||
BOOST_CHECK( equals(join_if_regex(tokens1, "-", regex("x+")), "xx-xx") );
|
||||
BOOST_CHECK( equals(join_if_regex(tokens1, "-", regex("[abc]+")), "abc") );
|
||||
#endif
|
||||
}
|
||||
|
||||
static void replace_test()
|
||||
{
|
||||
string str1("123a1cxxxa23cXXXa456c321");
|
||||
@ -131,6 +152,7 @@ static void replace_test()
|
||||
int test_main( int, char*[] )
|
||||
{
|
||||
find_test();
|
||||
join_test();
|
||||
replace_test();
|
||||
|
||||
return 0;
|
||||
|
@ -136,17 +136,27 @@ void replace_nth_test()
|
||||
{
|
||||
// replace nth
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("YYY"), string("1YYY3abc2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ -1 C_ string("YYY"), string("1abc3YYY2") );
|
||||
TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ 0 C_ "YYY", string("1YYY3abc2") );
|
||||
TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ -1 C_ "YYY", string("1AbC3YYY2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("Z"), string("1Z3abc2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("XXXX"), string("1XXXX3abc2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 0 C_ "XXXX", string("1XXXX3abc2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 3 C_ "XXXX", string("1abc3abc2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ -3 C_ "XXXX", string("1abc3abc2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", string("") C_ 0 C_ string("XXXX"), string("1abc3abc2") );
|
||||
TEST_ALGO( replace_nth, "", string("") C_ 0 C_ string("XXXX"), string("") );
|
||||
TEST_ALGO( replace_nth, "", string("") C_ -1 C_ string("XXXX"), string("") );
|
||||
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ 0, string("13abc2") );
|
||||
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -1, string("1abc32") );
|
||||
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ -3, string("1abc3abc2") );
|
||||
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ 0, string("13aBc2") );
|
||||
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -1, string("1aBc32") );
|
||||
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ -3, string("1aBc3aBc2") );
|
||||
TEST_ALGO( erase_nth, "1abc3abc2", "abc" C_ 0, string("13abc2") );
|
||||
TEST_ALGO( erase_nth, "1abc3abc2", string("") C_ 0, string("1abc3abc2") );
|
||||
TEST_ALGO( erase_nth, "", string("abc") C_ 0, string("") );
|
||||
TEST_ALGO( erase_nth, "", string("abc") C_ -1, string("") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 1 C_ string("YYY"), string("1abc3YYY2") );
|
||||
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 2 C_ string("YYY"), string("1abc3abc2") );
|
||||
}
|
||||
@ -155,28 +165,37 @@ void replace_head_test()
|
||||
{
|
||||
// replace head
|
||||
TEST_ALGO( replace_head, "abc3abc2", 3 C_ string("YYY"), string("YYY3abc2") );
|
||||
TEST_ALGO( replace_head, "abc3abc2", -3 C_ string("YYY"), string("YYYbc2") );
|
||||
TEST_ALGO( replace_head, "abc3abc2", 3 C_ "YYY", string("YYY3abc2") );
|
||||
TEST_ALGO( replace_head, "abc", 3 C_ string("Z"), string("Z") );
|
||||
TEST_ALGO( replace_head, "abc", 6 C_ string("XXXX"), string("XXXX") );
|
||||
TEST_ALGO( replace_head, "abc", -6 C_ string("XXXX"), string("abc") );
|
||||
TEST_ALGO( replace_head, "abc3abc2", 0 C_ string("XXXX"), string("abc3abc2") );
|
||||
TEST_ALGO( replace_head, "", 4 C_ string("XXXX"), string("") );
|
||||
TEST_ALGO( replace_head, "", -4 C_ string("XXXX"), string("") );
|
||||
TEST_ALGO( erase_head, "abc3abc2", 3, string("3abc2") );
|
||||
TEST_ALGO( erase_head, "abc3abc2", -3, string("bc2") );
|
||||
TEST_ALGO( erase_head, "abc3abc2", 0, string("abc3abc2") );
|
||||
TEST_ALGO( erase_head, "", 4, string("") );
|
||||
TEST_ALGO( erase_head, "", -4, string("") );
|
||||
}
|
||||
|
||||
void replace_tail_test()
|
||||
{
|
||||
// replace tail
|
||||
TEST_ALGO( replace_tail, "abc3abc", 3 C_ string("YYY"), string("abc3YYY") );
|
||||
TEST_ALGO( replace_tail, "abc3abc", 3 C_ "YYY", string("abc3YYY") );
|
||||
TEST_ALGO( replace_tail, "abc3abc", -3 C_ "YYY", string("abcYYY") );
|
||||
TEST_ALGO( replace_tail, "abc", 3 C_ string("Z"), string("Z") );
|
||||
TEST_ALGO( replace_tail, "abc", 6 C_ string("XXXX"), string("XXXX") );
|
||||
TEST_ALGO( replace_tail, "abc", -6 C_ string("XXXX"), string("abc") );
|
||||
TEST_ALGO( replace_tail, "abc3abc", 0 C_ string("XXXX"), string("abc3abc") );
|
||||
TEST_ALGO( replace_tail, "", 4 C_ string("XXXX"), string("") );
|
||||
TEST_ALGO( replace_tail, "", -4 C_ string("XXXX"), string("") );
|
||||
TEST_ALGO( erase_tail, "abc3abc", 3, string("abc3") );
|
||||
TEST_ALGO( erase_tail, "abc3abc", -3, string("abc") );
|
||||
TEST_ALGO( erase_tail, "abc3abc", 0, string("abc3abc") );
|
||||
TEST_ALGO( erase_tail, "", 4, string("") );
|
||||
TEST_ALGO( erase_tail, "", -4, string("") );
|
||||
}
|
||||
|
||||
void replace_range_test()
|
||||
|
Reference in New Issue
Block a user