Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with boost::find_format_all, boost::regex_finder and custom regex formatter (bug boost 1.42)
    primarykey
    data
    text
    <p>I have a code that has been working for almost 4 years (since boost 1.33) and today I went from boost 1.36 to boost 1.42 and now I have a problem.</p> <p>I'm calling a custom formatter on a string to format parts of the string that match a REGEX.</p> <p>For instance, a string like: "abc;def:" will be changed to "abc\2Cdef\3B" if the REGEX contains "([;:])"</p> <pre><code>boost::find_format_all( mystring, boost::regex_finder( REGEX ), custom_formatter() ); </code></pre> <p>The custom formatter looks like this:</p> <pre><code>struct custom_formatter() { template&lt; typename T &gt; std::string operator()( const T &amp; s ) const { std::string matchStr = s.match_results().str(1); // perform substitutions return matchStr; } } </code></pre> <p>This worked fine but with boost 1.42 I know have "non initialized" s.match_results() which yield to boost::exception_detail::clone_implINS0_::error_info_injectorISt11logic_errorEEEE - Attempt to access an uninitialzed boost::match_results&lt;> class.</p> <p>This means that sometimes I am in the functor to format a string but there is no match.</p> <p>Am I doing something wrong? Or is it normal to enter the functor when there is no match and I should check against something?</p> <p>for now my solution is to try{}catch(){} the exception and everything works fine, but somehow that doesn't feel very good.</p> <p><strong>EDIT1</strong></p> <p>Actually I have a new empty match at the end of each string to parse.</p> <p><strong>EDIT2 : one solution inspired by ablaeul</strong></p> <pre><code> template&lt; typename T &gt; std::string operator()( const T &amp; s ) const { if( s.begin() == s.end() ) return std::string(); std::string matchStr = s.match_results().str(1); // perform substitutions return matchStr; } </code></pre> <p><strong>EDIT3 Seems to be a bug in (at least) boost 1.42</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload