formatter.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Boost string_algo library formatter.hpp header file ---------------------------//
  2. // Copyright Pavol Droba 2002-2003.
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org/ for updates, documentation, and revision history.
  8. #ifndef BOOST_STRING_FORMATTER_HPP
  9. #define BOOST_STRING_FORMATTER_HPP
  10. #include <boost/detail/iterator.hpp>
  11. #include <boost/range/value_type.hpp>
  12. #include <boost/range/iterator_range_core.hpp>
  13. #include <boost/range/as_literal.hpp>
  14. #include <boost/algorithm/string/detail/formatter.hpp>
  15. /*! \file
  16. Defines Formatter generators. Formatter is a functor which formats
  17. a string according to given parameters. A Formatter works
  18. in conjunction with a Finder. A Finder can provide additional information
  19. for a specific Formatter. An example of such a cooperation is regex_finder
  20. and regex_formatter.
  21. Formatters are used as pluggable components for replace facilities.
  22. This header contains generator functions for the Formatters provided in this library.
  23. */
  24. namespace boost {
  25. namespace algorithm {
  26. // generic formatters ---------------------------------------------------------------//
  27. //! Constant formatter
  28. /*!
  29. Constructs a \c const_formatter. Const formatter always returns
  30. the same value, regardless of the parameter.
  31. \param Format A predefined value used as a result for formatting
  32. \return An instance of the \c const_formatter object.
  33. */
  34. template<typename RangeT>
  35. inline detail::const_formatF<
  36. iterator_range<
  37. BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >
  38. const_formatter(const RangeT& Format)
  39. {
  40. return detail::const_formatF<
  41. iterator_range<
  42. BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(::boost::as_literal(Format));
  43. }
  44. //! Identity formatter
  45. /*!
  46. Constructs an \c identity_formatter. Identity formatter always returns
  47. the parameter.
  48. \return An instance of the \c identity_formatter object.
  49. */
  50. template<typename RangeT>
  51. inline detail::identity_formatF<
  52. iterator_range<
  53. BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >
  54. identity_formatter()
  55. {
  56. return detail::identity_formatF<
  57. iterator_range<
  58. BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >();
  59. }
  60. //! Empty formatter
  61. /*!
  62. Constructs an \c empty_formatter. Empty formatter always returns an empty
  63. sequence.
  64. \param Input container used to select a correct value_type for the
  65. resulting empty_container<>.
  66. \return An instance of the \c empty_formatter object.
  67. */
  68. template<typename RangeT>
  69. inline detail::empty_formatF<
  70. BOOST_STRING_TYPENAME range_value<RangeT>::type>
  71. empty_formatter(const RangeT&)
  72. {
  73. return detail::empty_formatF<
  74. BOOST_STRING_TYPENAME range_value<RangeT>::type>();
  75. }
  76. //! Empty formatter
  77. /*!
  78. Constructs a \c dissect_formatter. Dissect formatter uses a specified finder
  79. to extract a portion of the formatted sequence. The first finder's match is returned
  80. as a result
  81. \param Finder a finder used to select a portion of the formatted sequence
  82. \return An instance of the \c dissect_formatter object.
  83. */
  84. template<typename FinderT>
  85. inline detail::dissect_formatF< FinderT >
  86. dissect_formatter(const FinderT& Finder)
  87. {
  88. return detail::dissect_formatF<FinderT>(Finder);
  89. }
  90. } // namespace algorithm
  91. // pull the names to the boost namespace
  92. using algorithm::const_formatter;
  93. using algorithm::identity_formatter;
  94. using algorithm::empty_formatter;
  95. using algorithm::dissect_formatter;
  96. } // namespace boost
  97. #endif // BOOST_FORMATTER_HPP