Opened 13 years ago
Closed 10 years ago
#4103 closed Bugs (wontfix)
erase_all_regex does not work well with possibly empty strings.
| Reported by: | Owned by: | Marshall Clow | |
|---|---|---|---|
| Milestone: | Boost 1.43.0 | Component: | algorithm |
| Version: | Boost Development Trunk | Severity: | Problem |
| Keywords: | Cc: |
Description
Here is a test case, I want to remove all the substrings that matches the regular expression '\s*': all spaces, tabs and similars.
$ cat test_case.cc
#include <boost/algorithm/string/regex.hpp>
#include <iostream>
#include <string>
boost::regex const& spaces() {
static boost::regex rv("\\s*");
return rv;
}
int main() {
std::string e1(" Leading spaces! Remove them all! ");
std::string c1(e1);
std::string e2("No trailing or leading... Remove them all!");
std::string c2(e2);
boost::erase_all_regex(e1, spaces());
std::cout << "Erased: -" << e1 << "-" << std::endl;
std::cout << "Original: -" << c1 << "-" << std::endl;
std::cout << std::endl;
boost::erase_all_regex(e2, spaces());
std::cout << "Erased: -" << e2 << "-" << std::endl;
std::cout << "Original: -" << c2 << "-" << std::endl;
}
$ g++ -lboost_regex -W -Wall -pedantic -o test_case test_case.cc
$ ./test_case
Erased: -Leading spaces! Remove them all! -
Original: - Leading spaces! Remove them all! -
Erased: -No trailing or leading... Remove them all!-
Original: -No trailing or leading... Remove them all!-
$
I think the expected output should not have spaces in the output string. Instead only the leading spaces are removed.
While the problem still persist with '\s*' the bug apparead also
with regex '\s+' in the version 1.41, but using the svn trunk
downloaded yesterday it disappeared. It is worth to note because the bug
is not very grave anymore. It is enough to use a regex that does
not allow empty strings.
Change History (5)
comment:1 by , 13 years ago
| Component: | None → string_algo |
|---|---|
| Owner: | set to |
comment:2 by , 12 years ago
comment:3 by , 11 years ago
| Component: | string_algo → algorithm |
|---|---|
| Owner: | changed from to |
comment:4 by , 10 years ago
This is still around in 1.51; but since there's an easy workaround (use a non-empty regex), I'm inclined not to fix this.
Comments?
comment:5 by , 10 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |

It looks like an empty match is taken as the sentinel to indicate that there is no match.