formatter.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.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. Construct the \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 formating
  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> >(as_literal(Format));
  43. }
  44. //! Identity formatter
  45. /*!
  46. Construct the \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. Construct the \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. } // namespace algorithm
  77. // pull the names to the boost namespace
  78. using algorithm::const_formatter;
  79. using algorithm::identity_formatter;
  80. using algorithm::empty_formatter;
  81. } // namespace boost
  82. #endif // BOOST_FORMATTER_HPP