formatter.hpp 4.1 KB

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