Compare commits

...

8 Commits

Author SHA1 Message Date
9535d80b31 Release 1_46_0 beta 1
[SVN r68581]
2011-01-31 13:00:44 +00:00
01492a93c6 trunk changes merged
[SVN r67922]
2011-01-10 19:36:38 +00:00
50703b8c97 Merge documentation fixes to release.
[SVN r66285]
2010-10-30 17:34:45 +00:00
0f8d556130 Merge r65004 from trunk
Fix #4551,#4553,#4575 by removing unused parameter.



[SVN r65168]
2010-09-01 16:18:07 +00:00
bbd3220a1e Merging changes from trunk
[SVN r63824]
2010-07-10 20:29:03 +00:00
9068069106 Spirit: merging from trunk upto rev. 61489
[SVN r63640]
2010-07-04 22:38:38 +00:00
a37af3c81e Merge documentation fixes.
* Use `doc/src/*.css` instead of `doc/html/*.css`.
* Remove wiki and people directories.
* Some documentation fixes.
* Left out `minimal.css` changes and boostbook changes because of clashes.


[SVN r63347]
2010-06-26 12:30:09 +00:00
f5885c6fb0 Merge minmax from the trunk
[SVN r62088]
2010-05-18 17:53:36 +00:00
16 changed files with 316 additions and 84 deletions

View File

@ -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)

View File

@ -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) {}

View File

@ -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;
} }
@ -74,13 +74,17 @@ namespace boost {
const InputT& Input, const InputT& Input,
FormatterT Formatter, FormatterT Formatter,
const FindResultT& FindResult ) const FindResultT& FindResult )
{ {
return ::boost::algorithm::detail::find_format_copy_impl2( if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
Output, return ::boost::algorithm::detail::find_format_copy_impl2(
Input, Output,
Formatter, Input,
FindResult, Formatter,
Formatter(FindResult) ); 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)
{ {
return ::boost::algorithm::detail::find_format_copy_impl2( if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
Input, return ::boost::algorithm::detail::find_format_copy_impl2(
Formatter, Input,
FindResult, Formatter,
Formatter(FindResult) ); FindResult,
Formatter(FindResult) );
} else {
return Input;
}
} }
// replace implementation ----------------------------------------------------// // replace implementation ----------------------------------------------------//
@ -180,11 +188,13 @@ namespace boost {
FormatterT Formatter, FormatterT Formatter,
const FindResultT& FindResult) const FindResultT& FindResult)
{ {
::boost::algorithm::detail::find_format_impl2( if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
Input, ::boost::algorithm::detail::find_format_impl2(
Formatter, Input,
FindResult, Formatter,
Formatter(FindResult) ); FindResult,
Formatter(FindResult) );
}
} }
} // namespace detail } // namespace detail

View File

@ -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;
} }
@ -84,14 +84,18 @@ namespace boost {
FinderT Finder, FinderT Finder,
FormatterT Formatter, FormatterT Formatter,
const FindResultT& FindResult ) const FindResultT& FindResult )
{ {
return ::boost::algorithm::detail::find_format_all_copy_impl2( if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
Output, return ::boost::algorithm::detail::find_format_all_copy_impl2(
Input, Output,
Finder, Input,
Formatter, Finder,
FindResult, Formatter,
Formatter(FindResult) ); 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)
{ {
return ::boost::algorithm::detail::find_format_all_copy_impl2( if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
Input, return ::boost::algorithm::detail::find_format_all_copy_impl2(
Finder, Input,
Formatter, Finder,
FindResult, Formatter,
Formatter(FindResult) ); FindResult,
Formatter(FindResult) );
} else {
return Input;
}
} }
// find_format_all implementation ------------------------------------------------// // find_format_all implementation ------------------------------------------------//
@ -248,12 +256,14 @@ namespace boost {
FormatterT Formatter, FormatterT Formatter,
FindResultT FindResult) FindResultT FindResult)
{ {
::boost::algorithm::detail::find_format_all_impl2( if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
Input, ::boost::algorithm::detail::find_format_all_impl2(
Finder, Input,
Formatter, Finder,
FindResult, Formatter,
Formatter(FindResult) ); FindResult,
Formatter(FindResult) );
}
} }
} // namespace detail } // namespace detail

