GNOME Bugzilla – Bug 740810
Search and replace character duplication with regex + match at word boundaries options
Last modified: 2015-01-02 20:22:49 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); }
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.
Fixed: https://git.gnome.org/browse/gtksourceview/commit/?id=2171a6ec5fcb53f9f387125ce55d96e595bb667f