From 4d46e0ceb73f9ab3820477e6cf43e8042da0dbc5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 5 Sep 2023 19:44:32 +0100 Subject: [PATCH] Include underscore in word chars. Fixes https://gitlab.com/kicad/code/kicad/-/issues/14779 (cherry picked from commit 0dddb27408fdc429ce4e9c11c7f79bd128cc784d) --- common/eda_item.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/common/eda_item.cpp b/common/eda_item.cpp index 7a16666ada..4c3f134850 100644 --- a/common/eda_item.cpp +++ b/common/eda_item.cpp @@ -114,6 +114,12 @@ wxString EDA_ITEM::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const } +bool isWordChar( const wxUniChar& c ) +{ + return wxIsalnum( c ) || c == '_'; +} + + bool EDA_ITEM::Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const { wxString text = aText; @@ -129,6 +135,12 @@ bool EDA_ITEM::Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchDat searchText.MakeUpper(); } + auto isWordChar = + []( const wxUniChar& c ) + { + return wxIsalnum( c ) || c == '_'; + }; + if( aSearchData.matchMode == EDA_SEARCH_MATCH_MODE::WHOLEWORD ) { int ii = 0; @@ -143,8 +155,8 @@ bool EDA_ITEM::Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchDat ii = next; next += searchText.length(); - bool startOK = ( ii == 0 || !wxIsalnum( text.GetChar( ii - 1 ) ) ); - bool endOK = ( next == (int) text.length() || !wxIsalnum( text.GetChar( next ) ) ); + bool startOK = ( ii == 0 || !isWordChar( text.GetChar( ii - 1 ) ) ); + bool endOK = ( next == (int) text.length() || !isWordChar( text.GetChar( next ) ) ); if( startOK && endOK ) return true; @@ -201,8 +213,8 @@ bool EDA_ITEM::Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText ) if( aSearchData.matchMode == EDA_SEARCH_MATCH_MODE::WHOLEWORD ) { - startOK = ( ii == 0 || !wxIsalnum( text.GetChar( ii - 1 ) ) ); - endOK = ( next == (int) text.length() || !wxIsalnum( text.GetChar( next ) ) ); + startOK = ( ii == 0 || !isWordChar( text.GetChar( ii - 1 ) ) ); + endOK = ( next == (int) text.length() || !isWordChar( text.GetChar( next ) ) ); } else {