forked from boostorg/algorithm
Compare commits
6 Commits
boost-1.42
...
boost-1.44
Author | SHA1 | Date | |
---|---|---|---|
f6c5cd6d2b | |||
bbd3220a1e | |||
9068069106 | |||
a37af3c81e | |||
f5885c6fb0 | |||
d45bb3545e |
@ -31,7 +31,7 @@ namespace boost {
|
|||||||
struct to_lowerF : public std::unary_function<CharT, CharT>
|
struct to_lowerF : public std::unary_function<CharT, CharT>
|
||||||
{
|
{
|
||||||
// Constructor
|
// Constructor
|
||||||
to_lowerF( const std::locale& Loc ) : m_Loc( Loc ) {}
|
to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {}
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
CharT operator ()( CharT Ch ) const
|
CharT operator ()( CharT Ch ) const
|
||||||
@ -39,11 +39,11 @@ namespace boost {
|
|||||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||||
return std::tolower( Ch);
|
return std::tolower( Ch);
|
||||||
#else
|
#else
|
||||||
return std::tolower<CharT>( Ch, m_Loc );
|
return std::tolower<CharT>( Ch, *m_Loc );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
const std::locale& m_Loc;
|
const std::locale* m_Loc;
|
||||||
};
|
};
|
||||||
|
|
||||||
// a toupper functor
|
// a toupper functor
|
||||||
@ -51,7 +51,7 @@ namespace boost {
|
|||||||
struct to_upperF : public std::unary_function<CharT, CharT>
|
struct to_upperF : public std::unary_function<CharT, CharT>
|
||||||
{
|
{
|
||||||
// Constructor
|
// Constructor
|
||||||
to_upperF( const std::locale& Loc ) : m_Loc( Loc ) {}
|
to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {}
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
CharT operator ()( CharT Ch ) const
|
CharT operator ()( CharT Ch ) const
|
||||||
@ -59,11 +59,11 @@ namespace boost {
|
|||||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||||
return std::toupper( Ch);
|
return std::toupper( Ch);
|
||||||
#else
|
#else
|
||||||
return std::toupper<CharT>( Ch, m_Loc );
|
return std::toupper<CharT>( Ch, *m_Loc );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
const std::locale& m_Loc;
|
const std::locale* m_Loc;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||||
|
@ -32,8 +32,8 @@ namespace boost {
|
|||||||
struct is_classifiedF :
|
struct is_classifiedF :
|
||||||
public predicate_facade<is_classifiedF>
|
public predicate_facade<is_classifiedF>
|
||||||
{
|
{
|
||||||
// Boost.Lambda support
|
// Boost.ResultOf support
|
||||||
template <class Args> struct sig { typedef bool type; };
|
typedef bool result_type;
|
||||||
|
|
||||||
// Constructor from a locale
|
// Constructor from a locale
|
||||||
is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) :
|
is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) :
|
||||||
@ -72,8 +72,8 @@ namespace boost {
|
|||||||
typedef typename ::boost::remove_const<CharT>::type set_value_type;
|
typedef typename ::boost::remove_const<CharT>::type set_value_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Boost.Lambda support
|
// Boost.ResultOf support
|
||||||
template <class Args> struct sig { typedef bool type; };
|
typedef bool result_type;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
template<typename RangeT>
|
template<typename RangeT>
|
||||||
@ -253,8 +253,8 @@ namespace boost {
|
|||||||
struct is_from_rangeF :
|
struct is_from_rangeF :
|
||||||
public predicate_facade< is_from_rangeF<CharT> >
|
public predicate_facade< is_from_rangeF<CharT> >
|
||||||
{
|
{
|
||||||
// Boost.Lambda support
|
// Boost.ResultOf support
|
||||||
template <class Args> struct sig { typedef bool type; };
|
typedef bool result_type;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
is_from_rangeF( CharT From, CharT To ) : m_From(From), m_To(To) {}
|
is_from_rangeF( CharT From, CharT To ) : m_From(From), m_To(To) {}
|
||||||
@ -278,8 +278,8 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Boost.Lambda support
|
// Boost.ResultOf support
|
||||||
template <class Args> struct sig { typedef bool type; };
|
typedef bool result_type;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
pred_andF( Pred1T Pred1, Pred2T Pred2 ) :
|
pred_andF( Pred1T Pred1, Pred2T Pred2 ) :
|
||||||
@ -303,8 +303,8 @@ namespace boost {
|
|||||||
public predicate_facade< pred_orF<Pred1T,Pred2T> >
|
public predicate_facade< pred_orF<Pred1T,Pred2T> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Boost.Lambda support
|
// Boost.ResultOf support
|
||||||
template <class Args> struct sig { typedef bool type; };
|
typedef bool result_type;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
pred_orF( Pred1T Pred1, Pred2T Pred2 ) :
|
pred_orF( Pred1T Pred1, Pred2T Pred2 ) :
|
||||||
@ -328,8 +328,8 @@ namespace boost {
|
|||||||
public predicate_facade< pred_notF<PredT> >
|
public predicate_facade< pred_notF<PredT> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Boost.Lambda support
|
// Boost.ResultOf support
|
||||||
template <class Args> struct sig { typedef bool type; };
|
typedef bool result_type;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
pred_notF( PredT Pred ) : m_Pred(Pred) {}
|
pred_notF( PredT Pred ) : m_Pred(Pred) {}
|
||||||
|
@ -49,17 +49,17 @@ namespace boost {
|
|||||||
if ( !M )
|
if ( !M )
|
||||||
{
|
{
|
||||||
// Match not found - return original sequence
|
// Match not found - return original sequence
|
||||||
std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
Output = std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
||||||
return Output;
|
return Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the beginning of the sequence
|
// Copy the beginning of the sequence
|
||||||
std::copy( ::boost::begin(Input), ::boost::begin(M), Output );
|
Output = std::copy( ::boost::begin(Input), ::boost::begin(M), Output );
|
||||||
// Format find result
|
// Format find result
|
||||||
// Copy formated result
|
// Copy formated result
|
||||||
std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
|
Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
|
||||||
// Copy the rest of the sequence
|
// Copy the rest of the sequence
|
||||||
std::copy( M.end(), ::boost::end(Input), Output );
|
Output = std::copy( M.end(), ::boost::end(Input), Output );
|
||||||
|
|
||||||
return Output;
|
return Output;
|
||||||
}
|
}
|
||||||
@ -75,12 +75,16 @@ namespace boost {
|
|||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
const FindResultT& FindResult )
|
const FindResultT& FindResult )
|
||||||
{
|
{
|
||||||
|
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||||
return ::boost::algorithm::detail::find_format_copy_impl2(
|
return ::boost::algorithm::detail::find_format_copy_impl2(
|
||||||
Output,
|
Output,
|
||||||
Input,
|
Input,
|
||||||
Formatter,
|
Formatter,
|
||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
|
} else {
|
||||||
|
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -132,11 +136,15 @@ namespace boost {
|
|||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
const FindResultT& FindResult)
|
const FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
|
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||||
return ::boost::algorithm::detail::find_format_copy_impl2(
|
return ::boost::algorithm::detail::find_format_copy_impl2(
|
||||||
Input,
|
Input,
|
||||||
Formatter,
|
Formatter,
|
||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
|
} else {
|
||||||
|
return Input;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace implementation ----------------------------------------------------//
|
// replace implementation ----------------------------------------------------//
|
||||||
@ -180,12 +188,14 @@ namespace boost {
|
|||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
const FindResultT& FindResult)
|
const FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
|
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||||
::boost::algorithm::detail::find_format_impl2(
|
::boost::algorithm::detail::find_format_impl2(
|
||||||
Input,
|
Input,
|
||||||
Formatter,
|
Formatter,
|
||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace algorithm
|
} // namespace algorithm
|
||||||
|
@ -57,9 +57,9 @@ namespace boost {
|
|||||||
while( M )
|
while( M )
|
||||||
{
|
{
|
||||||
// Copy the beginning of the sequence
|
// Copy the beginning of the sequence
|
||||||
std::copy( LastMatch, M.begin(), Output );
|
Output = std::copy( LastMatch, M.begin(), Output );
|
||||||
// Copy formated result
|
// Copy formated result
|
||||||
std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
|
Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
|
||||||
|
|
||||||
// Proceed to the next match
|
// Proceed to the next match
|
||||||
LastMatch=M.end();
|
LastMatch=M.end();
|
||||||
@ -67,7 +67,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the rest of the sequence
|
// Copy the rest of the sequence
|
||||||
std::copy( LastMatch, ::boost::end(Input), Output );
|
Output = std::copy( LastMatch, ::boost::end(Input), Output );
|
||||||
|
|
||||||
return Output;
|
return Output;
|
||||||
}
|
}
|
||||||
@ -85,6 +85,7 @@ namespace boost {
|
|||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
const FindResultT& FindResult )
|
const FindResultT& FindResult )
|
||||||
{
|
{
|
||||||
|
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||||
return ::boost::algorithm::detail::find_format_all_copy_impl2(
|
return ::boost::algorithm::detail::find_format_all_copy_impl2(
|
||||||
Output,
|
Output,
|
||||||
Input,
|
Input,
|
||||||
@ -92,6 +93,9 @@ namespace boost {
|
|||||||
Formatter,
|
Formatter,
|
||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
|
} else {
|
||||||
|
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find_format_all_copy implementation ----------------------------------------------//
|
// find_format_all_copy implementation ----------------------------------------------//
|
||||||
@ -156,12 +160,16 @@ namespace boost {
|
|||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
const FindResultT& FindResult)
|
const FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
|
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||||
return ::boost::algorithm::detail::find_format_all_copy_impl2(
|
return ::boost::algorithm::detail::find_format_all_copy_impl2(
|
||||||
Input,
|
Input,
|
||||||
Finder,
|
Finder,
|
||||||
Formatter,
|
Formatter,
|
||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
|
} else {
|
||||||
|
return Input;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find_format_all implementation ------------------------------------------------//
|
// find_format_all implementation ------------------------------------------------//
|
||||||
@ -248,6 +256,7 @@ namespace boost {
|
|||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
FindResultT FindResult)
|
FindResultT FindResult)
|
||||||
{
|
{
|
||||||
|
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||||
::boost::algorithm::detail::find_format_all_impl2(
|
::boost::algorithm::detail::find_format_all_impl2(
|
||||||
Input,
|
Input,
|
||||||
Finder,
|
Finder,
|
||||||
@ -255,6 +264,7 @@ namespace boost {
|
|||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace algorithm
|
} // namespace algorithm
|
||||||
|
@ -52,7 +52,9 @@ namespace boost {
|
|||||||
find_format_store& operator=( FindResultT FindResult )
|
find_format_store& operator=( FindResultT FindResult )
|
||||||
{
|
{
|
||||||
iterator_range<ForwardIteratorT>::operator=(FindResult);
|
iterator_range<ForwardIteratorT>::operator=(FindResult);
|
||||||
|
if( !this->empty() ) {
|
||||||
m_FormatResult=m_Formatter(FindResult);
|
m_FormatResult=m_Formatter(FindResult);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -68,6 +70,15 @@ namespace boost {
|
|||||||
const formatter_type& m_Formatter;
|
const formatter_type& m_Formatter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename InputT, typename FindResultT>
|
||||||
|
bool check_find_result(InputT& Input, FindResultT& FindResult)
|
||||||
|
{
|
||||||
|
typedef BOOST_STRING_TYPENAME
|
||||||
|
range_const_iterator<InputT>::type input_iterator_type;
|
||||||
|
iterator_range<input_iterator_type> ResultRange(FindResult);
|
||||||
|
return !ResultRange.empty();
|
||||||
|
}
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
@ -752,7 +752,7 @@ namespace boost {
|
|||||||
|
|
||||||
\param Output An output iterator to which the result will be copied
|
\param Output An output iterator to which the result will be copied
|
||||||
\param Input An input string
|
\param Input An input string
|
||||||
\param N Length of the head.
|
\param N Length of the tail.
|
||||||
For N>=0, at most N characters are extracted.
|
For N>=0, at most N characters are extracted.
|
||||||
For N<0, size(Input)-|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
|
\return An output iterator pointing just after the last inserted character or
|
||||||
@ -797,7 +797,7 @@ namespace boost {
|
|||||||
considered to be the tail. The input sequence is modified in-place.
|
considered to be the tail. The input sequence is modified in-place.
|
||||||
|
|
||||||
\param Input An input string
|
\param Input An input string
|
||||||
\param N Length of the head
|
\param N Length of the tail
|
||||||
For N>=0, at most N characters are extracted.
|
For N>=0, at most N characters are extracted.
|
||||||
For N<0, size(Input)-|N| characters are extracted.
|
For N<0, size(Input)-|N| characters are extracted.
|
||||||
*/
|
*/
|
||||||
|
@ -257,7 +257,7 @@ namespace boost {
|
|||||||
|
|
||||||
//! Find tail algorithm
|
//! Find tail algorithm
|
||||||
/*!
|
/*!
|
||||||
Get the head of the input. Head is a suffix of the string of the
|
Get the tail of the input. Tail is a suffix of the string of the
|
||||||
given size. If the input is shorter then required, whole input if considered
|
given size. If the input is shorter then required, whole input if considered
|
||||||
to be the tail.
|
to be the tail.
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ namespace boost {
|
|||||||
m_Match(Other.m_Match),
|
m_Match(Other.m_Match),
|
||||||
m_Next(Other.m_Next),
|
m_Next(Other.m_Next),
|
||||||
m_End(Other.m_End),
|
m_End(Other.m_End),
|
||||||
m_bEof(false)
|
m_bEof(Other.m_bEof)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
|
@ -92,11 +92,11 @@ Synopsis of <tt><boost/algorithm/minmax.hpp></tt></h3>
|
|||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
tuple<T const&, T const&> >
|
tuple<T const&, T const&>
|
||||||
minmax(const T& a, const T& b);
|
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&> >
|
tuple<T const&, T const&>
|
||||||
minmax(const T& a, const T& b, BinaryPredicate comp);
|
minmax(const T& a, const T& b, BinaryPredicate comp);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ range
|
|||||||
|
|
||||||
<a name="complexity">
|
<a name="complexity">
|
||||||
<h3>
|
<h3>
|
||||||
<a NAME="Complexity"></a>Complexity</h3>
|
Complexity</h3>
|
||||||
Minmax performs a single comparison and is otherwise of constant complexity.
|
Minmax performs a single comparison and is otherwise of constant complexity.
|
||||||
The use of <tt>boost::tuple<T const&></tt> prevents copy
|
The use of <tt>boost::tuple<T const&></tt> prevents copy
|
||||||
constructors in case the arguments are passed by reference.
|
constructors in case the arguments are passed by reference.
|
||||||
@ -438,7 +438,7 @@ comparisons).</p>
|
|||||||
slower than
|
slower than
|
||||||
<tt>first_min_element</tt> alone, still much less than <tt>first_min_element</tt>
|
<tt>first_min_element</tt> alone, still much less than <tt>first_min_element</tt>
|
||||||
and
|
and
|
||||||
<tt>last_max_element</tt> called separately. <a href="#Performance">[2]</a>
|
<tt>last_max_element</tt> called separately. <a href="#Note2">[2]</a>
|
||||||
|
|
||||||
<h4><b>Why algorithms and not accumulators?</b></h4>
|
<h4><b>Why algorithms and not accumulators?</b></h4>
|
||||||
<p>The minmax algorithms are useful in computing the extent of a range.
|
<p>The minmax algorithms are useful in computing the extent of a range.
|
||||||
|
@ -12,6 +12,7 @@ toolset.using doxygen ;
|
|||||||
|
|
||||||
boostbook string_algo : string_algo.xml autodoc
|
boostbook string_algo : string_algo.xml autodoc
|
||||||
:
|
:
|
||||||
|
<xsl:param>boost.root=../../../../..
|
||||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<emphasis role="bold">Definition:</emphasis> A string is a
|
<emphasis role="bold">Definition:</emphasis> A string is a
|
||||||
<ulink url="../../libs/range/doc/range.html">range</ulink> of characters accessible in sequential
|
<ulink url="../../libs/range/index.html">range</ulink> of characters accessible in sequential
|
||||||
ordered fashion. Character is any value type with "cheap" copying and assignment.
|
ordered fashion. Character is any value type with "cheap" copying and assignment.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
|
@ -32,7 +32,9 @@
|
|||||||
free-standing functions and type-generators exists:</p><code>void foo( const T&, int ); <br>
|
free-standing functions and type-generators exists:</p><code>void foo( const T&, int ); <br>
|
||||||
int bar( T& ); <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).
|
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
|
<br>Use, modification and distribution is subject to the Boost
|
||||||
in all copies. This software is provided "as is" without express or implied warranty, and with no
|
Software License, Version 1.0. (See accompanying file
|
||||||
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>
|
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||||
<!-- Copyright Dezide Aps 2003-2004 -->
|
</br>
|
||||||
|
</p>
|
||||||
|
<!-- Copyright Dezide Aps 2003-2004 -->
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
<librarypurpose>
|
<librarypurpose>
|
||||||
A set of generic string-related algorithms and utilities
|
A set of generic string-related algorithms and utilities
|
||||||
</librarypurpose>
|
</librarypurpose>
|
||||||
<librarycategory name="category:algoritms"/>
|
<librarycategory name="category:algorithms"/>
|
||||||
<librarycategory name="category:string-text"/>
|
<librarycategory name="category:string-text"/>
|
||||||
</libraryinfo>
|
</libraryinfo>
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
The magic of <ulink url="../../libs/range/index.html">Boost.Range</ulink>
|
The magic of <ulink url="../../libs/range/index.html">Boost.Range</ulink>
|
||||||
provides a uniform way of handling different string types.
|
provides a uniform way of handling different string types.
|
||||||
If there is a need to pass a pair of iterators,
|
If there is a need to pass a pair of iterators,
|
||||||
<ulink url="../../libs/range/doc/utility_class.html"><code>boost::iterator_range</code></ulink>
|
<ulink url="../../libs/range/doc/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink>
|
||||||
can be used to package iterators into a structure with a compatible interface.
|
can be used to package iterators into a structure with a compatible interface.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -169,7 +169,7 @@
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
string str1=" hello world! ";
|
string str1=" hello world! ";
|
||||||
string str2=trim_left_copy(str1); // str2 == "hello world! "
|
string str2=trim_left_copy(str1); // str2 == "hello world! "
|
||||||
string str3=trim_right_copy(str2); // str3 == " hello world!"
|
string str3=trim_right_copy(str1); // str3 == " hello world!"
|
||||||
trim(str1); // str1 == "hello world!"
|
trim(str1); // str1 == "hello world!"
|
||||||
|
|
||||||
string phone="00423333444";
|
string phone="00423333444";
|
||||||
@ -208,7 +208,7 @@
|
|||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
We have used <functionname>find_last()</functionname> to search the <code>text</code> for "ll".
|
We have used <functionname>find_last()</functionname> to search the <code>text</code> for "ll".
|
||||||
The result is given in the <ulink url="../../libs/range/doc/utility_class.html"><code>boost::iterator_range</code></ulink>.
|
The result is given in the <ulink url="../../libs/range/doc/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink>.
|
||||||
This range delimits the
|
This range delimits the
|
||||||
part of the input which satisfies the find criteria. In our example it is the last occurrence of "ll".
|
part of the input which satisfies the find criteria. In our example it is the last occurrence of "ll".
|
||||||
|
|
||||||
@ -217,7 +217,7 @@
|
|||||||
<ulink url="../../libs/range/index.html">Boost.Range</ulink>.
|
<ulink url="../../libs/range/index.html">Boost.Range</ulink>.
|
||||||
|
|
||||||
The following lines transform the result. Notice that
|
The following lines transform the result. Notice that
|
||||||
<ulink url="../../libs/range/doc/utility_class.html"><code>boost::iterator_range</code></ulink> has familiar
|
<ulink url="../../libs/range/doc/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink> has familiar
|
||||||
<code>begin()</code> and <code>end()</code> methods, so it can be used like any other STL container.
|
<code>begin()</code> and <code>end()</code> methods, so it can be used like any other STL container.
|
||||||
Also it is convertible to bool therefore it is easy to use find algorithms for a simple containment checking.
|
Also it is convertible to bool therefore it is easy to use find algorithms for a simple containment checking.
|
||||||
</para>
|
</para>
|
||||||
@ -264,7 +264,7 @@
|
|||||||
the find iterator allows us to iterate over the substrings matching the specified criteria.
|
the find iterator allows us to iterate over the substrings matching the specified criteria.
|
||||||
This facility is using the <link linkend="string_algo.finder_concept">Finder</link> to incrementally
|
This facility is using the <link linkend="string_algo.finder_concept">Finder</link> to incrementally
|
||||||
search the string.
|
search the string.
|
||||||
Dereferencing a find iterator yields an <ulink url="../../libs/range/doc/utility_class.html"><code>boost::iterator_range</code></ulink>
|
Dereferencing a find iterator yields an <ulink url="../../libs/range/doc/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink>
|
||||||
object, that delimits the current match.
|
object, that delimits the current match.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
@ -339,7 +339,7 @@
|
|||||||
typedef vector< string > split_vector_type;
|
typedef vector< string > split_vector_type;
|
||||||
|
|
||||||
split_vector_type SplitVec; // #2: Search for tokens
|
split_vector_type SplitVec; // #2: Search for tokens
|
||||||
split( SplitVec, str1, is_any_of("-*") ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
|
split( SplitVec, str1, is_any_of("-*"), token_compress_on ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>
|
<para>
|
||||||
<code>[hello]</code> designates an <code>iterator_range</code> delimiting this substring.
|
<code>[hello]</code> designates an <code>iterator_range</code> delimiting this substring.
|
||||||
|
@ -59,5 +59,11 @@ test-suite algorithm/string
|
|||||||
:
|
:
|
||||||
: regex
|
: regex
|
||||||
]
|
]
|
||||||
|
[ run
|
||||||
|
find_format_test.cpp
|
||||||
|
: :
|
||||||
|
:
|
||||||
|
: find_format
|
||||||
|
]
|
||||||
;
|
;
|
||||||
|
|
||||||
|
163
string/test/find_format_test.cpp
Normal file
163
string/test/find_format_test.cpp
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
// Boost string_algo library find_format_test.cpp file ------------------//
|
||||||
|
|
||||||
|
// Copyright (c) 2009 Steven Watanabe
|
||||||
|
// Distributed under 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/find_format.hpp>
|
||||||
|
#include <boost/algorithm/string/finder.hpp>
|
||||||
|
#include <boost/algorithm/string/formatter.hpp>
|
||||||
|
|
||||||
|
// Include unit test framework
|
||||||
|
#include <boost/test/included/test_exec_monitor.hpp>
|
||||||
|
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
// We're only using const_formatter.
|
||||||
|
template<class Formatter>
|
||||||
|
struct formatter_result {
|
||||||
|
typedef boost::iterator_range<const char*> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class Formatter>
|
||||||
|
struct checked_formatter {
|
||||||
|
public:
|
||||||
|
checked_formatter(const Formatter& formatter) : formatter_(formatter) {}
|
||||||
|
template< typename T >
|
||||||
|
typename formatter_result<Formatter>::type operator()( const T & s ) const {
|
||||||
|
BOOST_CHECK( !s.empty() );
|
||||||
|
return formatter_(s);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Formatter formatter_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class Formatter>
|
||||||
|
checked_formatter<Formatter>
|
||||||
|
make_checked_formatter(const Formatter& formatter) {
|
||||||
|
return checked_formatter<Formatter>(formatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void find_format_test()
|
||||||
|
{
|
||||||
|
const std::string source = "$replace $replace";
|
||||||
|
std::string expected = "ok $replace";
|
||||||
|
std::string output(80, '\0');
|
||||||
|
|
||||||
|
std::string::iterator pos =
|
||||||
|
boost::find_format_copy(
|
||||||
|
output.begin(),
|
||||||
|
source,
|
||||||
|
boost::first_finder("$replace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("ok")));
|
||||||
|
BOOST_CHECK(pos == output.begin() + expected.size());
|
||||||
|
output.erase(std::remove(output.begin(), output.end(), '\0'), output.end());
|
||||||
|
BOOST_CHECK_EQUAL(output, expected);
|
||||||
|
|
||||||
|
output =
|
||||||
|
boost::find_format_copy(
|
||||||
|
source,
|
||||||
|
boost::first_finder("$replace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("ok")));
|
||||||
|
BOOST_CHECK_EQUAL(output, expected);
|
||||||
|
|
||||||
|
// now try finding a string that doesn't exist
|
||||||
|
output.resize(80);
|
||||||
|
pos =
|
||||||
|
boost::find_format_copy(
|
||||||
|
output.begin(),
|
||||||
|
source,
|
||||||
|
boost::first_finder("$noreplace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("bad")));
|
||||||
|
BOOST_CHECK(pos == output.begin() + source.size());
|
||||||
|
output.erase(std::remove(output.begin(), output.end(), '\0'), output.end());
|
||||||
|
BOOST_CHECK_EQUAL(output, source);
|
||||||
|
|
||||||
|
output =
|
||||||
|
boost::find_format_copy(
|
||||||
|
source,
|
||||||
|
boost::first_finder("$noreplace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("bad")));
|
||||||
|
BOOST_CHECK_EQUAL(output, source);
|
||||||
|
|
||||||
|
// in place version
|
||||||
|
output = source;
|
||||||
|
boost::find_format(
|
||||||
|
output,
|
||||||
|
boost::first_finder("$replace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("ok")));
|
||||||
|
BOOST_CHECK_EQUAL(output, expected);
|
||||||
|
output = source;
|
||||||
|
boost::find_format(
|
||||||
|
output,
|
||||||
|
boost::first_finder("$noreplace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("bad")));
|
||||||
|
BOOST_CHECK_EQUAL(output, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
void find_format_all_test()
|
||||||
|
{
|
||||||
|
const std::string source = "$replace $replace";
|
||||||
|
std::string expected = "ok ok";
|
||||||
|
std::string output(80, '\0');
|
||||||
|
|
||||||
|
std::string::iterator pos =
|
||||||
|
boost::find_format_all_copy(output.begin(),
|
||||||
|
source,
|
||||||
|
boost::first_finder("$replace"),
|
||||||
|
boost::const_formatter("ok"));
|
||||||
|
BOOST_CHECK(pos == output.begin() + expected.size());
|
||||||
|
output.erase(std::remove(output.begin(), output.end(), '\0'), output.end());
|
||||||
|
BOOST_CHECK_EQUAL(output, expected);
|
||||||
|
|
||||||
|
output =
|
||||||
|
boost::find_format_all_copy(
|
||||||
|
source,
|
||||||
|
boost::first_finder("$replace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("ok")));
|
||||||
|
BOOST_CHECK_EQUAL(output, expected);
|
||||||
|
|
||||||
|
// now try finding a string that doesn't exist
|
||||||
|
output.resize(80);
|
||||||
|
pos =
|
||||||
|
boost::find_format_all_copy(
|
||||||
|
output.begin(),
|
||||||
|
source,
|
||||||
|
boost::first_finder("$noreplace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("bad")));
|
||||||
|
BOOST_CHECK(pos == output.begin() + source.size());
|
||||||
|
output.erase(std::remove(output.begin(), output.end(), '\0'), output.end());
|
||||||
|
BOOST_CHECK_EQUAL(output, source);
|
||||||
|
|
||||||
|
output =
|
||||||
|
boost::find_format_all_copy(
|
||||||
|
source,
|
||||||
|
boost::first_finder("$noreplace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("bad")));
|
||||||
|
BOOST_CHECK_EQUAL(output, source);
|
||||||
|
|
||||||
|
// in place version
|
||||||
|
output = source;
|
||||||
|
boost::find_format_all(
|
||||||
|
output,
|
||||||
|
boost::first_finder("$replace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("ok")));
|
||||||
|
BOOST_CHECK_EQUAL(output, expected);
|
||||||
|
output = source;
|
||||||
|
boost::find_format_all(
|
||||||
|
output,
|
||||||
|
boost::first_finder("$noreplace"),
|
||||||
|
make_checked_formatter(boost::const_formatter("bad")));
|
||||||
|
BOOST_CHECK_EQUAL(output, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_main( int, char*[] )
|
||||||
|
{
|
||||||
|
find_format_test();
|
||||||
|
find_format_all_test();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -139,6 +139,7 @@ void iterator_test()
|
|||||||
++siter;
|
++siter;
|
||||||
BOOST_CHECK(equals(*siter, "abb"));
|
BOOST_CHECK(equals(*siter, "abb"));
|
||||||
++siter;
|
++siter;
|
||||||
|
BOOST_CHECK(siter==split_iterator<string::iterator>(siter));
|
||||||
BOOST_CHECK(siter==split_iterator<string::iterator>());
|
BOOST_CHECK(siter==split_iterator<string::iterator>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user