Ugly, not-to-be-pushed sucking in of all of Boost to get windows to work.
[dyninst.git] / external / boost / algorithm / string / detail / find_format_all.hpp
1 //  Boost string_algo library find_format_all.hpp header file  ---------------------------//
2
3 //  Copyright Pavol Droba 2002-2003. Use, modification and
4 //  distribution is subject to the Boost Software License, Version
5 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7
8 //  See http://www.boost.org for updates, documentation, and revision history.
9
10 #ifndef BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP
11 #define BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP
12
13 #include <boost/algorithm/string/config.hpp>
14 #include <boost/range/iterator_range.hpp>
15 #include <boost/range/const_iterator.hpp>
16 #include <boost/range/value_type.hpp>
17 #include <boost/algorithm/string/detail/find_format_store.hpp>
18 #include <boost/algorithm/string/detail/replace_storage.hpp>
19
20 namespace boost {
21     namespace algorithm {
22         namespace detail {
23
24 // find_format_all_copy (iterator variant) implementation ---------------------------//
25
26             template< 
27                 typename OutputIteratorT,
28                 typename InputT,
29                 typename FinderT,
30                 typename FormatterT,
31                 typename FindResultT >
32             inline OutputIteratorT find_format_all_copy_impl(
33                 OutputIteratorT Output,
34                 const InputT& Input,
35                 FinderT Finder,
36                 FormatterT Formatter,
37                 const FindResultT& FindResult )
38             {       
39                 return find_format_all_copy_impl2( 
40                     Output,
41                     Input,
42                     Finder,
43                     Formatter,
44                     FindResult,
45                     Formatter(FindResult) );
46             }
47
48             template< 
49                 typename OutputIteratorT,
50                 typename InputT,
51                 typename FinderT,
52                 typename FormatterT,
53                 typename FindResultT,
54                 typename FormatResultT >
55             inline OutputIteratorT find_format_all_copy_impl2(
56                 OutputIteratorT Output,
57                 const InputT& Input,
58                 FinderT Finder,
59                 FormatterT Formatter,
60                 const FindResultT& FindResult,
61                 const FormatResultT& FormatResult )
62             {       
63                 typedef BOOST_STRING_TYPENAME 
64                     range_const_iterator<InputT>::type input_iterator_type; 
65
66                 typedef find_format_store<
67                         input_iterator_type, 
68                         FormatterT,
69                         FormatResultT > store_type;
70
71                 // Create store for the find result
72                 store_type M( FindResult, FormatResult, Formatter );
73
74                 // Initialize last match
75                 input_iterator_type LastMatch=begin(Input);
76
77                 // Iterate through all matches
78                 while( M )
79                 {
80                     // Copy the beginning of the sequence
81                     std::copy( LastMatch, M.begin(), Output );
82                     // Copy formated result
83                     std::copy( begin(M.format_result()), end(M.format_result()), Output );
84
85                     // Proceed to the next match
86                     LastMatch=M.end();
87                     M=Finder( LastMatch, end(Input) );
88                 }
89
90                 // Copy the rest of the sequence
91                 std::copy( LastMatch, end(Input), Output );
92
93                 return Output;
94             }
95
96 // find_format_all_copy implementation ----------------------------------------------//
97
98             template< 
99                 typename InputT, 
100                 typename FinderT,
101                 typename FormatterT,
102                 typename FindResultT >
103             inline InputT find_format_all_copy_impl(
104                 const InputT& Input,
105                 FinderT Finder,
106                 FormatterT Formatter,
107                 const FindResultT& FindResult)
108             {
109                 return find_format_all_copy_impl2(
110                     Input,
111                     Finder,
112                     Formatter,
113                     FindResult,
114                     Formatter(FindResult) );
115             }
116
117             template< 
118                 typename InputT, 
119                 typename FinderT,
120                 typename FormatterT,
121                 typename FindResultT,
122                 typename FormatResultT >
123             inline InputT find_format_all_copy_impl2(
124                 const InputT& Input,
125                 FinderT Finder,
126                 FormatterT Formatter,
127                 const FindResultT& FindResult,
128                 const FormatResultT& FormatResult)
129             {
130                 typedef BOOST_STRING_TYPENAME 
131                     range_const_iterator<InputT>::type input_iterator_type; 
132
133                 typedef find_format_store<
134                         input_iterator_type, 
135                         FormatterT,
136                         FormatResultT > store_type;
137
138                 // Create store for the find result
139                 store_type M( FindResult, FormatResult, Formatter );
140
141                 // Initialize last match
142                 input_iterator_type LastMatch=begin(Input);
143
144                 // Output temporary
145                 InputT Output;
146
147                 // Iterate through all matches
148                 while( M )
149                 {
150                     // Copy the beginning of the sequence
151                     insert( Output, end(Output), LastMatch, M.begin() );
152                     // Copy formated result
153                     insert( Output, end(Output), M.format_result() );
154
155                     // Proceed to the next match
156                     LastMatch=M.end();
157                     M=Finder( LastMatch, end(Input) );
158                 }
159
160                 // Copy the rest of the sequence
161                 insert( Output, end(Output), LastMatch, end(Input) );
162
163                 return Output;
164             }
165
166 // find_format_all implementation ------------------------------------------------//
167         
168             template<
169                 typename InputT,
170                 typename FinderT,
171                 typename FormatterT,
172                 typename FindResultT >
173             inline void find_format_all_impl( 
174                 InputT& Input,
175                 FinderT Finder,
176                 FormatterT Formatter,
177                 FindResultT FindResult)
178             {
179                 find_format_all_impl2(
180                     Input,
181                     Finder,
182                     Formatter,
183                     FindResult,
184                     Formatter(FindResult) );
185             }
186
187             template<
188                 typename InputT,
189                 typename FinderT,
190                 typename FormatterT,
191                 typename FindResultT,
192                 typename FormatResultT >
193             inline void find_format_all_impl2( 
194                 InputT& Input,
195                 FinderT Finder,
196                 FormatterT Formatter,
197                 FindResultT FindResult,
198                 FormatResultT FormatResult)
199             {
200                 typedef BOOST_STRING_TYPENAME 
201                     range_iterator<InputT>::type input_iterator_type; 
202                 typedef find_format_store<
203                         input_iterator_type, 
204                         FormatterT,
205                         FormatResultT > store_type;
206
207                 // Create store for the find result
208                 store_type M( FindResult, FormatResult, Formatter );
209           
210                 // Instantiate replacement storage
211                 std::deque<
212                     BOOST_STRING_TYPENAME range_value<InputT>::type> Storage;
213
214                 // Initialize replacement iterators
215                 input_iterator_type InsertIt=begin(Input);
216                 input_iterator_type SearchIt=begin(Input);
217                 
218                 while( M )
219                 {
220                     // process the segment
221                     InsertIt=process_segment( 
222                         Storage,
223                         Input,
224                         InsertIt,
225                         SearchIt,
226                         M.begin() );
227                     
228                     // Adjust search iterator
229                     SearchIt=M.end();
230
231                     // Copy formated replace to the storage
232                     copy_to_storage( Storage, M.format_result() );
233
234                     // Find range for a next match
235                     M=Finder( SearchIt, end(Input) );
236                 }
237
238                 // process the last segment
239                 InsertIt=process_segment( 
240                     Storage,
241                     Input,
242                     InsertIt,
243                     SearchIt,
244                     end(Input) );
245                 
246                 if ( Storage.empty() )
247                 {
248                     // Truncate input
249                     erase( Input, InsertIt, end(Input) );
250                 }
251                 else
252                 {
253                     // Copy remaining data to the end of input
254                     insert( Input, end(Input), Storage.begin(), Storage.end() );
255                 }
256             }
257
258         } // namespace detail
259     } // namespace algorithm
260 } // namespace boost
261
262 #endif  // BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP