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.hpp
1 //  Boost string_algo library find_format.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_DETAIL_HPP
11 #define BOOST_STRING_FIND_FORMAT_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/iterator.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_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_copy_impl(
33                 OutputIteratorT Output,
34                 const InputT& Input,
35                 FinderT Finder,
36                 FormatterT Formatter,
37                 const FindResultT& FindResult )
38             {       
39                 return find_format_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_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 find_format_store<
64                     BOOST_STRING_TYPENAME 
65                         range_const_iterator<InputT>::type, 
66                         FormatterT,
67                         FormatResultT > store_type;
68
69                 // Create store for the find result
70                 store_type M( FindResult, FormatResult, Formatter );
71
72                 if ( !M )
73                 {
74                     // Match not found - return original sequence
75                     std::copy( begin(Input), end(Input), Output );
76                     return Output;
77                 }
78
79                 // Copy the beginning of the sequence
80                 std::copy( begin(Input), begin(M), Output );
81                 // Format find result
82                 // Copy formated result
83                 std::copy( begin(M.format_result()), end(M.format_result()), Output );
84                 // Copy the rest of the sequence
85                 std::copy( M.end(), end(Input), Output );
86
87                 return Output;
88             }
89
90 // find_format_copy implementation --------------------------------------------------//
91
92             template< 
93                 typename InputT, 
94                 typename FinderT,
95                 typename FormatterT,
96                 typename FindResultT >
97             inline InputT find_format_copy_impl(
98                 const InputT& Input,
99                 FinderT Finder,
100                 FormatterT Formatter,
101                 const FindResultT& FindResult)
102             {
103                 return find_format_copy_impl2(
104                     Input,
105                     Finder,
106                     Formatter,
107                     FindResult,
108                     Formatter(FindResult) );
109             }
110
111             template< 
112                 typename InputT, 
113                 typename FinderT,
114                 typename FormatterT,
115                 typename FindResultT,
116                 typename FormatResultT >
117             inline InputT find_format_copy_impl2(
118                 const InputT& Input,
119                 FinderT Finder,
120                 FormatterT Formatter,
121                 const FindResultT& FindResult,
122                 const FormatResultT& FormatResult)
123             {
124                 typedef find_format_store<
125                     BOOST_STRING_TYPENAME 
126                         range_const_iterator<InputT>::type, 
127                         FormatterT,
128                         FormatResultT > store_type;
129
130                 // Create store for the find result
131                 store_type M( FindResult, FormatResult, Formatter );
132
133                 if ( !M )
134                 {
135                     // Match not found - return original sequence
136                     return InputT( Input );
137                 }
138
139                 InputT Output;
140                 // Copy the beginning of the sequence
141                 insert( Output, end(Output), begin(Input), M.begin() );
142                 // Copy formated result
143                 insert( Output, end(Output), M.format_result() );
144                 // Copy the rest of the sequence
145                 insert( Output, end(Output), M.end(), end(Input) );
146
147                 return Output;
148             }
149
150 // replace implementation ----------------------------------------------------//
151         
152             template<
153                 typename InputT,
154                 typename FinderT,
155                 typename FormatterT,
156                 typename FindResultT >
157             inline void find_format_impl( 
158                 InputT& Input,
159                 FinderT Finder,
160                 FormatterT Formatter,
161                 const FindResultT& FindResult)
162             {
163                 find_format_impl2(
164                     Input,
165                     Finder,
166                     Formatter,
167                     FindResult,
168                     Formatter(FindResult) );
169             }
170
171             template<
172                 typename InputT,
173                 typename FinderT,
174                 typename FormatterT,
175                 typename FindResultT,
176                 typename FormatResultT >
177             inline void find_format_impl2( 
178                 InputT& Input,
179                 FinderT,
180                 FormatterT Formatter,
181                 const FindResultT& FindResult,
182                 const FormatResultT& FormatResult)
183             {
184                 typedef find_format_store<
185                     BOOST_STRING_TYPENAME 
186                         range_iterator<InputT>::type, 
187                         FormatterT,
188                         FormatResultT > store_type;
189
190                 // Create store for the find result
191                 store_type M( FindResult, FormatResult, Formatter );
192
193                 if ( !M )
194                 {
195                     // Search not found - return original sequence
196                     return;
197                 }
198
199                 // Replace match
200                 replace( Input, M.begin(), M.end(), M.format_result() );
201             }
202
203         } // namespace detail
204     } // namespace algorithm
205 } // namespace boost
206
207 #endif  // BOOST_STRING_FIND_FORMAT_DETAIL_HPP