Chris@16
|
1 // Boost string_algo library formatter.hpp header file ---------------------------//
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright Pavol Droba 2002-2003.
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_STRING_FORMATTER_DETAIL_HPP
|
Chris@16
|
12 #define BOOST_STRING_FORMATTER_DETAIL_HPP
|
Chris@16
|
13
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/range/iterator_range_core.hpp>
|
Chris@16
|
16 #include <boost/range/begin.hpp>
|
Chris@16
|
17 #include <boost/range/end.hpp>
|
Chris@16
|
18 #include <boost/range/const_iterator.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #include <boost/algorithm/string/detail/util.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 // generic replace functors -----------------------------------------------//
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost {
|
Chris@16
|
25 namespace algorithm {
|
Chris@16
|
26 namespace detail {
|
Chris@16
|
27
|
Chris@16
|
28 // const format functor ----------------------------------------------------//
|
Chris@16
|
29
|
Chris@16
|
30 // constant format functor
|
Chris@16
|
31 template<typename RangeT>
|
Chris@16
|
32 struct const_formatF
|
Chris@16
|
33 {
|
Chris@16
|
34 private:
|
Chris@16
|
35 typedef BOOST_STRING_TYPENAME
|
Chris@16
|
36 range_const_iterator<RangeT>::type format_iterator;
|
Chris@16
|
37 typedef iterator_range<format_iterator> result_type;
|
Chris@16
|
38
|
Chris@16
|
39 public:
|
Chris@16
|
40 // Construction
|
Chris@16
|
41 const_formatF(const RangeT& Format) :
|
Chris@16
|
42 m_Format(::boost::begin(Format), ::boost::end(Format)) {}
|
Chris@16
|
43
|
Chris@16
|
44 // Operation
|
Chris@16
|
45 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
Chris@16
|
46 template<typename Range2T>
|
Chris@16
|
47 result_type& operator()(const Range2T&)
|
Chris@16
|
48 {
|
Chris@16
|
49 return m_Format;
|
Chris@16
|
50 }
|
Chris@16
|
51 #endif
|
Chris@16
|
52
|
Chris@16
|
53 template<typename Range2T>
|
Chris@16
|
54 const result_type& operator()(const Range2T&) const
|
Chris@16
|
55 {
|
Chris@16
|
56 return m_Format;
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 private:
|
Chris@16
|
60 result_type m_Format;
|
Chris@16
|
61 };
|
Chris@16
|
62
|
Chris@16
|
63 // identity format functor ----------------------------------------------------//
|
Chris@16
|
64
|
Chris@16
|
65 // identity format functor
|
Chris@16
|
66 template<typename RangeT>
|
Chris@16
|
67 struct identity_formatF
|
Chris@16
|
68 {
|
Chris@16
|
69 // Operation
|
Chris@16
|
70 template< typename Range2T >
|
Chris@16
|
71 const RangeT& operator()(const Range2T& Replace) const
|
Chris@16
|
72 {
|
Chris@16
|
73 return RangeT(::boost::begin(Replace), ::boost::end(Replace));
|
Chris@16
|
74 }
|
Chris@16
|
75 };
|
Chris@16
|
76
|
Chris@16
|
77 // empty format functor ( used by erase ) ------------------------------------//
|
Chris@16
|
78
|
Chris@16
|
79 // empty format functor
|
Chris@16
|
80 template< typename CharT >
|
Chris@16
|
81 struct empty_formatF
|
Chris@16
|
82 {
|
Chris@16
|
83 template< typename ReplaceT >
|
Chris@16
|
84 empty_container<CharT> operator()(const ReplaceT&) const
|
Chris@16
|
85 {
|
Chris@16
|
86 return empty_container<CharT>();
|
Chris@16
|
87 }
|
Chris@16
|
88 };
|
Chris@16
|
89
|
Chris@16
|
90 // dissect format functor ----------------------------------------------------//
|
Chris@16
|
91
|
Chris@16
|
92 // dissect format functor
|
Chris@16
|
93 template<typename FinderT>
|
Chris@16
|
94 struct dissect_formatF
|
Chris@16
|
95 {
|
Chris@16
|
96 public:
|
Chris@16
|
97 // Construction
|
Chris@16
|
98 dissect_formatF(FinderT Finder) :
|
Chris@16
|
99 m_Finder(Finder) {}
|
Chris@16
|
100
|
Chris@16
|
101 // Operation
|
Chris@16
|
102 template<typename RangeT>
|
Chris@16
|
103 inline iterator_range<
|
Chris@16
|
104 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
|
Chris@16
|
105 operator()(const RangeT& Replace) const
|
Chris@16
|
106 {
|
Chris@16
|
107 return m_Finder(::boost::begin(Replace), ::boost::end(Replace));
|
Chris@16
|
108 }
|
Chris@16
|
109
|
Chris@16
|
110 private:
|
Chris@16
|
111 FinderT m_Finder;
|
Chris@16
|
112 };
|
Chris@16
|
113
|
Chris@16
|
114
|
Chris@16
|
115 } // namespace detail
|
Chris@16
|
116 } // namespace algorithm
|
Chris@16
|
117 } // namespace boost
|
Chris@16
|
118
|
Chris@16
|
119 #endif // BOOST_STRING_FORMATTER_DETAIL_HPP
|