From 01492a93c69ae15a402cb15e128ea2171c878923 Mon Sep 17 00:00:00 2001 From: Pavol Droba Date: Mon, 10 Jan 2011 19:36:38 +0000 Subject: [PATCH] trunk changes merged [SVN r67922] --- .../algorithm/string/detail/find_format.hpp | 40 ++++++++-------- .../string/detail/find_format_all.hpp | 46 +++++++++---------- .../string/detail/find_format_store.hpp | 2 +- .../boost/algorithm/string/find_iterator.hpp | 12 ++++- string/test/split_test.cpp | 20 ++++++++ 5 files changed, 74 insertions(+), 46 deletions(-) diff --git a/include/boost/algorithm/string/detail/find_format.hpp b/include/boost/algorithm/string/detail/find_format.hpp index 7f5f780..8b9ad42 100644 --- a/include/boost/algorithm/string/detail/find_format.hpp +++ b/include/boost/algorithm/string/detail/find_format.hpp @@ -74,17 +74,17 @@ namespace boost { const InputT& Input, FormatterT Formatter, const FindResultT& FindResult ) - { + { if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { - return ::boost::algorithm::detail::find_format_copy_impl2( - Output, - Input, - Formatter, - FindResult, - Formatter(FindResult) ); + return ::boost::algorithm::detail::find_format_copy_impl2( + Output, + Input, + Formatter, + FindResult, + Formatter(FindResult) ); } else { return std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); - } + } } @@ -137,14 +137,14 @@ namespace boost { const FindResultT& FindResult) { if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { - return ::boost::algorithm::detail::find_format_copy_impl2( - Input, - Formatter, - FindResult, - Formatter(FindResult) ); + return ::boost::algorithm::detail::find_format_copy_impl2( + Input, + Formatter, + FindResult, + Formatter(FindResult) ); } else { return Input; - } + } } // replace implementation ----------------------------------------------------// @@ -189,12 +189,12 @@ namespace boost { const FindResultT& FindResult) { if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { - ::boost::algorithm::detail::find_format_impl2( - Input, - Formatter, - FindResult, - Formatter(FindResult) ); - } + ::boost::algorithm::detail::find_format_impl2( + Input, + Formatter, + FindResult, + Formatter(FindResult) ); + } } } // namespace detail diff --git a/include/boost/algorithm/string/detail/find_format_all.hpp b/include/boost/algorithm/string/detail/find_format_all.hpp index 0f184a3..978710c 100644 --- a/include/boost/algorithm/string/detail/find_format_all.hpp +++ b/include/boost/algorithm/string/detail/find_format_all.hpp @@ -84,18 +84,18 @@ namespace boost { FinderT Finder, FormatterT Formatter, const FindResultT& FindResult ) - { + { if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { - return ::boost::algorithm::detail::find_format_all_copy_impl2( - Output, - Input, - Finder, - Formatter, - FindResult, - Formatter(FindResult) ); + return ::boost::algorithm::detail::find_format_all_copy_impl2( + Output, + Input, + Finder, + Formatter, + FindResult, + Formatter(FindResult) ); } else { return std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); - } + } } // find_format_all_copy implementation ----------------------------------------------// @@ -161,15 +161,15 @@ namespace boost { const FindResultT& FindResult) { if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { - return ::boost::algorithm::detail::find_format_all_copy_impl2( - Input, - Finder, - Formatter, - FindResult, - Formatter(FindResult) ); + return ::boost::algorithm::detail::find_format_all_copy_impl2( + Input, + Finder, + Formatter, + FindResult, + Formatter(FindResult) ); } else { return Input; - } + } } // find_format_all implementation ------------------------------------------------// @@ -257,13 +257,13 @@ namespace boost { FindResultT FindResult) { if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { - ::boost::algorithm::detail::find_format_all_impl2( - Input, - Finder, - Formatter, - FindResult, - Formatter(FindResult) ); - } + ::boost::algorithm::detail::find_format_all_impl2( + Input, + Finder, + Formatter, + FindResult, + Formatter(FindResult) ); + } } } // namespace detail diff --git a/include/boost/algorithm/string/detail/find_format_store.hpp b/include/boost/algorithm/string/detail/find_format_store.hpp index 4872c5a..e8bd84a 100644 --- a/include/boost/algorithm/string/detail/find_format_store.hpp +++ b/include/boost/algorithm/string/detail/find_format_store.hpp @@ -53,7 +53,7 @@ namespace boost { { iterator_range::operator=(FindResult); if( !this->empty() ) { - m_FormatResult=m_Formatter(FindResult); + m_FormatResult=m_Formatter(FindResult); } return *this; diff --git a/include/boost/algorithm/string/find_iterator.hpp b/include/boost/algorithm/string/find_iterator.hpp index 72696c7..b72ba7c 100644 --- a/include/boost/algorithm/string/find_iterator.hpp +++ b/include/boost/algorithm/string/find_iterator.hpp @@ -259,7 +259,11 @@ namespace boost { m_End(End), m_bEof(false) { - increment(); + // force the correct behavior for empty sequences and yield at least one token + if(Begin!=End) + { + increment(); + } } //! Constructor /*! @@ -278,7 +282,11 @@ namespace boost { m_Next=::boost::begin(lit_col); m_End=::boost::end(lit_col); - increment(); + // force the correct behavior for empty sequences and yield at least one token + if(m_Next!=m_End) + { + increment(); + } } diff --git a/string/test/split_test.cpp b/string/test/split_test.cpp index d85bce7..89d1083 100644 --- a/string/test/split_test.cpp +++ b/string/test/split_test.cpp @@ -40,6 +40,7 @@ void iterator_test() string str1("xx-abc--xx-abb"); string str2("Xx-abc--xX-abb-xx"); string str3("xx"); + string strempty(""); const char* pch1="xx-abc--xx-abb"; vector tokens; vector< vector > vtokens; @@ -123,6 +124,25 @@ void iterator_test() BOOST_CHECK( tokens[3]==string("xx") ); BOOST_CHECK( tokens[4]==string("abb") ); + split( + tokens, + str3, + is_any_of(","), + token_compress_off); + + BOOST_REQUIRE( tokens.size()==1 ); + BOOST_CHECK( tokens[0]==string("xx") ); + + split( + tokens, + strempty, + is_punct(), + token_compress_off); + + BOOST_REQUIRE( tokens.size()==1 ); + BOOST_CHECK( tokens[0]==string("") ); + + find_iterator fiter=make_find_iterator(str1, first_finder("xx")); BOOST_CHECK(equals(*fiter, "xx")); ++fiter;