View File

@ -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);
m_FormatResult=m_Formatter(FindResult); if( !this->empty() ) {
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&, 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

View File

@ -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.
*/ */

View File

@ -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.

View File

@ -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
@ -259,7 +259,11 @@ namespace boost {
m_End(End), m_End(End),
m_bEof(false) m_bEof(false)
{ {
increment(); // force the correct behavior for empty sequences and yield at least one token
if(Begin!=End)
{
increment();
}
} }
//! Constructor //! Constructor
/*! /*!
@ -278,7 +282,11 @@ namespace boost {
m_Next=::boost::begin(lit_col); m_Next=::boost::begin(lit_col);
m_End=::boost::end(lit_col); m_End=::boost::end(lit_col);
increment(); // force the correct behavior for empty sequences and yield at least one token
if(m_Next!=m_End)
{
increment();
}
} }

View File

@ -92,11 +92,11 @@ Synopsis of <tt>&lt;boost/algorithm/minmax.hpp></tt></h3>
namespace boost { namespace boost {
template &lt;class T> template &lt;class T>
tuple&lt;T const&amp;, T const&amp;> > tuple&lt;T const&amp;, T const&amp;>
minmax(const T&amp; a, const T&amp; b); minmax(const T&amp; a, const T&amp; b);
template &lt;class T, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>> template &lt;class T, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
tuple&lt;T const&amp;, T const&amp;> > tuple&lt;T const&amp;, T const&amp;>
minmax(const T&amp; a, const T&amp; b, BinaryPredicate comp); minmax(const T&amp; a, const T&amp; 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&lt;T const&amp;></tt> prevents copy The use of <tt>boost::tuple&lt;T const&amp;></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.

View File

@ -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
; ;

View File

@ -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 >&copy; 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 >&copy; 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 -->

View File

@ -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>

View File

@ -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/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink> <ulink url="../../libs/range/doc/html/range/reference/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/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink>. The result is given in the <ulink url="../../libs/range/doc/html/range/reference/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/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink> has familiar <ulink url="../../libs/range/doc/html/range/reference/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/html/range/utilities/iterator_range.html"><code>boost::iterator_range</code></ulink> Dereferencing a find iterator yields an <ulink url="../../libs/range/doc/html/range/reference/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&lt; string &gt; split_vector_type; typedef vector&lt; string &gt; 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.

View File

@ -59,5 +59,11 @@ test-suite algorithm/string
: :
: regex : regex
] ]
[ run
find_format_test.cpp
: :
:
: find_format
]
; ;

View 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;
}

View File

@ -40,6 +40,7 @@ void iterator_test()
string str1("xx-abc--xx-abb"); string str1("xx-abc--xx-abb");
string str2("Xx-abc--xX-abb-xx"); string str2("Xx-abc--xX-abb-xx");
string str3("xx"); string str3("xx");
string strempty("");
const char* pch1="xx-abc--xx-abb"; const char* pch1="xx-abc--xx-abb";
vector<string> tokens; vector<string> tokens;
vector< vector<int> > vtokens; vector< vector<int> > vtokens;
@ -123,6 +124,25 @@ void iterator_test()
BOOST_CHECK( tokens[3]==string("xx") ); BOOST_CHECK( tokens[3]==string("xx") );
BOOST_CHECK( tokens[4]==string("abb") ); BOOST_CHECK( tokens[4]==string("abb") );
split(
tokens,
str3,
is_any_of(","),
token_compress_off);
BOOST_REQUIRE( tokens.size()==1 );
BOOST_CHECK( tokens[0]==string("xx") );
split(
tokens,
strempty,
is_punct(),
token_compress_off);
BOOST_REQUIRE( tokens.size()==1 );
BOOST_CHECK( tokens[0]==string("") );
find_iterator<string::iterator> fiter=make_find_iterator(str1, first_finder("xx")); find_iterator<string::iterator> fiter=make_find_iterator(str1, first_finder("xx"));
BOOST_CHECK(equals(*fiter, "xx")); BOOST_CHECK(equals(*fiter, "xx"));
++fiter; ++fiter;
@ -139,6 +159,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>());
} }