Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72380 - in branches/release: boost/algorithm/string boost/algorithm/string/detail libs/algorithm/string/test
From: droba_at_[hidden]
Date: 2011-06-03 17:13:38


Author: pavol_droba
Date: 2011-06-03 17:13:37 EDT (Fri, 03 Jun 2011)
New Revision: 72380
URL: http://svn.boost.org/trac/boost/changeset/72380

Log:
merged from trunk

Added:
   branches/release/boost/algorithm/string/trim_all.hpp
      - copied unchanged from r72379, /trunk/boost/algorithm/string/trim_all.hpp
Properties modified:
   branches/release/boost/algorithm/string/ (props changed)
Text files modified:
   branches/release/boost/algorithm/string/detail/formatter.hpp | 25 +++++++++++
   branches/release/boost/algorithm/string/formatter.hpp | 23 +++++++++-
   branches/release/libs/algorithm/string/test/replace_test.cpp | 21 +++++++++
   branches/release/libs/algorithm/string/test/trim_test.cpp | 88 +++++++++++++++++++++++++++++++++++++++
   4 files changed, 153 insertions(+), 4 deletions(-)

Modified: branches/release/boost/algorithm/string/detail/formatter.hpp
==============================================================================
--- branches/release/boost/algorithm/string/detail/formatter.hpp (original)
+++ branches/release/boost/algorithm/string/detail/formatter.hpp 2011-06-03 17:13:37 EDT (Fri, 03 Jun 2011)
@@ -87,6 +87,31 @@
                 }
             };
 
+// dissect format functor ----------------------------------------------------//
+
+ // dissect format functor
+ template<typename FinderT>
+ struct dissect_formatF
+ {
+ public:
+ // Construction
+ dissect_formatF(FinderT Finder) :
+ m_Finder(Finder) {}
+
+ // Operation
+ template<typename RangeT>
+ inline iterator_range<
+ BOOST_STRING_TYPENAME range_const_iterator<RangeT>::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

Modified: branches/release/boost/algorithm/string/formatter.hpp
==============================================================================
--- branches/release/boost/algorithm/string/formatter.hpp (original)
+++ branches/release/boost/algorithm/string/formatter.hpp 2011-06-03 17:13:37 EDT (Fri, 03 Jun 2011)
@@ -36,7 +36,7 @@
 
         //! 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 @@
 
         //! 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 @@
 
         //! 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 @@
                 BOOST_STRING_TYPENAME range_value<RangeT>::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<typename FinderT>
+ inline detail::dissect_formatF< FinderT >
+ dissect_formatter(const FinderT& Finder)
+ {
+ return detail::dissect_formatF<FinderT>(Finder);
+ }
+
 
     } // namespace algorithm
 
@@ -96,6 +112,7 @@
     using algorithm::const_formatter;
     using algorithm::identity_formatter;
     using algorithm::empty_formatter;
+ using algorithm::dissect_formatter;
 
 } // namespace boost
 

Modified: branches/release/libs/algorithm/string/test/replace_test.cpp
==============================================================================
--- branches/release/libs/algorithm/string/test/replace_test.cpp (original)
+++ branches/release/libs/algorithm/string/test/replace_test.cpp 2011-06-03 17:13:37 EDT (Fri, 03 Jun 2011)
@@ -11,6 +11,9 @@
 #include <boost/algorithm/string/erase.hpp>
 #include <boost/algorithm/string/std/list_traits.hpp>
 #include <boost/algorithm/string/std/string_traits.hpp>
+#include <boost/algorithm/string/finder.hpp>
+#include <boost/algorithm/string/formatter.hpp>
+#include <boost/algorithm/string/classification.hpp>
 
 // Include unit test framework
 #include <boost/test/included/test_exec_monitor.hpp>
@@ -285,6 +288,23 @@
     }
 }
 
+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 @@
     replace_tail_test();
     replace_range_test();
     collection_comp_test();
+ dissect_format_test();
 
     return 0;
 }

