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