[Boost-bugs] [Boost C++ Libraries] #2777: find_format_all calls formatter with invalid match

Subject: [Boost-bugs] [Boost C++ Libraries] #2777: find_format_all calls formatter with invalid match
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-02-18 14:18:04


#2777: find_format_all calls formatter with invalid match
-----------------------------------------------------------------+----------
 Reporter: Éric Malenfant <eric.malenfant_at_[hidden]> | Owner: pavol_droba
     Type: Bugs | Status: new
Milestone: Boost 1.39.0 | Component: string_algo
  Version: Boost 1.35.0 | Severity: Problem
 Keywords: |
-----------------------------------------------------------------+----------
 find_format_all() calls the formatter with an invalid match when the end
 of the input is reached.

 Example:


 {{{
 // A Boost.StringAlgo Formatter expecting
 // to be called with matches to the regex:
 // (\d+\.)(\d+)
 struct NextVersionNumber {
   template<class RegexMatchT>
   std::string operator()(const RegexMatchT& M)const
   {
     // Without this check, we end up with
     // a bad_lexical_cast exception,
     // because operator() ends up being called twice:
     // First with a good match, and then with an emtpy one
     if (!Match){
       return "";
     }

     using boost::lexical_cast;
     return M.match_results()[1] +
       lexical_cast<std::string>(
         lexical_cast<unsigned int>(M.match_results()[2]) + 1
       );
   }
 };

 int main()
 {
   namespace bsa = boost::algorithm;
   const std::string s("version is 1.0");

   // Outputs:
   // version is: 1.1
   std::cout <<
       bsa::find_format_all_copy(
           s, bsa::regex_finder(boost::regex("(\\d+\\.)(\\d+)")),
           NextVersionNumber()
       );
   return 0;
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2777>
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:49:59 UTC