File indexing completed on 2025-01-18 09:28:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP
0012 #define BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP
0013
0014 #include <boost/algorithm/string/config.hpp>
0015 #include <boost/range/iterator_range_core.hpp>
0016 #include <boost/range/const_iterator.hpp>
0017 #include <boost/range/value_type.hpp>
0018 #include <boost/algorithm/string/detail/find_format_store.hpp>
0019 #include <boost/algorithm/string/detail/replace_storage.hpp>
0020
0021 #include <deque>
0022
0023 namespace boost {
0024 namespace algorithm {
0025 namespace detail {
0026
0027
0028
0029 template<
0030 typename OutputIteratorT,
0031 typename InputT,
0032 typename FinderT,
0033 typename FormatterT,
0034 typename FindResultT,
0035 typename FormatResultT >
0036 inline OutputIteratorT find_format_all_copy_impl2(
0037 OutputIteratorT Output,
0038 const InputT& Input,
0039 FinderT Finder,
0040 FormatterT Formatter,
0041 const FindResultT& FindResult,
0042 const FormatResultT& FormatResult )
0043 {
0044 typedef BOOST_STRING_TYPENAME
0045 range_const_iterator<InputT>::type input_iterator_type;
0046
0047 typedef find_format_store<
0048 input_iterator_type,
0049 FormatterT,
0050 FormatResultT > store_type;
0051
0052
0053 store_type M( FindResult, FormatResult, Formatter );
0054
0055
0056 input_iterator_type LastMatch=::boost::begin(Input);
0057
0058
0059 while( M )
0060 {
0061
0062 Output = std::copy( LastMatch, M.begin(), Output );
0063
0064 Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
0065
0066
0067 LastMatch=M.end();
0068 M=Finder( LastMatch, ::boost::end(Input) );
0069 }
0070
0071
0072 Output = std::copy( LastMatch, ::boost::end(Input), Output );
0073
0074 return Output;
0075 }
0076
0077 template<
0078 typename OutputIteratorT,
0079 typename InputT,
0080 typename FinderT,
0081 typename FormatterT,
0082 typename FindResultT >
0083 inline OutputIteratorT find_format_all_copy_impl(
0084 OutputIteratorT Output,
0085 const InputT& Input,
0086 FinderT Finder,
0087 FormatterT Formatter,
0088 const FindResultT& FindResult )
0089 {
0090 if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
0091 return ::boost::algorithm::detail::find_format_all_copy_impl2(
0092 Output,
0093 Input,
0094 Finder,
0095 Formatter,
0096 FindResult,
0097 Formatter(FindResult) );
0098 } else {
0099 return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
0100 }
0101 }
0102
0103
0104
0105 template<
0106 typename InputT,
0107 typename FinderT,
0108 typename FormatterT,
0109 typename FindResultT,
0110 typename FormatResultT >
0111 inline InputT find_format_all_copy_impl2(
0112 const InputT& Input,
0113 FinderT Finder,
0114 FormatterT Formatter,
0115 const FindResultT& FindResult,
0116 const FormatResultT& FormatResult)
0117 {
0118 typedef BOOST_STRING_TYPENAME
0119 range_const_iterator<InputT>::type input_iterator_type;
0120
0121 typedef find_format_store<
0122 input_iterator_type,
0123 FormatterT,
0124 FormatResultT > store_type;
0125
0126
0127 store_type M( FindResult, FormatResult, Formatter );
0128
0129
0130 input_iterator_type LastMatch=::boost::begin(Input);
0131
0132
0133 InputT Output;
0134
0135
0136 while( M )
0137 {
0138
0139 boost::algorithm::detail::insert( Output, ::boost::end(Output), LastMatch, M.begin() );
0140
0141 boost::algorithm::detail::insert( Output, ::boost::end(Output), M.format_result() );
0142
0143
0144 LastMatch=M.end();
0145 M=Finder( LastMatch, ::boost::end(Input) );
0146 }
0147
0148
0149 ::boost::algorithm::detail::insert( Output, ::boost::end(Output), LastMatch, ::boost::end(Input) );
0150
0151 return Output;
0152 }
0153
0154 template<
0155 typename InputT,
0156 typename FinderT,
0157 typename FormatterT,
0158 typename FindResultT >
0159 inline InputT find_format_all_copy_impl(
0160 const InputT& Input,
0161 FinderT Finder,
0162 FormatterT Formatter,
0163 const FindResultT& FindResult)
0164 {
0165 if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
0166 return ::boost::algorithm::detail::find_format_all_copy_impl2(
0167 Input,
0168 Finder,
0169 Formatter,
0170 FindResult,
0171 Formatter(FindResult) );
0172 } else {
0173 return Input;
0174 }
0175 }
0176
0177
0178
0179 template<
0180 typename InputT,
0181 typename FinderT,
0182 typename FormatterT,
0183 typename FindResultT,
0184 typename FormatResultT >
0185 inline void find_format_all_impl2(
0186 InputT& Input,
0187 FinderT Finder,
0188 FormatterT Formatter,
0189 FindResultT FindResult,
0190 FormatResultT FormatResult)
0191 {
0192 typedef BOOST_STRING_TYPENAME
0193 range_iterator<InputT>::type input_iterator_type;
0194 typedef find_format_store<
0195 input_iterator_type,
0196 FormatterT,
0197 FormatResultT > store_type;
0198
0199
0200 store_type M( FindResult, FormatResult, Formatter );
0201
0202
0203 std::deque<
0204 BOOST_STRING_TYPENAME range_value<InputT>::type> Storage;
0205
0206
0207 input_iterator_type InsertIt=::boost::begin(Input);
0208 input_iterator_type SearchIt=::boost::begin(Input);
0209
0210 while( M )
0211 {
0212
0213 InsertIt=process_segment(
0214 Storage,
0215 Input,
0216 InsertIt,
0217 SearchIt,
0218 M.begin() );
0219
0220
0221 SearchIt=M.end();
0222
0223
0224 ::boost::algorithm::detail::copy_to_storage( Storage, M.format_result() );
0225
0226
0227 M=Finder( SearchIt, ::boost::end(Input) );
0228 }
0229
0230
0231 InsertIt=::boost::algorithm::detail::process_segment(
0232 Storage,
0233 Input,
0234 InsertIt,
0235 SearchIt,
0236 ::boost::end(Input) );
0237
0238 if ( Storage.empty() )
0239 {
0240
0241 ::boost::algorithm::detail::erase( Input, InsertIt, ::boost::end(Input) );
0242 }
0243 else
0244 {
0245
0246 ::boost::algorithm::detail::insert( Input, ::boost::end(Input), Storage.begin(), Storage.end() );
0247 }
0248 }
0249
0250 template<
0251 typename InputT,
0252 typename FinderT,
0253 typename FormatterT,
0254 typename FindResultT >
0255 inline void find_format_all_impl(
0256 InputT& Input,
0257 FinderT Finder,
0258 FormatterT Formatter,
0259 FindResultT FindResult)
0260 {
0261 if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
0262 ::boost::algorithm::detail::find_format_all_impl2(
0263 Input,
0264 Finder,
0265 Formatter,
0266 FindResult,
0267 Formatter(FindResult) );
0268 }
0269 }
0270
0271 }
0272 }
0273 }
0274
0275 #endif