Skip to content

Commit d6d75c9

Browse files
committed
Fixed bug in boost::algorithm::find_all with overlapping results; thanks to cedstrom for the report and the patch; Refs #7784
[SVN r82117]
1 parent 54d2649 commit d6d75c9

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

include/boost/algorithm/string/find_iterator.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ namespace boost {
132132
// increment
133133
void increment()
134134
{
135-
m_Match=this->do_find(m_Match.end(),m_End);
135+
if(m_Match.begin() == m_Match.end())
136+
m_Match=this->do_find(m_Match.end(),m_End);
137+
else
138+
m_Match=this->do_find(m_Match.begin()+1,m_End);
136139
}
137140

138141
// comparison

string/test/find_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <boost/algorithm/string/find.hpp>
1111
#include <boost/algorithm/string/classification.hpp>
12+
#include <boost/algorithm/string/split.hpp>
1213

1314
// Include unit test framework
1415
#include <boost/test/included/test_exec_monitor.hpp>
@@ -248,6 +249,20 @@ void find_test()
248249
ostringstream osstr;
249250
osstr << find_first( str1, "abc" );
250251
BOOST_CHECK( osstr.str()=="abc" );
252+
253+
// Empty string test
254+
BOOST_CHECKPOINT( "overlapping" );
255+
256+
std::string overlap_target("aaaa");
257+
std::vector<boost::iterator_range<std::string::iterator> > overlap_results;
258+
boost::algorithm::find_all(overlap_results, overlap_target, string("aaa"));
259+
BOOST_CHECK( overlap_results.size() == 2 );
260+
261+
std::string overlap_target2("aaaabbbbaaaa");
262+
boost::algorithm::find_all(overlap_results, overlap_target2, string("bb"));
263+
BOOST_CHECK( overlap_results.size() == 3 );
264+
boost::algorithm::find_all(overlap_results, overlap_target2, string("aa"));
265+
BOOST_CHECK( overlap_results.size() == 6 );
251266
}
252267

253268
// test main

0 commit comments

Comments
 (0)