From d6d75c9a311c579cb810bbee36ef1425a2db9809 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 20 Dec 2012 15:52:59 +0000 Subject: [PATCH] Fixed bug in boost::algorithm::find_all with overlapping results; thanks to cedstrom for the report and the patch; Refs #7784 [SVN r82117] --- include/boost/algorithm/string/find_iterator.hpp | 5 ++++- string/test/find_test.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/boost/algorithm/string/find_iterator.hpp b/include/boost/algorithm/string/find_iterator.hpp index b72ba7c..07a909e 100644 --- a/include/boost/algorithm/string/find_iterator.hpp +++ b/include/boost/algorithm/string/find_iterator.hpp @@ -132,7 +132,10 @@ namespace boost { // increment void increment() { - m_Match=this->do_find(m_Match.end(),m_End); + if(m_Match.begin() == m_Match.end()) + m_Match=this->do_find(m_Match.end(),m_End); + else + m_Match=this->do_find(m_Match.begin()+1,m_End); } // comparison diff --git a/string/test/find_test.cpp b/string/test/find_test.cpp index 67d3759..a93c878 100644 --- a/string/test/find_test.cpp +++ b/string/test/find_test.cpp @@ -9,6 +9,7 @@ #include #include +#include // Include unit test framework #include @@ -248,6 +249,20 @@ void find_test() ostringstream osstr; osstr << find_first( str1, "abc" ); BOOST_CHECK( osstr.str()=="abc" ); + + // Empty string test + BOOST_CHECKPOINT( "overlapping" ); + + std::string overlap_target("aaaa"); + std::vector > overlap_results; + boost::algorithm::find_all(overlap_results, overlap_target, string("aaa")); + BOOST_CHECK( overlap_results.size() == 2 ); + + std::string overlap_target2("aaaabbbbaaaa"); + boost::algorithm::find_all(overlap_results, overlap_target2, string("bb")); + BOOST_CHECK( overlap_results.size() == 3 ); + boost::algorithm::find_all(overlap_results, overlap_target2, string("aa")); + BOOST_CHECK( overlap_results.size() == 6 ); } // test main