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