From bbd3220a1e99a09bb9106160bce13f2010b18701 Mon Sep 17 00:00:00 2001 From: Pavol Droba Date: Sat, 10 Jul 2010 20:29:03 +0000 Subject: [PATCH] Merging changes from trunk [SVN r63824] --- .../algorithm/string/detail/case_conv.hpp | 12 +- .../string/detail/classification.hpp | 24 +-- .../algorithm/string/detail/find_format.hpp | 18 +- .../string/detail/find_format_all.hpp | 16 +- .../string/detail/find_format_store.hpp | 11 ++ include/boost/algorithm/string/erase.hpp | 4 +- include/boost/algorithm/string/find.hpp | 2 +- .../boost/algorithm/string/find_iterator.hpp | 2 +- string/doc/external_concepts.html | 10 +- string/doc/string_algo.xml | 2 +- string/doc/usage.xml | 4 +- string/test/Jamfile.v2 | 6 + string/test/find_format_test.cpp | 163 ++++++++++++++++++ string/test/split_test.cpp | 1 + 14 files changed, 239 insertions(+), 36 deletions(-) create mode 100644 string/test/find_format_test.cpp diff --git a/include/boost/algorithm/string/detail/case_conv.hpp b/include/boost/algorithm/string/detail/case_conv.hpp index 3440c27..5b0064f 100644 --- a/include/boost/algorithm/string/detail/case_conv.hpp +++ b/include/boost/algorithm/string/detail/case_conv.hpp @@ -31,7 +31,7 @@ namespace boost { struct to_lowerF : public std::unary_function { // Constructor - to_lowerF( const std::locale& Loc ) : m_Loc( Loc ) {} + to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {} // Operation CharT operator ()( CharT Ch ) const @@ -39,11 +39,11 @@ namespace boost { #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) return std::tolower( Ch); #else - return std::tolower( Ch, m_Loc ); + return std::tolower( Ch, *m_Loc ); #endif } private: - const std::locale& m_Loc; + const std::locale* m_Loc; }; // a toupper functor @@ -51,7 +51,7 @@ namespace boost { struct to_upperF : public std::unary_function { // Constructor - to_upperF( const std::locale& Loc ) : m_Loc( Loc ) {} + to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {} // Operation CharT operator ()( CharT Ch ) const @@ -59,11 +59,11 @@ namespace boost { #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) return std::toupper( Ch); #else - return std::toupper( Ch, m_Loc ); + return std::toupper( Ch, *m_Loc ); #endif } private: - const std::locale& m_Loc; + const std::locale* m_Loc; }; #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) diff --git a/include/boost/algorithm/string/detail/classification.hpp b/include/boost/algorithm/string/detail/classification.hpp index 9a34bf0..fb43955 100644 --- a/include/boost/algorithm/string/detail/classification.hpp +++ b/include/boost/algorithm/string/detail/classification.hpp @@ -32,8 +32,8 @@ namespace boost { struct is_classifiedF : public predicate_facade { - // Boost.Lambda support - template struct sig { typedef bool type; }; + // Boost.ResultOf support + typedef bool result_type; // Constructor from a locale is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) : @@ -72,8 +72,8 @@ namespace boost { typedef typename ::boost::remove_const::type set_value_type; public: - // Boost.Lambda support - template struct sig { typedef bool type; }; + // Boost.ResultOf support + typedef bool result_type; // Constructor template @@ -253,8 +253,8 @@ namespace boost { struct is_from_rangeF : public predicate_facade< is_from_rangeF > { - // Boost.Lambda support - template struct sig { typedef bool type; }; + // Boost.ResultOf support + typedef bool result_type; // Constructor is_from_rangeF( CharT From, CharT To ) : m_From(From), m_To(To) {} @@ -278,8 +278,8 @@ namespace boost { { public: - // Boost.Lambda support - template struct sig { typedef bool type; }; + // Boost.ResultOf support + typedef bool result_type; // Constructor pred_andF( Pred1T Pred1, Pred2T Pred2 ) : @@ -303,8 +303,8 @@ namespace boost { public predicate_facade< pred_orF > { public: - // Boost.Lambda support - template struct sig { typedef bool type; }; + // Boost.ResultOf support + typedef bool result_type; // Constructor pred_orF( Pred1T Pred1, Pred2T Pred2 ) : @@ -328,8 +328,8 @@ namespace boost { public predicate_facade< pred_notF > { public: - // Boost.Lambda support - template struct sig { typedef bool type; }; + // Boost.ResultOf support + typedef bool result_type; // Constructor pred_notF( PredT Pred ) : m_Pred(Pred) {} diff --git a/include/boost/algorithm/string/detail/find_format.hpp b/include/boost/algorithm/string/detail/find_format.hpp index 0d8b104..7f5f780 100644 --- a/include/boost/algorithm/string/detail/find_format.hpp +++ b/include/boost/algorithm/string/detail/find_format.hpp @@ -49,17 +49,17 @@ namespace boost { if ( !M ) { // Match not found - return original sequence - std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); + Output = std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); return Output; } // Copy the beginning of the sequence - std::copy( ::boost::begin(Input), ::boost::begin(M), Output ); + Output = std::copy( ::boost::begin(Input), ::boost::begin(M), Output ); // Format find result // Copy formated result - std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); + Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); // Copy the rest of the sequence - std::copy( M.end(), ::boost::end(Input), Output ); + Output = std::copy( M.end(), ::boost::end(Input), Output ); return Output; } @@ -75,12 +75,16 @@ namespace boost { 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) ); + } else { + return std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); + } } @@ -132,11 +136,15 @@ namespace boost { FormatterT Formatter, 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) ); + } else { + return Input; + } } // replace implementation ----------------------------------------------------// @@ -180,12 +188,14 @@ namespace boost { FormatterT Formatter, const FindResultT& FindResult) { + if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { ::boost::algorithm::detail::find_format_impl2( Input, Formatter, FindResult, Formatter(FindResult) ); } + } } // namespace detail } // namespace algorithm diff --git a/include/boost/algorithm/string/detail/find_format_all.hpp b/include/boost/algorithm/string/detail/find_format_all.hpp index 36edf56..0f184a3 100644 --- a/include/boost/algorithm/string/detail/find_format_all.hpp +++ b/include/boost/algorithm/string/detail/find_format_all.hpp @@ -57,9 +57,9 @@ namespace boost { while( M ) { // Copy the beginning of the sequence - std::copy( LastMatch, M.begin(), Output ); + Output = std::copy( LastMatch, M.begin(), Output ); // Copy formated result - std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); + Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); // Proceed to the next match LastMatch=M.end(); @@ -67,7 +67,7 @@ namespace boost { } // Copy the rest of the sequence - std::copy( LastMatch, ::boost::end(Input), Output ); + Output = std::copy( LastMatch, ::boost::end(Input), Output ); return Output; } @@ -85,6 +85,7 @@ namespace boost { 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, @@ -92,6 +93,9 @@ namespace boost { Formatter, FindResult, Formatter(FindResult) ); + } else { + return std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); + } } // find_format_all_copy implementation ----------------------------------------------// @@ -156,12 +160,16 @@ namespace boost { FormatterT Formatter, 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) ); + } else { + return Input; + } } // find_format_all implementation ------------------------------------------------// @@ -248,6 +256,7 @@ namespace boost { FormatterT Formatter, FindResultT FindResult) { + if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) { ::boost::algorithm::detail::find_format_all_impl2( Input, Finder, @@ -255,6 +264,7 @@ namespace boost { FindResult, Formatter(FindResult) ); } + } } // namespace detail } // namespace algorithm diff --git a/include/boost/algorithm/string/detail/find_format_store.hpp b/include/boost/algorithm/string/detail/find_format_store.hpp index 2260fc2..24fe374 100644 --- a/include/boost/algorithm/string/detail/find_format_store.hpp +++ b/include/boost/algorithm/string/detail/find_format_store.hpp @@ -52,7 +52,9 @@ namespace boost { find_format_store& operator=( FindResultT FindResult ) { iterator_range::operator=(FindResult); + if( !this->empty() ) { m_FormatResult=m_Formatter(FindResult); + } return *this; } @@ -68,6 +70,15 @@ namespace boost { const formatter_type& m_Formatter; }; + template + bool check_find_result(InputT& Input, FindResultT& FindResult) + { + typedef BOOST_STRING_TYPENAME + range_const_iterator::type input_iterator_type; + iterator_range ResultRange(FindResult); + return !ResultRange.empty(); + } + #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) #pragma warning(pop) #endif diff --git a/include/boost/algorithm/string/erase.hpp b/include/boost/algorithm/string/erase.hpp index 0951b8a..e738b86 100644 --- a/include/boost/algorithm/string/erase.hpp +++ b/include/boost/algorithm/string/erase.hpp @@ -752,7 +752,7 @@ namespace boost { \param Output An output iterator to which the result will be copied \param Input An input string - \param N Length of the head. + \param N Length of the tail. For N>=0, at most N characters are extracted. For N<0, size(Input)-|N| characters are extracted. \return An output iterator pointing just after the last inserted character or @@ -797,7 +797,7 @@ namespace boost { considered to be the tail. The input sequence is modified in-place. \param Input An input string - \param N Length of the head + \param N Length of the tail For N>=0, at most N characters are extracted. For N<0, size(Input)-|N| characters are extracted. */ diff --git a/include/boost/algorithm/string/find.hpp b/include/boost/algorithm/string/find.hpp index b282d1a..304646d 100644 --- a/include/boost/algorithm/string/find.hpp +++ b/include/boost/algorithm/string/find.hpp @@ -257,7 +257,7 @@ namespace boost { //! Find tail algorithm /*! - Get the head of the input. Head is a suffix of the string of the + Get the tail of the input. Tail is a suffix of the string of the given size. If the input is shorter then required, whole input if considered to be the tail. diff --git a/include/boost/algorithm/string/find_iterator.hpp b/include/boost/algorithm/string/find_iterator.hpp index 4224a19..72696c7 100644 --- a/include/boost/algorithm/string/find_iterator.hpp +++ b/include/boost/algorithm/string/find_iterator.hpp @@ -240,7 +240,7 @@ namespace boost { m_Match(Other.m_Match), m_Next(Other.m_Next), m_End(Other.m_End), - m_bEof(false) + m_bEof(Other.m_bEof) {} //! Constructor diff --git a/string/doc/external_concepts.html b/string/doc/external_concepts.html index 7a4a502..af403be 100644 --- a/string/doc/external_concepts.html +++ b/string/doc/external_concepts.html @@ -32,7 +32,9 @@ free-standing functions and type-generators exists:

void foo( const T&, int );
int bar( T& );
foo_type_of< T >::type;



Literature


© Thorsten Ottosen 2003-2004 (nesotto_AT_cs.auc.dk). - Permission to copy, use, modify, sell and distribute this software is granted provided this copyright notice appears - in all copies. This software is provided "as is" without express or implied warranty, and with no - claim as to its suitability for any purpose.































- \ No newline at end of file +
Use, modification and distribution is subject to the Boost + Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +
+

+ diff --git a/string/doc/string_algo.xml b/string/doc/string_algo.xml index f803968..bbf1fe0 100644 --- a/string/doc/string_algo.xml +++ b/string/doc/string_algo.xml @@ -33,7 +33,7 @@ A set of generic string-related algorithms and utilities - + diff --git a/string/doc/usage.xml b/string/doc/usage.xml index 39c4e1a..2dafad4 100644 --- a/string/doc/usage.xml +++ b/string/doc/usage.xml @@ -169,7 +169,7 @@ string str1=" hello world! "; string str2=trim_left_copy(str1); // str2 == "hello world! " - string str3=trim_right_copy(str2); // str3 == " hello world!" + string str3=trim_right_copy(str1); // str3 == " hello world!" trim(str1); // str1 == "hello world!" string phone="00423333444"; @@ -339,7 +339,7 @@ typedef vector< string > split_vector_type; split_vector_type SplitVec; // #2: Search for tokens - split( SplitVec, str1, is_any_of("-*") ); // SplitVec == { "hello abc","ABC","aBc goodbye" } + split( SplitVec, str1, is_any_of("-*"), token_compress_on ); // SplitVec == { "hello abc","ABC","aBc goodbye" } [hello] designates an iterator_range delimiting this substring. diff --git a/string/test/Jamfile.v2 b/string/test/Jamfile.v2 index d85bdec..8b38e2c 100644 --- a/string/test/Jamfile.v2 +++ b/string/test/Jamfile.v2 @@ -59,5 +59,11 @@ test-suite algorithm/string : : regex ] + [ run + find_format_test.cpp + : : + : + : find_format + ] ; diff --git a/string/test/find_format_test.cpp b/string/test/find_format_test.cpp new file mode 100644 index 0000000..4201e1e --- /dev/null +++ b/string/test/find_format_test.cpp @@ -0,0 +1,163 @@ +// Boost string_algo library find_format_test.cpp file ------------------// + +// Copyright (c) 2009 Steven Watanabe +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for updates, documentation, and revision history. + +#include +#include +#include + +// Include unit test framework +#include + +#include + +// We're only using const_formatter. +template +struct formatter_result { + typedef boost::iterator_range type; +}; + +template +struct checked_formatter { +public: + checked_formatter(const Formatter& formatter) : formatter_(formatter) {} + template< typename T > + typename formatter_result::type operator()( const T & s ) const { + BOOST_CHECK( !s.empty() ); + return formatter_(s); + } +private: + Formatter formatter_; +}; + +template +checked_formatter +make_checked_formatter(const Formatter& formatter) { + return checked_formatter(formatter); +} + +void find_format_test() +{ + const std::string source = "$replace $replace"; + std::string expected = "ok $replace"; + std::string output(80, '\0'); + + std::string::iterator pos = + boost::find_format_copy( + output.begin(), + source, + boost::first_finder("$replace"), + make_checked_formatter(boost::const_formatter("ok"))); + BOOST_CHECK(pos == output.begin() + expected.size()); + output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); + BOOST_CHECK_EQUAL(output, expected); + + output = + boost::find_format_copy( + source, + boost::first_finder("$replace"), + make_checked_formatter(boost::const_formatter("ok"))); + BOOST_CHECK_EQUAL(output, expected); + + // now try finding a string that doesn't exist + output.resize(80); + pos = + boost::find_format_copy( + output.begin(), + source, + boost::first_finder("$noreplace"), + make_checked_formatter(boost::const_formatter("bad"))); + BOOST_CHECK(pos == output.begin() + source.size()); + output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); + BOOST_CHECK_EQUAL(output, source); + + output = + boost::find_format_copy( + source, + boost::first_finder("$noreplace"), + make_checked_formatter(boost::const_formatter("bad"))); + BOOST_CHECK_EQUAL(output, source); + + // in place version + output = source; + boost::find_format( + output, + boost::first_finder("$replace"), + make_checked_formatter(boost::const_formatter("ok"))); + BOOST_CHECK_EQUAL(output, expected); + output = source; + boost::find_format( + output, + boost::first_finder("$noreplace"), + make_checked_formatter(boost::const_formatter("bad"))); + BOOST_CHECK_EQUAL(output, source); +} + +void find_format_all_test() +{ + const std::string source = "$replace $replace"; + std::string expected = "ok ok"; + std::string output(80, '\0'); + + std::string::iterator pos = + boost::find_format_all_copy(output.begin(), + source, + boost::first_finder("$replace"), + boost::const_formatter("ok")); + BOOST_CHECK(pos == output.begin() + expected.size()); + output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); + BOOST_CHECK_EQUAL(output, expected); + + output = + boost::find_format_all_copy( + source, + boost::first_finder("$replace"), + make_checked_formatter(boost::const_formatter("ok"))); + BOOST_CHECK_EQUAL(output, expected); + + // now try finding a string that doesn't exist + output.resize(80); + pos = + boost::find_format_all_copy( + output.begin(), + source, + boost::first_finder("$noreplace"), + make_checked_formatter(boost::const_formatter("bad"))); + BOOST_CHECK(pos == output.begin() + source.size()); + output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); + BOOST_CHECK_EQUAL(output, source); + + output = + boost::find_format_all_copy( + source, + boost::first_finder("$noreplace"), + make_checked_formatter(boost::const_formatter("bad"))); + BOOST_CHECK_EQUAL(output, source); + + // in place version + output = source; + boost::find_format_all( + output, + boost::first_finder("$replace"), + make_checked_formatter(boost::const_formatter("ok"))); + BOOST_CHECK_EQUAL(output, expected); + output = source; + boost::find_format_all( + output, + boost::first_finder("$noreplace"), + make_checked_formatter(boost::const_formatter("bad"))); + BOOST_CHECK_EQUAL(output, source); +} + +int test_main( int, char*[] ) +{ + find_format_test(); + find_format_all_test(); + + return 0; +} diff --git a/string/test/split_test.cpp b/string/test/split_test.cpp index bb4e1a2..d85bce7 100644 --- a/string/test/split_test.cpp +++ b/string/test/split_test.cpp @@ -139,6 +139,7 @@ void iterator_test() ++siter; BOOST_CHECK(equals(*siter, "abb")); ++siter; + BOOST_CHECK(siter==split_iterator(siter)); BOOST_CHECK(siter==split_iterator()); }