Index: boost/algorithm/string/detail/find_format_all.hpp =================================================================== --- boost/algorithm/string/detail/find_format_all.hpp (revision 53262) +++ boost/algorithm/string/detail/find_format_all.hpp (working copy) @@ -29,28 +29,6 @@ typename InputT, typename FinderT, typename FormatterT, - typename FindResultT > - inline OutputIteratorT find_format_all_copy_impl( - OutputIteratorT Output, - const InputT& Input, - FinderT Finder, - FormatterT Formatter, - const FindResultT& FindResult ) - { - return find_format_all_copy_impl2( - Output, - Input, - Finder, - Formatter, - FindResult, - Formatter(FindResult) ); - } - - template< - typename OutputIteratorT, - typename InputT, - typename FinderT, - typename FormatterT, typename FindResultT, typename FormatResultT > inline OutputIteratorT find_format_all_copy_impl2( @@ -79,9 +57,9 @@ 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(); @@ -89,25 +67,26 @@ } // Copy the rest of the sequence - std::copy( LastMatch, ::boost::end(Input), Output ); + Output = std::copy( LastMatch, ::boost::end(Input), Output ); return Output; } -// find_format_all_copy implementation ----------------------------------------------// - template< - typename InputT, + typename OutputIteratorT, + typename InputT, typename FinderT, typename FormatterT, typename FindResultT > - inline InputT find_format_all_copy_impl( + inline OutputIteratorT find_format_all_copy_impl( + OutputIteratorT Output, const InputT& Input, FinderT Finder, FormatterT Formatter, - const FindResultT& FindResult) - { - return find_format_all_copy_impl2( + const FindResultT& FindResult ) + { + return find_format_all_copy_impl2( + Output, Input, Finder, Formatter, @@ -115,6 +94,8 @@ Formatter(FindResult) ); } +// find_format_all_copy implementation ----------------------------------------------// + template< typename InputT, typename FinderT, @@ -164,20 +145,18 @@ return Output; } -// find_format_all implementation ------------------------------------------------// - - template< - typename InputT, + template< + typename InputT, typename FinderT, typename FormatterT, typename FindResultT > - inline void find_format_all_impl( - InputT& Input, + inline InputT find_format_all_copy_impl( + const InputT& Input, FinderT Finder, FormatterT Formatter, - FindResultT FindResult) + const FindResultT& FindResult) { - find_format_all_impl2( + return find_format_all_copy_impl2( Input, Finder, Formatter, @@ -185,6 +164,8 @@ Formatter(FindResult) ); } +// find_format_all implementation ------------------------------------------------// + template< typename InputT, typename FinderT, @@ -255,6 +236,25 @@ insert( Input, ::boost::end(Input), Storage.begin(), Storage.end() ); } } + + template< + typename InputT, + typename FinderT, + typename FormatterT, + typename FindResultT > + inline void find_format_all_impl( + InputT& Input, + FinderT Finder, + FormatterT Formatter, + FindResultT FindResult) + { + find_format_all_impl2( + Input, + Finder, + Formatter, + FindResult, + Formatter(FindResult) ); + } } // namespace detail } // namespace algorithm Index: boost/algorithm/string/detail/find_format.hpp =================================================================== --- boost/algorithm/string/detail/find_format.hpp (revision 53262) +++ boost/algorithm/string/detail/find_format.hpp (working copy) @@ -28,25 +28,6 @@ typename OutputIteratorT, typename InputT, typename FormatterT, - typename FindResultT > - inline OutputIteratorT find_format_copy_impl( - OutputIteratorT Output, - const InputT& Input, - FormatterT Formatter, - const FindResultT& FindResult ) - { - return find_format_copy_impl2( - Output, - Input, - Formatter, - FindResult, - Formatter(FindResult) ); - } - - template< - typename OutputIteratorT, - typename InputT, - typename FormatterT, typename FindResultT, typename FormatResultT > inline OutputIteratorT find_format_copy_impl2( @@ -68,39 +49,42 @@ 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; } -// find_format_copy implementation --------------------------------------------------// - template< - typename InputT, + typename OutputIteratorT, + typename InputT, typename FormatterT, typename FindResultT > - inline InputT find_format_copy_impl( + inline OutputIteratorT find_format_copy_impl( + OutputIteratorT Output, const InputT& Input, FormatterT Formatter, - const FindResultT& FindResult) - { - return find_format_copy_impl2( + const FindResultT& FindResult ) + { + return find_format_copy_impl2( + Output, Input, Formatter, FindResult, Formatter(FindResult) ); } +// find_format_copy implementation --------------------------------------------------// + template< typename InputT, typename FormatterT, @@ -138,24 +122,24 @@ return Output; } -// replace implementation ----------------------------------------------------// - - template< - typename InputT, + template< + typename InputT, typename FormatterT, typename FindResultT > - inline void find_format_impl( - InputT& Input, + inline InputT find_format_copy_impl( + const InputT& Input, FormatterT Formatter, const FindResultT& FindResult) { - find_format_impl2( + return find_format_copy_impl2( Input, Formatter, FindResult, Formatter(FindResult) ); } +// replace implementation ----------------------------------------------------// + template< typename InputT, typename FormatterT, @@ -185,6 +169,22 @@ // Replace match replace( Input, M.begin(), M.end(), M.format_result() ); } + + template< + typename InputT, + typename FormatterT, + typename FindResultT > + inline void find_format_impl( + InputT& Input, + FormatterT Formatter, + const FindResultT& FindResult) + { + find_format_impl2( + Input, + Formatter, + FindResult, + Formatter(FindResult) ); + } } // namespace detail } // namespace algorithm Index: libs/algorithm/string/test/find_format_test.cpp =================================================================== --- libs/algorithm/string/test/find_format_test.cpp (revision 0) +++ libs/algorithm/string/test/find_format_test.cpp (revision 0) @@ -0,0 +1,105 @@ +// 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 + +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"), + 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"), 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"), + 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"), boost::const_formatter("bad")); + BOOST_CHECK_EQUAL(output, source); + + // in place version + output = source; + boost::find_format(output, boost::first_finder("$replace"), boost::const_formatter("ok")); + BOOST_CHECK_EQUAL(output, expected); + output = source; + boost::find_format(output, boost::first_finder("$noreplace"), 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"), 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"), + 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"), boost::const_formatter("bad")); + BOOST_CHECK_EQUAL(output, source); + + // in place version + output = source; + boost::find_format_all(output, boost::first_finder("$replace"), boost::const_formatter("ok")); + BOOST_CHECK_EQUAL(output, expected); + output = source; + boost::find_format_all(output, boost::first_finder("$noreplace"), boost::const_formatter("bad")); + BOOST_CHECK_EQUAL(output, source); +} + +int test_main( int, char*[] ) +{ + find_format_test(); + find_format_all_test(); + + return 0; +} Property changes on: libs\algorithm\string\test\find_format_test.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/algorithm/string/test/Jamfile.v2 =================================================================== --- libs/algorithm/string/test/Jamfile.v2 (revision 53262) +++ libs/algorithm/string/test/Jamfile.v2 (working copy) @@ -59,5 +59,11 @@ : : regex ] + [ run + find_format_test.cpp + : : + : + : find_format + ] ;