|
1 // 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_HPP |
|
12 #define BOOST_STRING_FORMATTER_HPP |
|
13 |
|
14 #include <boost/detail/iterator.hpp> |
|
15 #include <boost/range/value_type.hpp> |
|
16 #include <boost/range/iterator_range.hpp> |
|
17 #include <boost/range/as_literal.hpp> |
|
18 |
|
19 #include <boost/algorithm/string/detail/formatter.hpp> |
|
20 |
|
21 /*! \file |
|
22 Defines Formatter generators. Formatter is a functor which formats |
|
23 a string according to given parameters. A Formatter works |
|
24 in conjunction with a Finder. A Finder can provide additional information |
|
25 for a specific Formatter. An example of such a cooperation is regex_finder |
|
26 and regex_formatter. |
|
27 |
|
28 Formatters are used as pluggable components for replace facilities. |
|
29 This header contains generator functions for the Formatters provided in this library. |
|
30 */ |
|
31 |
|
32 namespace boost { |
|
33 namespace algorithm { |
|
34 |
|
35 // generic formatters ---------------------------------------------------------------// |
|
36 |
|
37 //! Constant formatter |
|
38 /*! |
|
39 Construct the \c const_formatter. Const formatter always returns |
|
40 the same value, regardless of the parameter. |
|
41 |
|
42 \param Format A predefined value used as a result for formating |
|
43 \return An instance of the \c const_formatter object. |
|
44 */ |
|
45 template<typename RangeT> |
|
46 inline detail::const_formatF< |
|
47 iterator_range< |
|
48 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> > |
|
49 const_formatter(const RangeT& Format) |
|
50 { |
|
51 return detail::const_formatF< |
|
52 iterator_range< |
|
53 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(as_literal(Format)); |
|
54 } |
|
55 |
|
56 //! Identity formatter |
|
57 /*! |
|
58 Construct the \c identity_formatter. Identity formatter always returns |
|
59 the parameter. |
|
60 |
|
61 \return An instance of the \c identity_formatter object. |
|
62 */ |
|
63 template<typename RangeT> |
|
64 inline detail::identity_formatF< |
|
65 iterator_range< |
|
66 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> > |
|
67 identity_formatter() |
|
68 { |
|
69 return detail::identity_formatF< |
|
70 iterator_range< |
|
71 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(); |
|
72 } |
|
73 |
|
74 //! Empty formatter |
|
75 /*! |
|
76 Construct the \c empty_formatter. Empty formatter always returns an empty |
|
77 sequence. |
|
78 |
|
79 \param Input container used to select a correct value_type for the |
|
80 resulting empty_container<>. |
|
81 \return An instance of the \c empty_formatter object. |
|
82 */ |
|
83 template<typename RangeT> |
|
84 inline detail::empty_formatF< |
|
85 BOOST_STRING_TYPENAME range_value<RangeT>::type> |
|
86 empty_formatter(const RangeT&) |
|
87 { |
|
88 return detail::empty_formatF< |
|
89 BOOST_STRING_TYPENAME range_value<RangeT>::type>(); |
|
90 } |
|
91 |
|
92 |
|
93 } // namespace algorithm |
|
94 |
|
95 // pull the names to the boost namespace |
|
96 using algorithm::const_formatter; |
|
97 using algorithm::identity_formatter; |
|
98 using algorithm::empty_formatter; |
|
99 |
|
100 } // namespace boost |
|
101 |
|
102 |
|
103 #endif // BOOST_FORMATTER_HPP |