1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 1998-2002 |
---|
4 | * John Maddock |
---|
5 | * |
---|
6 | * Use, modification and distribution are subject to the |
---|
7 | * Boost Software License, Version 1.0. (See accompanying file |
---|
8 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
9 | * |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * LOCATION: see http://www.boost.org for most recent version. |
---|
14 | * FILE regex_format.hpp |
---|
15 | * VERSION see <boost/version.hpp> |
---|
16 | * DESCRIPTION: Provides formatting output routines for search and replace |
---|
17 | * operations. Note this is an internal header file included |
---|
18 | * by regex.hpp, do not include on its own. |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef BOOST_REGEX_V4_REGEX_REPLACE_HPP |
---|
22 | #define BOOST_REGEX_V4_REGEX_REPLACE_HPP |
---|
23 | |
---|
24 | |
---|
25 | namespace boost{ |
---|
26 | |
---|
27 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
28 | # include BOOST_ABI_PREFIX |
---|
29 | #endif |
---|
30 | |
---|
31 | template <class OutputIterator, class BidirectionalIterator, class traits, class charT> |
---|
32 | OutputIterator regex_replace(OutputIterator out, |
---|
33 | BidirectionalIterator first, |
---|
34 | BidirectionalIterator last, |
---|
35 | const basic_regex<charT, traits>& e, |
---|
36 | const charT* fmt, |
---|
37 | match_flag_type flags = match_default) |
---|
38 | { |
---|
39 | regex_iterator<BidirectionalIterator, charT, traits> i(first, last, e, flags); |
---|
40 | regex_iterator<BidirectionalIterator, charT, traits> j; |
---|
41 | if(i == j) |
---|
42 | { |
---|
43 | if(!(flags & regex_constants::format_no_copy)) |
---|
44 | out = re_detail::copy(first, last, out); |
---|
45 | } |
---|
46 | else |
---|
47 | { |
---|
48 | BidirectionalIterator last_m(first); |
---|
49 | while(i != j) |
---|
50 | { |
---|
51 | if(!(flags & regex_constants::format_no_copy)) |
---|
52 | out = re_detail::copy(i->prefix().first, i->prefix().second, out); |
---|
53 | out = i->format(out, fmt, flags, e); |
---|
54 | last_m = (*i)[0].second; |
---|
55 | if(flags & regex_constants::format_first_only) |
---|
56 | break; |
---|
57 | ++i; |
---|
58 | } |
---|
59 | if(!(flags & regex_constants::format_no_copy)) |
---|
60 | out = re_detail::copy(last_m, last, out); |
---|
61 | } |
---|
62 | return out; |
---|
63 | } |
---|
64 | |
---|
65 | template <class OutputIterator, class Iterator, class traits, class charT> |
---|
66 | inline OutputIterator regex_replace(OutputIterator out, |
---|
67 | Iterator first, |
---|
68 | Iterator last, |
---|
69 | const basic_regex<charT, traits>& e, |
---|
70 | const std::basic_string<charT>& fmt, |
---|
71 | match_flag_type flags = match_default) |
---|
72 | { |
---|
73 | return regex_replace(out, first, last, e, fmt.c_str(), flags); |
---|
74 | } |
---|
75 | |
---|
76 | template <class traits, class charT> |
---|
77 | std::basic_string<charT> regex_replace(const std::basic_string<charT>& s, |
---|
78 | const basic_regex<charT, traits>& e, |
---|
79 | const charT* fmt, |
---|
80 | match_flag_type flags = match_default) |
---|
81 | { |
---|
82 | std::basic_string<charT> result; |
---|
83 | re_detail::string_out_iterator<std::basic_string<charT> > i(result); |
---|
84 | regex_replace(i, s.begin(), s.end(), e, fmt, flags); |
---|
85 | return result; |
---|
86 | } |
---|
87 | |
---|
88 | template <class traits, class charT> |
---|
89 | std::basic_string<charT> regex_replace(const std::basic_string<charT>& s, |
---|
90 | const basic_regex<charT, traits>& e, |
---|
91 | const std::basic_string<charT>& fmt, |
---|
92 | match_flag_type flags = match_default) |
---|
93 | { |
---|
94 | std::basic_string<charT> result; |
---|
95 | re_detail::string_out_iterator<std::basic_string<charT> > i(result); |
---|
96 | regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags); |
---|
97 | return result; |
---|
98 | } |
---|
99 | |
---|
100 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
101 | # include BOOST_ABI_SUFFIX |
---|
102 | #endif |
---|
103 | |
---|
104 | } // namespace boost |
---|
105 | |
---|
106 | #endif // BOOST_REGEX_V4_REGEX_REPLACE_HPP |
---|
107 | |
---|
108 | |
---|