[Boost-bugs] [Boost C++ Libraries] #4103: erase_all_regex does not work well with possibly empty strings.

Subject: [Boost-bugs] [Boost C++ Libraries] #4103: erase_all_regex does not work well with possibly empty strings.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-04-15 14:32:42


#4103: erase_all_regex does not work well with possibly empty strings.
-------------------------------------------------+--------------------------
 Reporter: Paolo Bolzoni <bolzoni@…> | Owner:
     Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: None
  Version: Boost Development Trunk | Severity: Problem
 Keywords: |
-------------------------------------------------+--------------------------
 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.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4103>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC