After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 740810 - Search and replace character duplication with regex + match at word boundaries options
Search and replace character duplication with regex + match at word boundarie...
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
3.15.x
Other Linux
: Normal normal
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2014-11-27 13:56 UTC by sam.petrocelli
Modified: 2015-01-02 20:22 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description sam.petrocelli 2014-11-27 13:56:58 UTC
In the following code snippet, I want to replace all the 'brdf_' variables with the string brdf_data_pnt.  I use the find and replace tool with the 'match entire word only' and 'match as regular expression' options checked so that only 'brdf_' variables are found (not the brdf_ substring of m_brdf_vec).  When I replace each item, the results are not as expected.  The character immediately before 'brdf_' is duplicated.  If I turn off the 'match as regular expression' option, this error does not occur, but then I am left with manually filtering through the found results to avoid replacing substrings (ie. m_brdf_vec -> m_brdf_data_pntvec).

Original:

  brdfDataPnt_t &brdf_ = m_brdf_vec.front();
  m_curve_vec.reserve(num_curves);
  m_curve_vec.push_back( Curve(brdf_.i_angle, brdf_.wavelength, brdf_.wavelength_idx) );
  m_curve_vec.back().InsertDataPoint(static_cast<double>(brdf_.r_angle), brdf_.reflectivity);
  wavelength_idx_ = brdf_.wavelength_idx;
  for(auto it = m_brdf_vec.begin() + 1; it != m_brdf_vec.end(); ++it){
    if(it->wavelength_idx != wavelength_idx_){
      wavelength_idx_ = it->wavelength_idx;
      m_curve_vec.push_back( Curve(it->i_angle, it->wavelength, it->wavelength_idx) );
    }
    m_curve_vec.back().InsertDataPoint(static_cast<double>(it->r_angle), it->reflectivity);
  }


After string replacing:

  brdfDataPnt_t &&brdf_data_pnt = m_brdf_vec.front();
  m_curve_vec.reserve(num_curves);
  m_curve_vec.push_back( Curve((brdf_data_pnt.i_angle,  brdf_data_pnt.wavelength,  brdf_data_pnt.wavelength_idx) );
  m_curve_vec.back().InsertDataPoint(static_cast<double>((brdf_data_pnt.r_angle),  brdf_data_pnt.reflectivity);
  wavelength_idx_ =  brdf_data_pnt.wavelength_idx;
  for(auto it = m_brdf_vec.begin() + 1; it != m_brdf_vec.end(); ++it){
    if(it->wavelength_idx != wavelength_idx_){
      wavelength_idx_ = it->wavelength_idx;
      m_curve_vec.push_back( Curve(it->i_angle, it->wavelength, it->wavelength_idx) );
    }
    m_curve_vec.back().InsertDataPoint(static_cast<double>(it->r_angle), it->reflectivity);
  }
Comment 1 Sébastien Wilmet 2014-11-27 18:40:51 UTC
Thanks for the bug report. I don't think the underscore means something with perl-compatible regular expressions. So it's probably a bug in GtkSourceView, with the combination of regex + match at word boundaries.

If we keep the regex option but we uncheck "Match entire word only", then it doesn't duplicate the character.

To match at word boundaries, the search must look a few characters before the actual match, so it's most probably related to that.

I'll try to fix this bug soon, and write a unit test.