Opened 13 years ago
Closed 13 years ago
#3461 closed Bugs (invalid)
bug in iter_split or nth_finder
Reported by: | Owned by: | Pavol Droba | |
---|---|---|---|
Milestone: | Boost 1.41.0 | Component: | string_algo |
Version: | Boost 1.40.0 | Severity: | Problem |
Keywords: | Cc: |
Description
There appears to be a bug in iter_split or nt_finder.
Sample code: #include <iostream> #include <string> #include <vector> #include <boost/algorithm/string.hpp>
int main() {
std::string str("Hello, world, !!!"); std::vector<std::string> slist;
boost::algorithm::iter_split(slist, str, boost::algorithm::nth_finder(", ", 0));
for(int index=0; index<str.length(); ++index)
std::cout << slist[index] << std::endl;
return 0;
}
Output: Hello world !!!
Expected Output: Hello world, !!!
All other indices seem to work, only when you use 0.
This also happens on boost 1.37.0, so its possible it could be in every version in between.
Change History (2)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Hello,
The described behavior is perfectly correct. I'm afraid you've misunderstood the semantics of iter_split. If works as follows:
- set the start marker to the beginning of the sequence
- using the supplied finder, find the first splitter after the marker
- return the match between start marker and splitter
- move the start marker at the end of splitter and goto 2.
On other words, using nth_finder with iter-split will not split the sequence in two parts, rather it will split at every n-th splitter.
When you set nth index to 0, nth_finder works exatly as the first_finder, so the sequence is split at every splitter.
Best Regards, Pavol.
Sorry about the formatting. Output and Expected output should have been -
Output:
Hello
world
!![[BR]]
Expected Output:
Hello
world, !![[BR]]