Modified: branches/release/libs/algorithm/string/test/trim_test.cpp
==============================================================================
--- branches/release/libs/algorithm/string/test/trim_test.cpp (original)
+++ branches/release/libs/algorithm/string/test/trim_test.cpp 2011-06-03 17:13:37 EDT (Fri, 03 Jun 2011)
@@ -8,6 +8,7 @@
 // See http://www.boost.org for updates, documentation, and revision history.
 
 #include <boost/algorithm/string/trim.hpp>
+#include <boost/algorithm/string/trim_all.hpp>
 
 // Include unit test framework
 #include <boost/test/included/test_exec_monitor.hpp>
@@ -109,10 +110,95 @@
     BOOST_CHECK( trim_copy_if( string("<>abc<>"), is_any_of( "<<>>" ) )=="abc" );
 }
 
+void trim_all_test()
+{
+ string str1(" 1x x x x1 ");
+ string str2("+---...2x+--x--+x-+-x2...---+");
+ string str3(" ");
+
+ // *** value passing tests *** //
+
+ // general string test
+ BOOST_CHECK( trim_all_copy( str1 )=="1x x x x1" ) ;
+ BOOST_CHECK( trim_all_copy_if( str2, is_punct() )=="2x+x-x-x2" ) ;
+
+ // spaces-only string test
+ BOOST_CHECK( trim_all_copy( str3 )=="" );
+
+ // empty string check
+ BOOST_CHECK( trim_all_copy( string("") )=="" );
+
+ // general string test
+ trim_all( str1 );
+ BOOST_CHECK( str1=="1x x x x1" ) ;
+ trim_all_if( str2, is_punct() );
+ BOOST_CHECK( str2=="2x+x-x-x2" ) ;
+
+ // spaces-only string test
+ str3 = " "; trim_all( str3 );
+ BOOST_CHECK( str3=="" );
+
+ // empty string check
+ str3 = ""; trim_all( str3 );
+ BOOST_CHECK( str3=="" );
+ BOOST_CHECK( str3=="" );
+
+ // *** non-standard predicate tests *** //
+ BOOST_CHECK(
+ trim_all_copy_if(
+ string("123abc127deb456"),
+ is_classified(std::ctype_base::digit) )=="abc1deb" );
+ BOOST_CHECK( trim_all_copy_if( string("<>abc<>def<>"), is_any_of( "<<>>" ) )=="abc<def" );
+}
+
+void trim_fill_test()
+{
+ string str1(" 1x x x x1 ");
+ string str2("+---...2x+--x--+x-+-x2...---+");
+ string str3(" ");
+
+ // *** value passing tests *** //
+
+ // general string test
+ BOOST_CHECK( trim_fill_copy( str1, "-" )=="1x-x-x-x1" ) ;
+ BOOST_CHECK( trim_fill_copy_if( str2, " ", is_punct() )=="2x x x x2" ) ;
+
+ // spaces-only string test
+ BOOST_CHECK( trim_fill_copy( str3, " " )=="" );
+
+ // empty string check
+ BOOST_CHECK( trim_fill_copy( string(""), " " )=="" );
+
+ // general string test
+ trim_fill( str1, "-" );
+ BOOST_CHECK( str1=="1x-x-x-x1" ) ;
+ trim_fill_if( str2, "", is_punct() );
+ BOOST_CHECK( str2=="2xxxx2" ) ;
+
+ // spaces-only string test
+ str3 = " "; trim_fill( str3, "" );
+ BOOST_CHECK( str3=="" );
+
+ // empty string check
+ str3 = ""; trim_fill( str3, "" );
+ BOOST_CHECK( str3=="" );
+ BOOST_CHECK( str3=="" );
+
+ // *** non-standard predicate tests *** //
+ BOOST_CHECK(
+ trim_fill_copy_if(
+ string("123abc127deb456"),
+ "+",
+ is_classified(std::ctype_base::digit) )=="abc+deb" );
+ BOOST_CHECK( trim_fill_copy_if( string("<>abc<>def<>"), "-", is_any_of( "<<>>" ) )=="abc-def" );
+}
+
 // test main
 int test_main( int, char*[] )
 {
     trim_test();
-
+ trim_all_test();
+ trim_fill_test();
+
     return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk