formatter.hpp 3.7 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_DETAIL_HPP
  9. #define BOOST_STRING_FORMATTER_DETAIL_HPP
  10. #include <boost/range/iterator_range_core.hpp>
  11. #include <boost/range/begin.hpp>
  12. #include <boost/range/end.hpp>
  13. #include <boost/range/const_iterator.hpp>
  14. #include <boost/algorithm/string/detail/util.hpp>
  15. // generic replace functors -----------------------------------------------//
  16. namespace boost {
  17. namespace algorithm {
  18. namespace detail {
  19. // const format functor ----------------------------------------------------//
  20. // constant format functor
  21. template<typename RangeT>
  22. struct const_formatF
  23. {
  24. private:
  25. typedef BOOST_STRING_TYPENAME
  26. range_const_iterator<RangeT>::type format_iterator;
  27. typedef iterator_range<format_iterator> result_type;
  28. public:
  29. // Construction
  30. const_formatF(const RangeT& Format) :
  31. m_Format(::boost::begin(Format), ::boost::end(Format)) {}
  32. // Operation
  33. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  34. template<typename Range2T>
  35. result_type& operator()(const Range2T&)
  36. {
  37. return m_Format;
  38. }
  39. #endif
  40. template<typename Range2T>
  41. const result_type& operator()(const Range2T&) const
  42. {
  43. return m_Format;
  44. }
  45. private:
  46. result_type m_Format;
  47. };
  48. // identity format functor ----------------------------------------------------//
  49. // identity format functor
  50. template<typename RangeT>
  51. struct identity_formatF
  52. {
  53. // Operation
  54. template< typename Range2T >
  55. const RangeT& operator()(const Range2T& Replace) const
  56. {
  57. return RangeT(::boost::begin(Replace), ::boost::end(Replace));
  58. }
  59. };
  60. // empty format functor ( used by erase ) ------------------------------------//
  61. // empty format functor
  62. template< typename CharT >
  63. struct empty_formatF
  64. {
  65. template< typename ReplaceT >
  66. empty_container<CharT> operator()(const ReplaceT&) const
  67. {
  68. return empty_container<CharT>();
  69. }
  70. };
  71. // dissect format functor ----------------------------------------------------//
  72. // dissect format functor
  73. template<typename FinderT>
  74. struct dissect_formatF
  75. {
  76. public:
  77. // Construction
  78. dissect_formatF(FinderT Finder) :
  79. m_Finder(Finder) {}
  80. // Operation
  81. template<typename RangeT>
  82. inline iterator_range<
  83. BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
  84. operator()(const RangeT& Replace) const
  85. {
  86. return m_Finder(::boost::begin(Replace), ::boost::end(Replace));
  87. }
  88. private:
  89. FinderT m_Finder;
  90. };
  91. } // namespace detail
  92. } // namespace algorithm
  93. } // namespace boost
  94. #endif // BOOST_STRING_FORMATTER_DETAIL_HPP