mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-26 12:31:44 +02:00
Compare commits
40 Commits
svn-branch
...
boost-1.48
Author | SHA1 | Date | |
---|---|---|---|
3f86a45929 | |||
199a89a1e9 | |||
01492a93c6 | |||
50703b8c97 | |||
0f8d556130 | |||
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 |
@ -27,6 +27,9 @@
|
|||||||
sequence (string). In addition, spaces in the middle of the sequence are truncated
|
sequence (string). In addition, spaces in the middle of the sequence are truncated
|
||||||
to just one character. Space is recognized using given locales.
|
to just one character. Space is recognized using given locales.
|
||||||
|
|
||||||
|
\c trim_fill acts as trim_all, but the spaces in the middle are replaces with
|
||||||
|
a user-define sequence of character.
|
||||||
|
|
||||||
Parametric (\c _if) variants use a predicate (functor) to select which characters
|
Parametric (\c _if) variants use a predicate (functor) to select which characters
|
||||||
are to be trimmed..
|
are to be trimmed..
|
||||||
Functions take a selection predicate as a parameter, which is used to determine
|
Functions take a selection predicate as a parameter, which is used to determine
|
||||||
@ -42,7 +45,7 @@ namespace boost {
|
|||||||
//! Trim All - parametric
|
//! Trim All - parametric
|
||||||
/*!
|
/*!
|
||||||
Remove all leading and trailing spaces from the input and
|
Remove all leading and trailing spaces from the input and
|
||||||
compress all other spaces to a single space.
|
compress all other spaces to a single character.
|
||||||
The result is a trimmed copy of the input
|
The result is a trimmed copy of the input
|
||||||
|
|
||||||
\param Input An input sequence
|
\param Input An input sequence
|
||||||
@ -63,7 +66,7 @@ namespace boost {
|
|||||||
//! Trim All
|
//! Trim All
|
||||||
/*!
|
/*!
|
||||||
Remove all leading and trailing spaces from the input and
|
Remove all leading and trailing spaces from the input and
|
||||||
compress all other spaces to a single space.
|
compress all other spaces to a single character.
|
||||||
The input sequence is modified in-place.
|
The input sequence is modified in-place.
|
||||||
|
|
||||||
\param Input An input sequence
|
\param Input An input sequence
|
||||||
@ -83,7 +86,7 @@ namespace boost {
|
|||||||
//! Trim All
|
//! Trim All
|
||||||
/*!
|
/*!
|
||||||
Remove all leading and trailing spaces from the input and
|
Remove all leading and trailing spaces from the input and
|
||||||
compress all other spaces to a single space.
|
compress all other spaces to a single character.
|
||||||
The result is a trimmed copy of the input
|
The result is a trimmed copy of the input
|
||||||
|
|
||||||
\param Input An input sequence
|
\param Input An input sequence
|
||||||
@ -100,7 +103,7 @@ namespace boost {
|
|||||||
//! Trim All
|
//! Trim All
|
||||||
/*!
|
/*!
|
||||||
Remove all leading and trailing spaces from the input and
|
Remove all leading and trailing spaces from the input and
|
||||||
compress all other spaces to a single space.
|
compress all other spaces to a single character.
|
||||||
The input sequence is modified in-place.
|
The input sequence is modified in-place.
|
||||||
|
|
||||||
\param Input An input sequence
|
\param Input An input sequence
|
||||||
@ -114,6 +117,89 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Trim Fill - parametric
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
replace all every block of consecutive spaces with a fill string
|
||||||
|
defined by user.
|
||||||
|
The result is a trimmed copy of the input
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param Fill A string used to fill the inner spaces
|
||||||
|
\param IsSpace An unary predicate identifying spaces
|
||||||
|
\return A trimmed copy of the input
|
||||||
|
*/
|
||||||
|
template<typename SequenceT, typename RangeT, typename PredicateT>
|
||||||
|
inline SequenceT trim_fill_copy_if(const SequenceT& Input, const RangeT& Fill, PredicateT IsSpace)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
::boost::find_format_all_copy(
|
||||||
|
::boost::trim_copy_if(Input, IsSpace),
|
||||||
|
::boost::token_finder(IsSpace, ::boost::token_compress_on),
|
||||||
|
::boost::const_formatter(::boost::as_literal(Fill)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Trim Fill
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
replace all every block of consecutive spaces with a fill string
|
||||||
|
defined by user.
|
||||||
|
The input sequence is modified in-place.
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param Fill A string used to fill the inner spaces
|
||||||
|
\param IsSpace An unary predicate identifying spaces
|
||||||
|
*/
|
||||||
|
template<typename SequenceT, typename RangeT, typename PredicateT>
|
||||||
|
inline void trim_fill_if(SequenceT& Input, const RangeT& Fill, PredicateT IsSpace)
|
||||||
|
{
|
||||||
|
::boost::trim_if(Input, IsSpace);
|
||||||
|
::boost::find_format_all(
|
||||||
|
Input,
|
||||||
|
::boost::token_finder(IsSpace, ::boost::token_compress_on),
|
||||||
|
::boost::const_formatter(::boost::as_literal(Fill)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Trim Fill
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
replace all every block of consecutive spaces with a fill string
|
||||||
|
defined by user.
|
||||||
|
The result is a trimmed copy of the input
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param Fill A string used to fill the inner spaces
|
||||||
|
\param Loc A locale used for 'space' classification
|
||||||
|
\return A trimmed copy of the input
|
||||||
|
*/
|
||||||
|
template<typename SequenceT, typename RangeT>
|
||||||
|
inline SequenceT trim_fill_copy(const SequenceT& Input, const RangeT& Fill, const std::locale& Loc =std::locale())
|
||||||
|
{
|
||||||
|
return trim_fill_copy_if(Input, Fill, ::boost::is_space(Loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Trim Fill
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
replace all every block of consecutive spaces with a fill string
|
||||||
|
defined by user.
|
||||||
|
The input sequence is modified in-place.
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param Fill A string used to fill the inner spaces
|
||||||
|
\param Loc A locale used for 'space' classification
|
||||||
|
\return A trimmed copy of the input
|
||||||
|
*/
|
||||||
|
template<typename SequenceT, typename RangeT>
|
||||||
|
inline void trim_fill(SequenceT& Input, const RangeT& Fill, const std::locale& Loc =std::locale())
|
||||||
|
{
|
||||||
|
trim_fill_if(Input, Fill, ::boost::is_space(Loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace algorithm
|
} // namespace algorithm
|
||||||
|
|
||||||
// pull names to the boost namespace
|
// pull names to the boost namespace
|
||||||
@ -121,6 +207,10 @@ namespace boost {
|
|||||||
using algorithm::trim_all_if;
|
using algorithm::trim_all_if;
|
||||||
using algorithm::trim_all_copy;
|
using algorithm::trim_all_copy;
|
||||||
using algorithm::trim_all_copy_if;
|
using algorithm::trim_all_copy_if;
|
||||||
|
using algorithm::trim_fill;
|
||||||
|
using algorithm::trim_fill_if;
|
||||||
|
using algorithm::trim_fill_copy;
|
||||||
|
using algorithm::trim_fill_copy_if;
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ most</i> instead of <i>exactly</i> in the odd case.
|
|||||||
<b>Rationale:</b></h3>
|
<b>Rationale:</b></h3>
|
||||||
|
|
||||||
<a name="two_headers">
|
<a name="two_headers">
|
||||||
<h4><b>Why not a single header <tt><boost/algorithm/minmax.hpp></tt>?</b></h4>
|
<h4><b>Why not a single header <tt>&boost/algorithm/minmax.hpp></tt>?</b></h4>
|
||||||
<p>This was the design originally proposed and approved in the formal
|
<p>This was the design originally proposed and approved in the formal
|
||||||
review. As the need for Boost.tuple became clear (due to the limitations
|
review. As the need for Boost.tuple became clear (due to the limitations
|
||||||
of <tt>std::pair</tt>), it became also annoying to require another
|
of <tt>std::pair</tt>), it became also annoying to require another
|
||||||
|
@ -43,7 +43,6 @@ doxygen autodoc
|
|||||||
[ glob ../../../../boost/algorithm/string/formatter.hpp ]
|
[ glob ../../../../boost/algorithm/string/formatter.hpp ]
|
||||||
[ glob ../../../../boost/algorithm/string/regex.hpp ]
|
[ glob ../../../../boost/algorithm/string/regex.hpp ]
|
||||||
[ glob ../../../../boost/algorithm/string/regex_find_format.hpp ]
|
[ glob ../../../../boost/algorithm/string/regex_find_format.hpp ]
|
||||||
[ glob ../../../../boost/algorithm/string/trim_all.hpp ]
|
|
||||||
:
|
:
|
||||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||||
|
@ -151,11 +151,54 @@ void trim_all_test()
|
|||||||
BOOST_CHECK( trim_all_copy_if( string("<>abc<>def<>"), is_any_of( "<<>>" ) )=="abc<def" );
|
BOOST_CHECK( trim_all_copy_if( string("<>abc<>def<>"), is_any_of( "<<>>" ) )=="abc<def" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trim_fill_test()
|
||||||
|
{
|
||||||
|
string str1(" 1x x x x1 ");
|
||||||
|
string str2("+---...2x+--x--+x-+-x2...---+");
|
||||||
|
string str3(" ");
|
||||||
|
|
||||||
|
// *** value passing tests *** //
|
||||||
|
|
||||||
|
// general string test
|
||||||
|
BOOST_CHECK( trim_fill_copy( str1, "-" )=="1x-x-x-x1" ) ;
|
||||||
|
BOOST_CHECK( trim_fill_copy_if( str2, " ", is_punct() )=="2x x x x2" ) ;
|
||||||
|
|
||||||
|
// spaces-only string test
|
||||||
|
BOOST_CHECK( trim_fill_copy( str3, " " )=="" );
|
||||||
|
|
||||||
|
// empty string check
|
||||||
|
BOOST_CHECK( trim_fill_copy( string(""), " " )=="" );
|
||||||
|
|
||||||
|
// general string test
|
||||||
|
trim_fill( str1, "-" );
|
||||||
|
BOOST_CHECK( str1=="1x-x-x-x1" ) ;
|
||||||
|
trim_fill_if( str2, "", is_punct() );
|
||||||
|
BOOST_CHECK( str2=="2xxxx2" ) ;
|
||||||
|
|
||||||
|
// spaces-only string test
|
||||||
|
str3 = " "; trim_fill( str3, "" );
|
||||||
|
BOOST_CHECK( str3=="" );
|
||||||
|
|
||||||
|
// empty string check
|
||||||
|
str3 = ""; trim_fill( str3, "" );
|
||||||
|
BOOST_CHECK( str3=="" );
|
||||||
|
BOOST_CHECK( str3=="" );
|
||||||
|
|
||||||
|
// *** non-standard predicate tests *** //
|
||||||
|
BOOST_CHECK(
|
||||||
|
trim_fill_copy_if(
|
||||||
|
string("123abc127deb456"),
|
||||||
|
"+",
|
||||||
|
is_classified(std::ctype_base::digit) )=="abc+deb" );
|
||||||
|
BOOST_CHECK( trim_fill_copy_if( string("<>abc<>def<>"), "-", is_any_of( "<<>>" ) )=="abc-def" );
|
||||||
|
}
|
||||||
|
|
||||||
// test main
|
// test main
|
||||||
int test_main( int, char*[] )
|
int test_main( int, char*[] )
|
||||||
{
|
{
|
||||||
trim_test();
|
trim_test();
|
||||||
trim_all_test();
|
trim_all_test();
|
||||||
|
trim_fill_test();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user