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_DETAIL_HPP
12
#define BOOST_STRING_FIND_FORMAT_DETAIL_HPP
14
#include <boost/algorithm/string/config.hpp>
15
#include <boost/range/iterator_range.hpp>
16
#include <boost/range/const_iterator.hpp>
17
#include <boost/range/iterator.hpp>
18
#include <boost/algorithm/string/detail/find_format_store.hpp>
19
#include <boost/algorithm/string/detail/replace_storage.hpp>
25
// find_format_copy (iterator variant) implementation -------------------------------//
28
typename OutputIteratorT,
32
typename FormatResultT >
33
inline OutputIteratorT find_format_copy_impl2(
34
OutputIteratorT Output,
37
const FindResultT& FindResult,
38
const FormatResultT& FormatResult )
40
typedef find_format_store<
42
range_const_iterator<InputT>::type,
44
FormatResultT > store_type;
46
// Create store for the find result
47
store_type M( FindResult, FormatResult, Formatter );
51
// Match not found - return original sequence
52
Output = std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
56
// Copy the beginning of the sequence
57
Output = std::copy( ::boost::begin(Input), ::boost::begin(M), Output );
59
// Copy formated result
60
Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
61
// Copy the rest of the sequence
62
Output = std::copy( M.end(), ::boost::end(Input), Output );
68
typename OutputIteratorT,
71
typename FindResultT >
72
inline OutputIteratorT find_format_copy_impl(
73
OutputIteratorT Output,
76
const FindResultT& FindResult )
78
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
79
return ::boost::algorithm::detail::find_format_copy_impl2(
84
Formatter(FindResult) );
86
return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
91
// find_format_copy implementation --------------------------------------------------//
97
typename FormatResultT >
98
inline InputT find_format_copy_impl2(
100
FormatterT Formatter,
101
const FindResultT& FindResult,
102
const FormatResultT& FormatResult)
104
typedef find_format_store<
105
BOOST_STRING_TYPENAME
106
range_const_iterator<InputT>::type,
108
FormatResultT > store_type;
110
// Create store for the find result
111
store_type M( FindResult, FormatResult, Formatter );
115
// Match not found - return original sequence
116
return InputT( Input );
120
// Copy the beginning of the sequence
121
insert( Output, ::boost::end(Output), ::boost::begin(Input), M.begin() );
122
// Copy formated result
123
insert( Output, ::boost::end(Output), M.format_result() );
124
// Copy the rest of the sequence
125
insert( Output, ::boost::end(Output), M.end(), ::boost::end(Input) );
133
typename FindResultT >
134
inline InputT find_format_copy_impl(
136
FormatterT Formatter,
137
const FindResultT& FindResult)
139
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
140
return ::boost::algorithm::detail::find_format_copy_impl2(
144
Formatter(FindResult) );
150
// replace implementation ----------------------------------------------------//
155
typename FindResultT,
156
typename FormatResultT >
157
inline void find_format_impl2(
159
FormatterT Formatter,
160
const FindResultT& FindResult,
161
const FormatResultT& FormatResult)
163
typedef find_format_store<
164
BOOST_STRING_TYPENAME
165
range_iterator<InputT>::type,
167
FormatResultT > store_type;
169
// Create store for the find result
170
store_type M( FindResult, FormatResult, Formatter );
174
// Search not found - return original sequence
179
::boost::algorithm::detail::replace( Input, M.begin(), M.end(), M.format_result() );
185
typename FindResultT >
186
inline void find_format_impl(
188
FormatterT Formatter,
189
const FindResultT& FindResult)
191
if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
192
::boost::algorithm::detail::find_format_impl2(
196
Formatter(FindResult) );
200
} // namespace detail
201
} // namespace algorithm
204
#endif // BOOST_STRING_FIND_FORMAT_DETAIL_HPP