forked from boostorg/algorithm
Compare commits
10 Commits
boost-1.44
...
boost-1.49
Author | SHA1 | Date | |
---|---|---|---|
2b38f25727 | |||
0f2399fef0 | |||
044d667e79 | |||
be9da63894 | |||
787c94bc53 | |||
e87ce37b34 | |||
199a89a1e9 | |||
01492a93c6 | |||
50703b8c97 | |||
0f8d556130 |
@ -15,6 +15,8 @@
|
|||||||
#include <locale>
|
#include <locale>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include <boost/type_traits/make_unsigned.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace algorithm {
|
namespace algorithm {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@ -37,7 +39,7 @@ namespace boost {
|
|||||||
CharT operator ()( CharT Ch ) const
|
CharT operator ()( CharT Ch ) const
|
||||||
{
|
{
|
||||||
#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( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
|
||||||
#else
|
#else
|
||||||
return std::tolower<CharT>( Ch, *m_Loc );
|
return std::tolower<CharT>( Ch, *m_Loc );
|
||||||
#endif
|
#endif
|
||||||
@ -57,7 +59,7 @@ namespace boost {
|
|||||||
CharT operator ()( CharT Ch ) const
|
CharT operator ()( CharT Ch ) const
|
||||||
{
|
{
|
||||||
#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( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
|
||||||
#else
|
#else
|
||||||
return std::toupper<CharT>( Ch, *m_Loc );
|
return std::toupper<CharT>( Ch, *m_Loc );
|
||||||
#endif
|
#endif
|
||||||
|
@ -126,7 +126,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use fixed storage
|
// Use fixed storage
|
||||||
::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
::std::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@ -206,7 +206,7 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the data
|
// Copy the data
|
||||||
::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
::std::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -74,17 +74,17 @@ namespace boost {
|
|||||||
const InputT& Input,
|
const InputT& Input,
|
||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
const FindResultT& FindResult )
|
const FindResultT& FindResult )
|
||||||
{
|
{
|
||||||
if( ::boost::algorithm::detail::check_find_result(Input, 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 {
|
} else {
|
||||||
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -137,14 +137,14 @@ namespace boost {
|
|||||||
const FindResultT& FindResult)
|
const FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
if( ::boost::algorithm::detail::check_find_result(Input, 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 {
|
} else {
|
||||||
return Input;
|
return Input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace implementation ----------------------------------------------------//
|
// replace implementation ----------------------------------------------------//
|
||||||
@ -189,12 +189,12 @@ namespace boost {
|
|||||||
const FindResultT& FindResult)
|
const FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
if( ::boost::algorithm::detail::check_find_result(Input, 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
|
||||||
|
@ -84,18 +84,18 @@ namespace boost {
|
|||||||
FinderT Finder,
|
FinderT Finder,
|
||||||
FormatterT Formatter,
|
FormatterT Formatter,
|
||||||
const FindResultT& FindResult )
|
const FindResultT& FindResult )
|
||||||
{
|
{
|
||||||
if( ::boost::algorithm::detail::check_find_result(Input, 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,
|
||||||
Finder,
|
Finder,
|
||||||
Formatter,
|
Formatter,
|
||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
} else {
|
} else {
|
||||||
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find_format_all_copy implementation ----------------------------------------------//
|
// find_format_all_copy implementation ----------------------------------------------//
|
||||||
@ -161,15 +161,15 @@ namespace boost {
|
|||||||
const FindResultT& FindResult)
|
const FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
if( ::boost::algorithm::detail::check_find_result(Input, 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 {
|
} else {
|
||||||
return Input;
|
return Input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find_format_all implementation ------------------------------------------------//
|
// find_format_all implementation ------------------------------------------------//
|
||||||
@ -257,13 +257,13 @@ namespace boost {
|
|||||||
FindResultT FindResult)
|
FindResultT FindResult)
|
||||||
{
|
{
|
||||||
if( ::boost::algorithm::detail::check_find_result(Input, 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,
|
||||||
Formatter,
|
Formatter,
|
||||||
FindResult,
|
FindResult,
|
||||||
Formatter(FindResult) );
|
Formatter(FindResult) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@ -53,7 +53,7 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
iterator_range<ForwardIteratorT>::operator=(FindResult);
|
iterator_range<ForwardIteratorT>::operator=(FindResult);
|
||||||
if( !this->empty() ) {
|
if( !this->empty() ) {
|
||||||
m_FormatResult=m_Formatter(FindResult);
|
m_FormatResult=m_Formatter(FindResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -71,7 +71,7 @@ namespace boost {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename InputT, typename FindResultT>
|
template<typename InputT, typename FindResultT>
|
||||||
bool check_find_result(InputT& Input, FindResultT& FindResult)
|
bool check_find_result(InputT&, FindResultT& FindResult)
|
||||||
{
|
{
|
||||||
typedef BOOST_STRING_TYPENAME
|
typedef BOOST_STRING_TYPENAME
|
||||||
range_const_iterator<InputT>::type input_iterator_type;
|
range_const_iterator<InputT>::type input_iterator_type;
|
||||||
|
@ -87,6 +87,31 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// dissect format functor ----------------------------------------------------//
|
||||||
|
|
||||||
|
// dissect format functor
|
||||||
|
template<typename FinderT>
|
||||||
|
struct dissect_formatF
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Construction
|
||||||
|
dissect_formatF(FinderT Finder) :
|
||||||
|
m_Finder(Finder) {}
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
template<typename RangeT>
|
||||||
|
inline iterator_range<
|
||||||
|
BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
|
||||||
|
operator()(const RangeT& Replace) const
|
||||||
|
{
|
||||||
|
return m_Finder(::boost::begin(Replace), ::boost::end(Replace));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
FinderT m_Finder;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace algorithm
|
} // namespace algorithm
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace boost {
|
|||||||
|
|
||||||
//! Constant formatter
|
//! Constant formatter
|
||||||
/*!
|
/*!
|
||||||
Construct the \c const_formatter. Const formatter always returns
|
Constructs a \c const_formatter. Const formatter always returns
|
||||||
the same value, regardless of the parameter.
|
the same value, regardless of the parameter.
|
||||||
|
|
||||||
\param Format A predefined value used as a result for formating
|
\param Format A predefined value used as a result for formating
|
||||||
@ -55,7 +55,7 @@ namespace boost {
|
|||||||
|
|
||||||
//! Identity formatter
|
//! Identity formatter
|
||||||
/*!
|
/*!
|
||||||
Construct the \c identity_formatter. Identity formatter always returns
|
Constructs an \c identity_formatter. Identity formatter always returns
|
||||||
the parameter.
|
the parameter.
|
||||||
|
|
||||||
\return An instance of the \c identity_formatter object.
|
\return An instance of the \c identity_formatter object.
|
||||||
@ -73,7 +73,7 @@ namespace boost {
|
|||||||
|
|
||||||
//! Empty formatter
|
//! Empty formatter
|
||||||
/*!
|
/*!
|
||||||
Construct the \c empty_formatter. Empty formatter always returns an empty
|
Constructs an \c empty_formatter. Empty formatter always returns an empty
|
||||||
sequence.
|
sequence.
|
||||||
|
|
||||||
\param Input container used to select a correct value_type for the
|
\param Input container used to select a correct value_type for the
|
||||||
@ -89,6 +89,22 @@ namespace boost {
|
|||||||
BOOST_STRING_TYPENAME range_value<RangeT>::type>();
|
BOOST_STRING_TYPENAME range_value<RangeT>::type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Empty formatter
|
||||||
|
/*!
|
||||||
|
Constructs a \c dissect_formatter. Dissect formatter uses a specified finder
|
||||||
|
to extract a portion of the formatted sequence. The first finder's match is returned
|
||||||
|
as a result
|
||||||
|
|
||||||
|
\param Finder a finder used to select a portion of the formated sequence
|
||||||
|
\return An instance of the \c dissect_formatter object.
|
||||||
|
*/
|
||||||
|
template<typename FinderT>
|
||||||
|
inline detail::dissect_formatF< FinderT >
|
||||||
|
dissect_formatter(const FinderT& Finder)
|
||||||
|
{
|
||||||
|
return detail::dissect_formatF<FinderT>(Finder);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace algorithm
|
} // namespace algorithm
|
||||||
|
|
||||||
@ -96,6 +112,7 @@ namespace boost {
|
|||||||
using algorithm::const_formatter;
|
using algorithm::const_formatter;
|
||||||
using algorithm::identity_formatter;
|
using algorithm::identity_formatter;
|
||||||
using algorithm::empty_formatter;
|
using algorithm::empty_formatter;
|
||||||
|
using algorithm::dissect_formatter;
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
217
include/boost/algorithm/string/trim_all.hpp
Normal file
217
include/boost/algorithm/string/trim_all.hpp
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
// Boost string_algo library trim.hpp header file ---------------------------//
|
||||||
|
|
||||||
|
// Copyright Pavol Droba 2002-2003.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#ifndef BOOST_STRING_TRIM_ALL_HPP
|
||||||
|
#define BOOST_STRING_TRIM_ALL_HPP
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/config.hpp>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
#include <boost/algorithm/string/find_format.hpp>
|
||||||
|
#include <boost/algorithm/string/formatter.hpp>
|
||||||
|
#include <boost/algorithm/string/finder.hpp>
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
|
/*! \file
|
||||||
|
Defines trim_all algorithms.
|
||||||
|
|
||||||
|
Just like \c trim, \c trim_all removes all trailing and leading spaces from a
|
||||||
|
sequence (string). In addition, spaces in the middle of the sequence are truncated
|
||||||
|
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
|
||||||
|
are to be trimmed..
|
||||||
|
Functions take a selection predicate as a parameter, which is used to determine
|
||||||
|
whether a character is a space. Common predicates are provided in classification.hpp header.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace algorithm {
|
||||||
|
|
||||||
|
// multi line trim ----------------------------------------------- //
|
||||||
|
|
||||||
|
//! Trim All - parametric
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
compress all other spaces to a single character.
|
||||||
|
The result is a trimmed copy of the input
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param IsSpace An unary predicate identifying spaces
|
||||||
|
\return A trimmed copy of the input
|
||||||
|
*/
|
||||||
|
template<typename SequenceT, typename PredicateT>
|
||||||
|
inline SequenceT trim_all_copy_if(const SequenceT& Input, PredicateT IsSpace)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
::boost::find_format_all_copy(
|
||||||
|
::boost::trim_copy_if(Input, IsSpace),
|
||||||
|
::boost::token_finder(IsSpace, ::boost::token_compress_on),
|
||||||
|
::boost::dissect_formatter(::boost::head_finder(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Trim All
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
compress all other spaces to a single character.
|
||||||
|
The input sequence is modified in-place.
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param IsSpace An unary predicate identifying spaces
|
||||||
|
*/
|
||||||
|
template<typename SequenceT, typename PredicateT>
|
||||||
|
inline void trim_all_if(SequenceT& Input, PredicateT IsSpace)
|
||||||
|
{
|
||||||
|
::boost::trim_if(Input, IsSpace);
|
||||||
|
::boost::find_format_all(
|
||||||
|
Input,
|
||||||
|
::boost::token_finder(IsSpace, ::boost::token_compress_on),
|
||||||
|
::boost::dissect_formatter(::boost::head_finder(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Trim All
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
compress all other spaces to a single character.
|
||||||
|
The result is a trimmed copy of the input
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param Loc A locale used for 'space' classification
|
||||||
|
\return A trimmed copy of the input
|
||||||
|
*/
|
||||||
|
template<typename SequenceT>
|
||||||
|
inline SequenceT trim_all_copy(const SequenceT& Input, const std::locale& Loc =std::locale())
|
||||||
|
{
|
||||||
|
return trim_all_copy_if(Input, ::boost::is_space(Loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Trim All
|
||||||
|
/*!
|
||||||
|
Remove all leading and trailing spaces from the input and
|
||||||
|
compress all other spaces to a single character.
|
||||||
|
The input sequence is modified in-place.
|
||||||
|
|
||||||
|
\param Input An input sequence
|
||||||
|
\param Loc A locale used for 'space' classification
|
||||||
|
\return A trimmed copy of the input
|
||||||
|
*/
|
||||||
|
template<typename SequenceT>
|
||||||
|
inline void trim_all(SequenceT& Input, const std::locale& Loc =std::locale())
|
||||||
|
{
|
||||||
|
trim_all_if(Input, ::boost::is_space(Loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! 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
|
||||||
|
|
||||||
|
// pull names to the boost namespace
|
||||||
|
using algorithm::trim_all;
|
||||||
|
using algorithm::trim_all_if;
|
||||||
|
using algorithm::trim_all_copy;
|
||||||
|
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
|
||||||
|
|
||||||
|
#endif // BOOST_STRING_TRIM_ALL_HPP
|
@ -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,6 +43,7 @@ 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
|
||||||
|
@ -737,6 +737,20 @@
|
|||||||
<functionname>is_xdigit()</functionname>
|
<functionname>is_xdigit()</functionname>
|
||||||
</entry>
|
</entry>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>is_any_of</entry>
|
||||||
|
<entry>Recognize any of a sequence of characters</entry>
|
||||||
|
<entry>
|
||||||
|
<functionname>is_any_of()</functionname>
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry>is_from_range</entry>
|
||||||
|
<entry>Recognize characters inside a min..max range</entry>
|
||||||
|
<entry>
|
||||||
|
<functionname>is_from_range()</functionname>
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
</tbody>
|
</tbody>
|
||||||
</tgroup>
|
</tgroup>
|
||||||
</table>
|
</table>
|
||||||
|
@ -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>
|
||||||
@ -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>
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
#include <boost/algorithm/string/erase.hpp>
|
#include <boost/algorithm/string/erase.hpp>
|
||||||
#include <boost/algorithm/string/std/list_traits.hpp>
|
#include <boost/algorithm/string/std/list_traits.hpp>
|
||||||
#include <boost/algorithm/string/std/string_traits.hpp>
|
#include <boost/algorithm/string/std/string_traits.hpp>
|
||||||
|
#include <boost/algorithm/string/finder.hpp>
|
||||||
|
#include <boost/algorithm/string/formatter.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
|
||||||
// Include unit test framework
|
// Include unit test framework
|
||||||
#include <boost/test/included/test_exec_monitor.hpp>
|
#include <boost/test/included/test_exec_monitor.hpp>
|
||||||
@ -285,6 +288,23 @@ void collection_comp_test()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dissect_format_test()
|
||||||
|
{
|
||||||
|
BOOST_CHECK(
|
||||||
|
find_format_all_copy(
|
||||||
|
string("aBc123Abc"),
|
||||||
|
first_finder("abc", is_iequal()),
|
||||||
|
dissect_formatter(token_finder(is_upper())))=="B123A");
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_CHECK(
|
||||||
|
find_format_all_copy(
|
||||||
|
string("abc 123 abc"),
|
||||||
|
token_finder(is_space(), token_compress_on),
|
||||||
|
dissect_formatter(head_finder(1)))=="abc 123 abc");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// test main
|
// test main
|
||||||
int test_main( int, char*[] )
|
int test_main( int, char*[] )
|
||||||
{
|
{
|
||||||
@ -297,6 +317,7 @@ int test_main( int, char*[] )
|
|||||||
replace_tail_test();
|
replace_tail_test();
|
||||||
replace_range_test();
|
replace_range_test();
|
||||||
collection_comp_test();
|
collection_comp_test();
|
||||||
|
dissect_format_test();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
// See http://www.boost.org for updates, documentation, and revision history.
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
#include <boost/algorithm/string/trim_all.hpp>
|
||||||
|
|
||||||
// Include unit test framework
|
// Include unit test framework
|
||||||
#include <boost/test/included/test_exec_monitor.hpp>
|
#include <boost/test/included/test_exec_monitor.hpp>
|
||||||
@ -109,10 +110,95 @@ void trim_test()
|
|||||||
BOOST_CHECK( trim_copy_if( string("<>abc<>"), is_any_of( "<<>>" ) )=="abc" );
|
BOOST_CHECK( trim_copy_if( string("<>abc<>"), is_any_of( "<<>>" ) )=="abc" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trim_all_test()
|
||||||
|
{
|
||||||
|
string str1(" 1x x x x1 ");
|
||||||
|
string str2("+---...2x+--x--+x-+-x2...---+");
|
||||||
|
string str3(" ");
|
||||||
|
|
||||||
|
// *** value passing tests *** //
|
||||||
|
|
||||||
|
// general string test
|
||||||
|
BOOST_CHECK( trim_all_copy( str1 )=="1x x x x1" ) ;
|
||||||
|
BOOST_CHECK( trim_all_copy_if( str2, is_punct() )=="2x+x-x-x2" ) ;
|
||||||
|
|
||||||
|
// spaces-only string test
|
||||||
|
BOOST_CHECK( trim_all_copy( str3 )=="" );
|
||||||
|
|
||||||
|
// empty string check
|
||||||
|
BOOST_CHECK( trim_all_copy( string("") )=="" );
|
||||||
|
|
||||||
|
// general string test
|
||||||
|
trim_all( str1 );
|
||||||
|
BOOST_CHECK( str1=="1x x x x1" ) ;
|
||||||
|
trim_all_if( str2, is_punct() );
|
||||||
|
BOOST_CHECK( str2=="2x+x-x-x2" ) ;
|
||||||
|
|
||||||
|
// spaces-only string test
|
||||||
|
str3 = " "; trim_all( str3 );
|
||||||
|
BOOST_CHECK( str3=="" );
|
||||||
|
|
||||||
|
// empty string check
|
||||||
|
str3 = ""; trim_all( str3 );
|
||||||
|
BOOST_CHECK( str3=="" );
|
||||||
|
BOOST_CHECK( str3=="" );
|
||||||
|
|
||||||
|
// *** non-standard predicate tests *** //
|
||||||
|
BOOST_CHECK(
|
||||||
|
trim_all_copy_if(
|
||||||
|
string("123abc127deb456"),
|
||||||
|
is_classified(std::ctype_base::digit) )=="abc1deb" );
|
||||||
|
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_fill_test();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user