1 // Boost string_algo library find_format.hpp header file ---------------------------//
3 // Copyright Pavol Droba 2002-2003.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/ for updates, documentation, and revision history.
11 #ifndef BOOST_STRING_FIND_FORMAT_HPP
12 #define BOOST_STRING_FIND_FORMAT_HPP
15 #include <boost/detail/iterator.hpp>
16 #include <boost/range/iterator_range_core.hpp>
17 #include <boost/range/begin.hpp>
18 #include <boost/range/end.hpp>
19 #include <boost/range/const_iterator.hpp>
20 #include <boost/range/as_literal.hpp>
22 #include <boost/algorithm/string/concept.hpp>
23 #include <boost/algorithm/string/detail/find_format.hpp>
24 #include <boost/algorithm/string/detail/find_format_all.hpp>
27 Defines generic replace algorithms. Each algorithm replaces
28 part(s) of the input. The part to be replaced is looked up using a Finder object.
29 Result of finding is then used by a Formatter object to generate the replacement.
35 // generic replace -----------------------------------------------------------------//
37 //! Generic replace algorithm
39 Use the Finder to search for a substring. Use the Formatter to format
40 this substring and replace it in the input.
41 The result is a modified copy of the input. It is returned as a sequence
42 or copied to the output iterator.
44 \param Output An output iterator to which the result will be copied
45 \param Input An input sequence
46 \param Finder A Finder object used to search for a match to be replaced
47 \param Formatter A Formatter object used to format a match
48 \return An output iterator pointing just after the last inserted character or
49 a modified copy of the input
51 \note The second variant of this function provides the strong exception-safety guarantee
54 typename OutputIteratorT,
58 inline OutputIteratorT find_format_copy(
59 OutputIteratorT Output,
62 FormatterT Formatter )
65 BOOST_CONCEPT_ASSERT((
68 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
70 BOOST_CONCEPT_ASSERT((
73 FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
76 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
78 return detail::find_format_copy_impl(
82 Finder( ::boost::begin(lit_input), ::boost::end(lit_input) ) );
85 //! Generic replace algorithm
93 inline SequenceT find_format_copy(
94 const SequenceT& Input,
96 FormatterT Formatter )
99 BOOST_CONCEPT_ASSERT((
102 BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
104 BOOST_CONCEPT_ASSERT((
107 FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
110 return detail::find_format_copy_impl(
113 Finder(::boost::begin(Input), ::boost::end(Input)));
116 //! Generic replace algorithm
118 Use the Finder to search for a substring. Use the Formatter to format
119 this substring and replace it in the input. The input is modified in-place.
121 \param Input An input sequence
122 \param Finder A Finder object used to search for a match to be replaced
123 \param Formatter A Formatter object used to format a match
129 inline void find_format(
132 FormatterT Formatter)
135 BOOST_CONCEPT_ASSERT((
138 BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
140 BOOST_CONCEPT_ASSERT((
143 FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
146 detail::find_format_impl(
149 Finder(::boost::begin(Input), ::boost::end(Input)));
153 // find_format_all generic ----------------------------------------------------------------//
155 //! Generic replace all algorithm
157 Use the Finder to search for a substring. Use the Formatter to format
158 this substring and replace it in the input. Repeat this for all matching
160 The result is a modified copy of the input. It is returned as a sequence
161 or copied to the output iterator.
163 \param Output An output iterator to which the result will be copied
164 \param Input An input sequence
165 \param Finder A Finder object used to search for a match to be replaced
166 \param Formatter A Formatter object used to format a match
167 \return An output iterator pointing just after the last inserted character or
168 a modified copy of the input
170 \note The second variant of this function provides the strong exception-safety guarantee
173 typename OutputIteratorT,
177 inline OutputIteratorT find_format_all_copy(
178 OutputIteratorT Output,
181 FormatterT Formatter)
184 BOOST_CONCEPT_ASSERT((
187 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
189 BOOST_CONCEPT_ASSERT((
192 FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
195 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
197 return detail::find_format_all_copy_impl(
202 Finder(::boost::begin(lit_input), ::boost::end(lit_input)));
205 //! Generic replace all algorithm
212 typename FormatterT >
213 inline SequenceT find_format_all_copy(
214 const SequenceT& Input,
216 FormatterT Formatter )
219 BOOST_CONCEPT_ASSERT((
222 BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
224 BOOST_CONCEPT_ASSERT((
227 FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
230 return detail::find_format_all_copy_impl(
234 Finder( ::boost::begin(Input), ::boost::end(Input) ) );
237 //! Generic replace all algorithm
239 Use the Finder to search for a substring. Use the Formatter to format
240 this substring and replace it in the input. Repeat this for all matching
241 substrings.The input is modified in-place.
243 \param Input An input sequence
244 \param Finder A Finder object used to search for a match to be replaced
245 \param Formatter A Formatter object used to format a match
250 typename FormatterT >
251 inline void find_format_all(
254 FormatterT Formatter )
257 BOOST_CONCEPT_ASSERT((
260 BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
262 BOOST_CONCEPT_ASSERT((
265 FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
268 detail::find_format_all_impl(
272 Finder(::boost::begin(Input), ::boost::end(Input)));
276 } // namespace algorithm
278 // pull the names to the boost namespace
279 using algorithm::find_format_copy;
280 using algorithm::find_format;
281 using algorithm::find_format_all_copy;
282 using algorithm::find_format_all;
287 #endif // BOOST_STRING_FIND_FORMAT_HPP