From 9d25072f2fe5de2893fae60161fb7fdcea33316a Mon Sep 17 00:00:00 2001 From: Pavol Droba Date: Thu, 13 Jan 2011 21:21:37 +0000 Subject: [PATCH] dissect formatter and tests added [SVN r68124] --- .../algorithm/string/detail/formatter.hpp | 25 +++++++++++++++++++ include/boost/algorithm/string/formatter.hpp | 23 ++++++++++++++--- string/test/replace_test.cpp | 21 ++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/include/boost/algorithm/string/detail/formatter.hpp b/include/boost/algorithm/string/detail/formatter.hpp index bd6a780..72a351a 100644 --- a/include/boost/algorithm/string/detail/formatter.hpp +++ b/include/boost/algorithm/string/detail/formatter.hpp @@ -87,6 +87,31 @@ namespace boost { } }; +// dissect format functor ----------------------------------------------------// + + // dissect format functor + template + struct dissect_formatF + { + public: + // Construction + dissect_formatF(FinderT Finder) : + m_Finder(Finder) {} + + // Operation + template + inline iterator_range< + BOOST_STRING_TYPENAME range_const_iterator::type> + operator()(const RangeT& Replace) const + { + return m_Finder(::boost::begin(Replace), ::boost::end(Replace)); + } + + private: + FinderT m_Finder; + }; + + } // namespace detail } // namespace algorithm } // namespace boost diff --git a/include/boost/algorithm/string/formatter.hpp b/include/boost/algorithm/string/formatter.hpp index 50006df..1fcfefa 100644 --- a/include/boost/algorithm/string/formatter.hpp +++ b/include/boost/algorithm/string/formatter.hpp @@ -36,7 +36,7 @@ namespace boost { //! Constant formatter /*! - Construct the \c const_formatter. Const formatter always returns + Constructs a \c const_formatter. Const formatter always returns the same value, regardless of the parameter. \param Format A predefined value used as a result for formating @@ -55,7 +55,7 @@ namespace boost { //! Identity formatter /*! - Construct the \c identity_formatter. Identity formatter always returns + Constructs an \c identity_formatter. Identity formatter always returns the parameter. \return An instance of the \c identity_formatter object. @@ -73,7 +73,7 @@ namespace boost { //! Empty formatter /*! - Construct the \c empty_formatter. Empty formatter always returns an empty + Constructs an \c empty_formatter. Empty formatter always returns an empty sequence. \param Input container used to select a correct value_type for the @@ -89,6 +89,22 @@ namespace boost { BOOST_STRING_TYPENAME range_value::type>(); } + //! Empty formatter + /*! + Constructs a \c dissect_formatter. Dissect formatter uses a specified finder + to extract a portion of the formatted sequence. The first finder's match is returned + as a result + + \param Finder a finder used to select a portion of the formated sequence + \return An instance of the \c dissect_formatter object. + */ + template + inline detail::dissect_formatF< FinderT > + dissect_formatter(const FinderT& Finder) + { + return detail::dissect_formatF(Finder); + } + } // namespace algorithm @@ -96,6 +112,7 @@ namespace boost { using algorithm::const_formatter; using algorithm::identity_formatter; using algorithm::empty_formatter; + using algorithm::dissect_formatter; } // namespace boost diff --git a/string/test/replace_test.cpp b/string/test/replace_test.cpp index f9239f6..9d335e4 100644 --- a/string/test/replace_test.cpp +++ b/string/test/replace_test.cpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include // Include unit test framework #include @@ -285,6 +288,23 @@ void collection_comp_test() } } +void dissect_format_test() +{ + BOOST_CHECK( + find_format_all_copy( + string("aBc123Abc"), + first_finder("abc", is_iequal()), + dissect_formatter(token_finder(is_upper())))=="B123A"); + + + BOOST_CHECK( + find_format_all_copy( + string("abc 123 abc"), + token_finder(is_space(), token_compress_on), + dissect_formatter(head_finder(1)))=="abc 123 abc"); + +} + // test main int test_main( int, char*[] ) { @@ -297,6 +317,7 @@ int test_main( int, char*[] ) replace_tail_test(); replace_range_test(); collection_comp_test(); + dissect_format_test(); return 0; }