source: NonGTP/Boost/boost/algorithm/string/find_format.hpp @ 857

Revision 857, 9.6 KB checked in by igarcia, 19 years ago (diff)
Line 
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_HPP
11#define BOOST_STRING_FIND_FORMAT_HPP
12
13#include <deque>
14#include <boost/detail/iterator.hpp>
15#include <boost/range/iterator_range.hpp>
16#include <boost/range/begin.hpp>
17#include <boost/range/end.hpp>
18#include <boost/range/const_iterator.hpp>
19
20#include <boost/algorithm/string/concept.hpp>
21#include <boost/algorithm/string/detail/find_format.hpp>
22#include <boost/algorithm/string/detail/find_format_all.hpp>
23
24/*! \file
25    Defines generic replace algorithms. Each algorithm replaces
26    part(s) of the input. The part to be replaced is looked up using a Finder object.
27    Result of finding is then used by a Formatter object to generate the replacement.
28*/
29
30namespace boost {
31    namespace algorithm {
32
33// generic replace  -----------------------------------------------------------------//
34
35        //! Generic replace algorithm
36        /*!
37            Use the Finder to search for a substring. Use the Formatter to format
38            this substring and replace it in the input.
39            The result is a modified copy of the input. It is returned as a sequence
40            or copied to the output iterator.
41   
42            \param Output An output iterator to which the result will be copied
43            \param Input An input sequence
44            \param Finder A Finder object used to search for a match to be replaced
45            \param Formatter A Formatter object used to format a match
46            \return An output iterator pointing just after the last inserted character or
47                a modified copy of the input
48
49            \note The second variant of this function provides the strong exception-safety guarantee
50        */
51        template<
52            typename OutputIteratorT,
53            typename RangeT,
54            typename FinderT,
55            typename FormatterT>
56        inline OutputIteratorT find_format_copy(
57            OutputIteratorT Output,
58            const RangeT& Input,
59            FinderT Finder,
60            FormatterT Formatter )
61        {
62            // Concept check
63            function_requires<
64                FinderConcept<FinderT,
65                BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >();
66            function_requires<
67                FormatterConcept<
68                    FormatterT,
69                    FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >();
70
71            return detail::find_format_copy_impl(
72                Output,
73                Input,
74                Finder,
75                Formatter,
76                Finder( begin(Input), end(Input) ) );
77        }
78
79        //! Generic replace algorithm
80        /*!
81            \overload
82        */
83        template<
84            typename SequenceT,
85            typename FinderT,
86            typename FormatterT>
87        inline SequenceT find_format_copy(
88            const SequenceT& Input,
89            FinderT Finder,
90            FormatterT Formatter )
91        {
92            // Concept check
93            function_requires<
94                FinderConcept<FinderT,
95                BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
96            function_requires<
97                FormatterConcept<
98                    FormatterT,
99                    FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
100
101            return detail::find_format_copy_impl(
102                Input,
103                Finder,
104                Formatter,
105                Finder(begin(Input), end(Input)));
106        }
107
108        //! Generic replace algorithm
109        /*!
110            Use the Finder to search for a substring. Use the Formatter to format
111            this substring and replace it in the input. The input is modified in-place.
112
113            \param Input An input sequence
114            \param Finder A Finder object used to search for a match to be replaced
115            \param Formatter A Formatter object used to format a match
116        */
117        template<
118            typename SequenceT,
119            typename FinderT,
120            typename FormatterT>
121        inline void find_format(
122            SequenceT& Input,
123            FinderT Finder,
124            FormatterT Formatter)
125        {
126            // Concept check
127            function_requires<
128                FinderConcept<FinderT,
129                BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
130            function_requires<
131                FormatterConcept<
132                    FormatterT,
133                    FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
134
135            detail::find_format_impl(
136                Input,
137                Finder,
138                Formatter,
139                Finder(begin(Input), end(Input)));
140        }
141
142
143//  find_format_all generic ----------------------------------------------------------------//
144
145        //! Generic replace all algorithm
146        /*!
147            Use the Finder to search for a substring. Use the Formatter to format
148            this substring and replace it in the input. Repeat this for all matching
149            substrings.
150            The result is a modified copy of the input. It is returned as a sequence
151            or copied to the output iterator.
152
153            \param Output An output iterator to which the result will be copied
154            \param Input An input sequence
155            \param Finder A Finder object used to search for a match to be replaced
156            \param Formatter A Formatter object used to format a match
157            \return An output iterator pointing just after the last inserted character or
158                a modified copy of the input
159
160             \note The second variant of this function provides the strong exception-safety guarantee
161        */
162        template<
163            typename OutputIteratorT,
164            typename RangeT,
165            typename FinderT,
166            typename FormatterT>
167        inline OutputIteratorT find_format_all_copy(
168            OutputIteratorT Output,
169            const RangeT& Input,
170            FinderT Finder,
171            FormatterT Formatter)
172        {
173            // Concept check
174            function_requires<
175                FinderConcept<FinderT,
176                BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >();
177            function_requires<
178                FormatterConcept<
179                    FormatterT,
180                    FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >();
181
182            return detail::find_format_all_copy_impl(
183                Output,
184                Input,
185                Finder,
186                Formatter,
187                Finder(begin(Input), end(Input)));
188        }
189
190        //! Generic replace all algorithm
191        /*!
192            \overload
193        */
194        template<
195            typename SequenceT,
196            typename FinderT,
197            typename FormatterT >
198        inline SequenceT find_format_all_copy(
199            const SequenceT& Input,
200            FinderT Finder,
201            FormatterT Formatter )
202        {
203            // Concept check
204            function_requires<
205                FinderConcept<FinderT,
206                BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
207            function_requires<
208                FormatterConcept<
209                    FormatterT,
210                    FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
211
212            return detail::find_format_all_copy_impl(
213                Input,
214                Finder,
215                Formatter,
216                Finder( begin(Input), end(Input) ) );
217        }
218
219        //! Generic replace all algorithm
220        /*!
221            Use the Finder to search for a substring. Use the Formatter to format
222            this substring and replace it in the input. Repeat this for all matching
223            substrings.The input is modified in-place.
224
225            \param Input An input sequence
226            \param Finder A Finder object used to search for a match to be replaced
227            \param Formatter A Formatter object used to format a match
228        */
229        template<
230            typename SequenceT,
231            typename FinderT,
232            typename FormatterT >
233        inline void find_format_all(
234            SequenceT& Input,
235            FinderT Finder,
236            FormatterT Formatter )
237        {
238            // Concept check
239            function_requires<
240                FinderConcept<FinderT,
241                BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
242            function_requires<
243                FormatterConcept<
244                    FormatterT,
245                    FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> >();
246
247            detail::find_format_all_impl(
248                Input,
249                Finder,
250                Formatter,
251                Finder(begin(Input), end(Input)));
252
253        }
254
255    } // namespace algorithm
256
257    // pull the names to the boost namespace
258    using algorithm::find_format_copy;
259    using algorithm::find_format;
260    using algorithm::find_format_all_copy;
261    using algorithm::find_format_all;
262
263} // namespace boost
264
265
266#endif  // BOOST_STRING_FIND_FORMAT_HPP
Note: See TracBrowser for help on using the repository browser.