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