mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-25 20:11:50 +02:00
Compare commits
36 Commits
svn-branch
...
boost-1.44
Author | SHA1 | Date | |
---|---|---|---|
f6c5cd6d2b | |||
bbd3220a1e | |||
9068069106 | |||
a37af3c81e | |||
f5885c6fb0 | |||
d45bb3545e | |||
d735b9fa1e | |||
62ec675581 | |||
e7cd4da67b | |||
6076f5a18e | |||
60cd5a0500 | |||
c33dad924d | |||
2f2935f07e | |||
3cbaafc27f | |||
c067b348bf | |||
c33935fa1f | |||
98a8b08afb | |||
fc0f3dcffc | |||
822636418b | |||
352e16aade | |||
89c76ea1bb | |||
50b5726a6f | |||
d4b95734dd | |||
05af96f84c | |||
5bdbb2b308 | |||
1a02969303 | |||
6309379618 | |||
37581bac55 | |||
a71a4ed5b1 | |||
c509c3fbad | |||
d8683f2498 | |||
7c0101aa51 | |||
6f3e85528f | |||
8af639b7cf | |||
d9bc7e800b | |||
b4ed9beb90 |
@ -31,7 +31,7 @@ namespace boost {
|
||||
struct to_lowerF : public std::unary_function<CharT, CharT>
|
||||
{
|
||||
// Constructor
|
||||
to_lowerF( const std::locale& Loc ) : m_Loc( Loc ) {}
|
||||
to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {}
|
||||
|
||||
// Operation
|
||||
CharT operator ()( CharT Ch ) const
|
||||
@ -39,11 +39,11 @@ namespace boost {
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::tolower( Ch);
|
||||
#else
|
||||
return std::tolower<CharT>( Ch, m_Loc );
|
||||
return std::tolower<CharT>( Ch, *m_Loc );
|
||||
#endif
|
||||
}
|
||||
private:
|
||||
const std::locale& m_Loc;
|
||||
const std::locale* m_Loc;
|
||||
};
|
||||
|
||||
// a toupper functor
|
||||
@ -51,7 +51,7 @@ namespace boost {
|
||||
struct to_upperF : public std::unary_function<CharT, CharT>
|
||||
{
|
||||
// Constructor
|
||||
to_upperF( const std::locale& Loc ) : m_Loc( Loc ) {}
|
||||
to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {}
|
||||
|
||||
// Operation
|
||||
CharT operator ()( CharT Ch ) const
|
||||
@ -59,11 +59,11 @@ namespace boost {
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::toupper( Ch);
|
||||
#else
|
||||
return std::toupper<CharT>( Ch, m_Loc );
|
||||
return std::toupper<CharT>( Ch, *m_Loc );
|
||||
#endif
|
||||
}
|
||||
private:
|
||||
const std::locale& m_Loc;
|
||||
const std::locale* m_Loc;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
|
@ -32,8 +32,8 @@ namespace boost {
|
||||
struct is_classifiedF :
|
||||
public predicate_facade<is_classifiedF>
|
||||
{
|
||||
// Boost.Lambda support
|
||||
template <class Args> struct sig { typedef bool type; };
|
||||
// Boost.ResultOf support
|
||||
typedef bool result_type;
|
||||
|
||||
// Constructor from a 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;
|
||||
|
||||
public:
|
||||
// Boost.Lambda support
|
||||
template <class Args> struct sig { typedef bool type; };
|
||||
// Boost.ResultOf support
|
||||
typedef bool result_type;
|
||||
|
||||
// Constructor
|
||||
template<typename RangeT>
|
||||
@ -253,8 +253,8 @@ namespace boost {
|
||||
struct is_from_rangeF :
|
||||
public predicate_facade< is_from_rangeF<CharT> >
|
||||
{
|
||||
// Boost.Lambda support
|
||||
template <class Args> struct sig { typedef bool type; };
|
||||
// Boost.ResultOf support
|
||||
typedef bool result_type;
|
||||
|
||||
// Constructor
|
||||
is_from_rangeF( CharT From, CharT To ) : m_From(From), m_To(To) {}
|
||||
@ -278,8 +278,8 @@ namespace boost {
|
||||
{
|
||||
public:
|
||||
|
||||
// Boost.Lambda support
|
||||
template <class Args> struct sig { typedef bool type; };
|
||||
// Boost.ResultOf support
|
||||
typedef bool result_type;
|
||||
|
||||
// Constructor
|
||||
pred_andF( Pred1T Pred1, Pred2T Pred2 ) :
|
||||
@ -303,8 +303,8 @@ namespace boost {
|
||||
public predicate_facade< pred_orF<Pred1T,Pred2T> >
|
||||
{
|
||||
public:
|
||||
// Boost.Lambda support
|
||||
template <class Args> struct sig { typedef bool type; };
|
||||
// Boost.ResultOf support
|
||||
typedef bool result_type;
|
||||
|
||||
// Constructor
|
||||
pred_orF( Pred1T Pred1, Pred2T Pred2 ) :
|
||||
@ -328,8 +328,8 @@ namespace boost {
|
||||
public predicate_facade< pred_notF<PredT> >
|
||||
{
|
||||
public:
|
||||
// Boost.Lambda support
|
||||
template <class Args> struct sig { typedef bool type; };
|
||||
// Boost.ResultOf support
|
||||
typedef bool result_type;
|
||||
|
||||
// Constructor
|
||||
pred_notF( PredT Pred ) : m_Pred(Pred) {}
|
||||
|
@ -49,17 +49,17 @@ namespace boost {
|
||||
if ( !M )
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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
|
||||
std::copy( M.end(), ::boost::end(Input), Output );
|
||||
Output = std::copy( M.end(), ::boost::end(Input), Output );
|
||||
|
||||
return Output;
|
||||
}
|
||||
@ -75,12 +75,16 @@ namespace boost {
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult )
|
||||
{
|
||||
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||
return ::boost::algorithm::detail::find_format_copy_impl2(
|
||||
Output,
|
||||
Input,
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
} else {
|
||||
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -132,11 +136,15 @@ namespace boost {
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult)
|
||||
{
|
||||
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||
return ::boost::algorithm::detail::find_format_copy_impl2(
|
||||
Input,
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
} else {
|
||||
return Input;
|
||||
}
|
||||
}
|
||||
|
||||
// replace implementation ----------------------------------------------------//
|
||||
@ -180,12 +188,14 @@ namespace boost {
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult)
|
||||
{
|
||||
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||
::boost::algorithm::detail::find_format_impl2(
|
||||
Input,
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace algorithm
|
||||
|
@ -57,9 +57,9 @@ namespace boost {
|
||||
while( M )
|
||||
{
|
||||
// Copy the beginning of the sequence
|
||||
std::copy( LastMatch, M.begin(), Output );
|
||||
Output = std::copy( LastMatch, M.begin(), Output );
|
||||
// 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
|
||||
LastMatch=M.end();
|
||||
@ -67,7 +67,7 @@ namespace boost {
|
||||
}
|
||||
|
||||
// Copy the rest of the sequence
|
||||
std::copy( LastMatch, ::boost::end(Input), Output );
|
||||
Output = std::copy( LastMatch, ::boost::end(Input), Output );
|
||||
|
||||
return Output;
|
||||
}
|
||||
@ -85,6 +85,7 @@ namespace boost {
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult )
|
||||
{
|
||||
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||
return ::boost::algorithm::detail::find_format_all_copy_impl2(
|
||||
Output,
|
||||
Input,
|
||||
@ -92,6 +93,9 @@ namespace boost {
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
} else {
|
||||
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
||||
}
|
||||
}
|
||||
|
||||
// find_format_all_copy implementation ----------------------------------------------//
|
||||
@ -156,12 +160,16 @@ namespace boost {
|
||||
FormatterT Formatter,
|
||||
const FindResultT& FindResult)
|
||||
{
|
||||
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||
return ::boost::algorithm::detail::find_format_all_copy_impl2(
|
||||
Input,
|
||||
Finder,
|
||||
Formatter,
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
} else {
|
||||
return Input;
|
||||
}
|
||||
}
|
||||
|
||||
// find_format_all implementation ------------------------------------------------//
|
||||
@ -248,6 +256,7 @@ namespace boost {
|
||||
FormatterT Formatter,
|
||||
FindResultT FindResult)
|
||||
{
|
||||
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
|
||||
::boost::algorithm::detail::find_format_all_impl2(
|
||||
Input,
|
||||
Finder,
|
||||
@ -255,6 +264,7 @@ namespace boost {
|
||||
FindResult,
|
||||
Formatter(FindResult) );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace algorithm
|
||||
|
@ -52,7 +52,9 @@ namespace boost {
|
||||
find_format_store& operator=( FindResultT FindResult )
|
||||
{
|
||||
iterator_range<ForwardIteratorT>::operator=(FindResult);
|
||||
if( !this->empty() ) {
|
||||
m_FormatResult=m_Formatter(FindResult);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -68,6 +70,15 @@ namespace boost {
|
||||
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)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
@ -752,7 +752,7 @@ 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 tail.
|
||||
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
|
||||
@ -797,7 +797,7 @@ namespace boost {
|
||||
considered to be the tail. The input sequence is modified in-place.
|
||||
|
||||
\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, size(Input)-|N| characters are extracted.
|
||||
*/
|
||||
|
@ -257,7 +257,7 @@ namespace boost {
|
||||
|
||||
//! 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
|
||||
to be the tail.
|
||||
|
||||
|
@ -240,7 +240,7 @@ namespace boost {
|
||||
m_Match(Other.m_Match),
|
||||
m_Next(Other.m_Next),
|
||||
m_End(Other.m_End),
|
||||
m_bEof(false)
|
||||
m_bEof(Other.m_bEof)
|
||||
{}
|
||||
|
||||
//! Constructor
|
||||
|
@ -92,11 +92,11 @@ Synopsis of <tt><boost/algorithm/minmax.hpp></tt></h3>
|
||||
namespace boost {
|
||||
|
||||
template <class T>
|
||||
tuple<T const&, T const&> >
|
||||
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>>
|
||||
tuple<T const&, T const&> >
|
||||
tuple<T const&, T const&>
|
||||
minmax(const T& a, const T& b, BinaryPredicate comp);
|
||||
|
||||
}
|
||||
@ -243,7 +243,7 @@ range
|
||||
|
||||
<a name="complexity">
|
||||
<h3>
|
||||
<a NAME="Complexity"></a>Complexity</h3>
|
||||
Complexity</h3>
|
||||
Minmax performs a single comparison and is otherwise of constant complexity.
|
||||
The use of <tt>boost::tuple<T const&></tt> prevents copy
|
||||
constructors in case the arguments are passed by reference.
|
||||
@ -438,7 +438,7 @@ comparisons).</p>
|
||||
slower than
|
||||
<tt>first_min_element</tt> alone, still much less than <tt>first_min_element</tt>
|
||||
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>
|
||||
<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
|
||||
:
|
||||
<xsl:param>boost.root=../../../../..
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
||||
;
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
</para>
|
||||
<para>
|
||||
<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.
|
||||
</para>
|
||||
<para>
|
||||
|
@ -32,7 +32,9 @@
|
||||
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 -->
|
||||
<br>Use, modification and distribution is subject to the Boost
|
||||
Software License, Version 1.0. (See accompanying file
|
||||
<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>)
|
||||
</br>
|
||||
</p>
|
||||
<!-- Copyright Dezide Aps 2003-2004 -->
|
||||
|
@ -33,7 +33,7 @@
|
||||
<librarypurpose>
|
||||
A set of generic string-related algorithms and utilities
|
||||
</librarypurpose>
|
||||
<librarycategory name="category:algoritms"/>
|
||||
<librarycategory name="category:algorithms"/>
|
||||
<librarycategory name="category:string-text"/>
|
||||
</libraryinfo>
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
||||
The magic of <ulink url="../../libs/range/index.html">Boost.Range</ulink>
|
||||
provides a uniform way of handling different string types.
|
||||
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.
|
||||
</para>
|
||||
</listitem>
|
||||
@ -169,7 +169,7 @@
|
||||
<programlisting>
|
||||
string str1=" 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!"
|
||||
|
||||
string phone="00423333444";
|
||||
@ -208,7 +208,7 @@
|
||||
</programlisting>
|
||||
<para>
|
||||
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
|
||||
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>.
|
||||
|
||||
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.
|
||||
Also it is convertible to bool therefore it is easy to use find algorithms for a simple containment checking.
|
||||
</para>
|
||||
@ -264,7 +264,7 @@
|
||||
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
|
||||
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.
|
||||
</para>
|
||||
<para>
|
||||
@ -339,7 +339,7 @@
|
||||
typedef vector< string > split_vector_type;
|
||||
|
||||
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>
|
||||
<para>
|
||||
<code>[hello]</code> designates an <code>iterator_range</code> delimiting this substring.
|
||||
|
@ -59,5 +59,11 @@ test-suite algorithm/string
|
||||
:
|
||||
: 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;
|
||||
BOOST_CHECK(equals(*siter, "abb"));
|
||||
++siter;
|
||||
BOOST_CHECK(siter==split_iterator<string::iterator>(siter));
|
||||
BOOST_CHECK(siter==split_iterator<string::iterator>());
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user