formatter_regex.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Boost string_algo library formatter_regex.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_REGEX_DETAIL_HPP
  9. #define BOOST_STRING_FORMATTER_REGEX_DETAIL_HPP
  10. #include <boost/algorithm/string/config.hpp>
  11. #include <string>
  12. #include <boost/regex.hpp>
  13. #include <boost/algorithm/string/detail/finder_regex.hpp>
  14. namespace boost {
  15. namespace algorithm {
  16. namespace detail {
  17. // regex format functor -----------------------------------------//
  18. // regex format functor
  19. template<typename StringT>
  20. struct regex_formatF
  21. {
  22. private:
  23. typedef StringT result_type;
  24. typedef BOOST_STRING_TYPENAME StringT::value_type char_type;
  25. public:
  26. // Construction
  27. regex_formatF( const StringT& Fmt, match_flag_type Flags=format_default ) :
  28. m_Fmt(Fmt), m_Flags( Flags ) {}
  29. template<typename InputIteratorT>
  30. result_type operator()(
  31. const regex_search_result<InputIteratorT>& Replace ) const
  32. {
  33. if ( Replace.empty() )
  34. {
  35. return result_type();
  36. }
  37. else
  38. {
  39. return Replace.match_results().format( m_Fmt, m_Flags );
  40. }
  41. }
  42. private:
  43. const StringT& m_Fmt;
  44. match_flag_type m_Flags;
  45. };
  46. } // namespace detail
  47. } // namespace algorithm
  48. } // namespace boost
  49. #endif // BOOST_STRING_FORMATTER_DETAIL_HPP