]> git.lyx.org Git - lyx.git/blob - boost/boost/regex/v4/regex_replace.hpp
update boost to version 1.36
[lyx.git] / boost / boost / regex / v4 / regex_replace.hpp
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_MSVC
28 #pragma warning(push)
29 #pragma warning(disable: 4103)
30 #endif
31 #ifdef BOOST_HAS_ABI_HEADERS
32 #  include BOOST_ABI_PREFIX
33 #endif
34 #ifdef BOOST_MSVC
35 #pragma warning(pop)
36 #endif
37
38 template <class OutputIterator, class BidirectionalIterator, class traits, class charT>
39 OutputIterator regex_replace(OutputIterator out,
40                          BidirectionalIterator first,
41                          BidirectionalIterator last,
42                          const basic_regex<charT, traits>& e, 
43                          const charT* fmt, 
44                          match_flag_type flags = match_default)
45 {
46    regex_iterator<BidirectionalIterator, charT, traits> i(first, last, e, flags);
47    regex_iterator<BidirectionalIterator, charT, traits> j;
48    if(i == j)
49    {
50       if(!(flags & regex_constants::format_no_copy))
51          out = re_detail::copy(first, last, out);
52    }
53    else
54    {
55       BidirectionalIterator last_m(first);
56       while(i != j)
57       {
58          if(!(flags & regex_constants::format_no_copy))
59             out = re_detail::copy(i->prefix().first, i->prefix().second, out); 
60          out = i->format(out, fmt, flags, e);
61          last_m = (*i)[0].second;
62          if(flags & regex_constants::format_first_only)
63             break;
64          ++i;
65       }
66       if(!(flags & regex_constants::format_no_copy))
67          out = re_detail::copy(last_m, last, out);
68    }
69    return out;
70 }
71
72 template <class OutputIterator, class Iterator, class traits, class charT>
73 inline OutputIterator regex_replace(OutputIterator out,
74                          Iterator first,
75                          Iterator last,
76                          const basic_regex<charT, traits>& e, 
77                          const std::basic_string<charT>& fmt,
78                          match_flag_type flags = match_default)
79 {
80    return regex_replace(out, first, last, e, fmt.c_str(), flags);
81 }
82
83 template <class traits, class charT>
84 std::basic_string<charT> regex_replace(const std::basic_string<charT>& s,
85                          const basic_regex<charT, traits>& e, 
86                          const charT* fmt,
87                          match_flag_type flags = match_default)
88 {
89    std::basic_string<charT> result;
90    re_detail::string_out_iterator<std::basic_string<charT> > i(result);
91    regex_replace(i, s.begin(), s.end(), e, fmt, flags);
92    return result;
93 }
94
95 template <class traits, class charT>
96 std::basic_string<charT> regex_replace(const std::basic_string<charT>& s,
97                          const basic_regex<charT, traits>& e, 
98                          const std::basic_string<charT>& fmt,
99                          match_flag_type flags = match_default)
100 {
101    std::basic_string<charT> result;
102    re_detail::string_out_iterator<std::basic_string<charT> > i(result);
103    regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
104    return result;
105 }
106
107 #ifdef BOOST_MSVC
108 #pragma warning(push)
109 #pragma warning(disable: 4103)
110 #endif
111 #ifdef BOOST_HAS_ABI_HEADERS
112 #  include BOOST_ABI_SUFFIX
113 #endif
114 #ifdef BOOST_MSVC
115 #pragma warning(pop)
116 #endif
117
118 } // namespace boost
119
120 #endif  // BOOST_REGEX_V4_REGEX_REPLACE_HPP
121
122