File indexing completed on 2025-02-22 09:55:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_STRING_JOIN_HPP
0012 #define BOOST_STRING_JOIN_HPP
0013
0014 #include <boost/algorithm/string/config.hpp>
0015 #include <boost/algorithm/string/detail/sequence.hpp>
0016 #include <boost/range/value_type.hpp>
0017 #include <boost/range/as_literal.hpp>
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 namespace boost {
0029 namespace algorithm {
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 template< typename SequenceSequenceT, typename Range1T>
0045 inline typename range_value<SequenceSequenceT>::type
0046 join(
0047 const SequenceSequenceT& Input,
0048 const Range1T& Separator)
0049 {
0050
0051 typedef typename range_value<SequenceSequenceT>::type ResultT;
0052 typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT;
0053
0054
0055 InputIteratorT itBegin=::boost::begin(Input);
0056 InputIteratorT itEnd=::boost::end(Input);
0057
0058
0059 ResultT Result;
0060
0061
0062 if(itBegin!=itEnd)
0063 {
0064 detail::insert(Result, ::boost::end(Result), *itBegin);
0065 ++itBegin;
0066 }
0067
0068 for(;itBegin!=itEnd; ++itBegin)
0069 {
0070
0071 detail::insert(Result, ::boost::end(Result), ::boost::as_literal(Separator));
0072
0073 detail::insert(Result, ::boost::end(Result), *itBegin);
0074 }
0075
0076 return Result;
0077 }
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 template< typename SequenceSequenceT, typename Range1T, typename PredicateT>
0095 inline typename range_value<SequenceSequenceT>::type
0096 join_if(
0097 const SequenceSequenceT& Input,
0098 const Range1T& Separator,
0099 PredicateT Pred)
0100 {
0101
0102 typedef typename range_value<SequenceSequenceT>::type ResultT;
0103 typedef typename range_const_iterator<SequenceSequenceT>::type InputIteratorT;
0104
0105
0106 InputIteratorT itBegin=::boost::begin(Input);
0107 InputIteratorT itEnd=::boost::end(Input);
0108
0109
0110 ResultT Result;
0111
0112
0113 while(itBegin!=itEnd && !Pred(*itBegin)) ++itBegin;
0114
0115 if(itBegin!=itEnd)
0116 {
0117 detail::insert(Result, ::boost::end(Result), *itBegin);
0118 ++itBegin;
0119 }
0120
0121 for(;itBegin!=itEnd; ++itBegin)
0122 {
0123 if(Pred(*itBegin))
0124 {
0125
0126 detail::insert(Result, ::boost::end(Result), ::boost::as_literal(Separator));
0127
0128 detail::insert(Result, ::boost::end(Result), *itBegin);
0129 }
0130 }
0131
0132 return Result;
0133 }
0134
0135 }
0136
0137
0138 using algorithm::join;
0139 using algorithm::join_if;
0140
0141 }
0142
0143
0144 #endif
0145