|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62694 - in trunk: boost/algorithm/string/detail libs/algorithm/string/test
From: steven_at_[hidden]
Date: 2010-06-09 17:12:07
Author: steven_watanabe
Date: 2010-06-09 17:12:06 EDT (Wed, 09 Jun 2010)
New Revision: 62694
URL: http://svn.boost.org/trac/boost/changeset/62694
Log:
Assign the iterator returned by std::copy back to Output, so that string algorithms will work with iterators other than inserters
Added:
trunk/libs/algorithm/string/test/find_format_test.cpp (contents, props changed)
Text files modified:
trunk/boost/algorithm/string/detail/find_format.hpp | 8 ++++----
trunk/boost/algorithm/string/detail/find_format_all.hpp | 6 +++---
trunk/libs/algorithm/string/test/Jamfile.v2 | 6 ++++++
3 files changed, 13 insertions(+), 7 deletions(-)
Modified: trunk/boost/algorithm/string/detail/find_format.hpp
==============================================================================
--- trunk/boost/algorithm/string/detail/find_format.hpp (original)
+++ trunk/boost/algorithm/string/detail/find_format.hpp 2010-06-09 17:12:06 EDT (Wed, 09 Jun 2010)
@@ -49,17 +49,17 @@
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;
}
Modified: trunk/boost/algorithm/string/detail/find_format_all.hpp
==============================================================================
--- trunk/boost/algorithm/string/detail/find_format_all.hpp (original)
+++ trunk/boost/algorithm/string/detail/find_format_all.hpp 2010-06-09 17:12:06 EDT (Wed, 09 Jun 2010)
@@ -57,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();
@@ -67,7 +67,7 @@
}
// Copy the rest of the sequence
- std::copy( LastMatch, ::boost::end(Input), Output );
+ Output = std::copy( LastMatch, ::boost::end(Input), Output );
return Output;
}
Modified: trunk/libs/algorithm/string/test/Jamfile.v2
==============================================================================
--- trunk/libs/algorithm/string/test/Jamfile.v2 (original)
+++ trunk/libs/algorithm/string/test/Jamfile.v2 2010-06-09 17:12:06 EDT (Wed, 09 Jun 2010)
@@ -59,5 +59,11 @@
:
: regex
]
+ [ run
+ find_format_test.cpp
+ : :
+ :
+ : find_format
+ ]
;
Added: trunk/libs/algorithm/string/test/find_format_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/algorithm/string/test/find_format_test.cpp 2010-06-09 17:12:06 EDT (Wed, 09 Jun 2010)
@@ -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 <boost/algorithm/string/find_format.hpp>
+#include <boost/algorithm/string/finder.hpp>
+#include <boost/algorithm/string/formatter.hpp>
+
+// Include unit test framework
+#include <boost/test/included/test_exec_monitor.hpp>
+
+#include <boost/test/test_tools.hpp>
+
+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;
+}
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