regex variant of join_if renamed to join_if_regex for compilers that do not support

template ordering.


[SVN r33136]
This commit is contained in:
Pavol Droba
2006-02-27 11:58:43 +00:00
parent 0bcbe2afc6
commit 134a106ae9

View File

@ -476,6 +476,8 @@ namespace boost {
// join_if ------------------------------------------------------------------// // join_if ------------------------------------------------------------------//
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
//! Conditional join algorithm //! Conditional join algorithm
/*! /*!
This algorithm joins all strings in a 'list' into one long string. This algorithm joins all strings in a 'list' into one long string.
@ -542,6 +544,76 @@ namespace boost {
return Result; return Result;
} }
#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
//! Conditional join algorithm
/*!
This algorithm joins all strings in a 'list' into one long string.
Segments are concatenated by given separator. Only segments that
match the given regular expression will be added to the result
This is a specialization of join_if algorithm.
\param Input A container that holds the input strings. It must be a container-of-containers.
\param Separator A string that will separate the joined segments.
\param Rx A regular expression
\param Flags Regex options
\return Concatenated string.
\note This function provides the strong exception-safety guarantee
*/
template<
typename SequenceSequenceT,
typename Range1T,
typename CharT,
typename RegexTraitsT >
inline typename range_value<SequenceSequenceT>::type
join_if_regex(
const SequenceSequenceT& Input,
Range1T& Separator,
const basic_regex<CharT, RegexTraitsT>& Rx,
match_flag_type Flags=match_default )
{
// Define working types
typedef typename range_value<SequenceSequenceT>::type ResultT;
typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT;
// Parse input
InputIteratorT itBegin=begin(Input);
InputIteratorT itEnd=end(Input);
// Construct container to hold the result
ResultT Result;
// Roll to the first element that will be added
while(
itBegin!=itEnd &&
!regex_match(begin(*itBegin), end(*itBegin), Rx, Flags)) ++itBegin;
// Add this element
if(itBegin!=itEnd)
{
detail::insert(Result, end(Result), *itBegin);
++itBegin;
}
for(;itBegin!=itEnd; ++itBegin)
{
if(regex_match(begin(*itBegin), end(*itBegin), Rx, Flags))
{
// Add separator
detail::insert(Result, end(Result), Separator);
// Add element
detail::insert(Result, end(Result), *itBegin);
}
}
return Result;
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
} // namespace algorithm } // namespace algorithm