bool EDA_ITEM::Replace( wxFindReplaceData& aSearchData, wxString& aText ) { wxCHECK_MSG( IsReplaceable(), false, wxT( "Attempt to replace text in <" ) + GetClass() + wxT( "> item." ) ); wxString searchString = (aSearchData.GetFlags() & wxFR_MATCHCASE) ? aText : aText.Upper(); int result = searchString.Find( (aSearchData.GetFlags() & wxFR_MATCHCASE) ? aSearchData.GetFindString() : aSearchData.GetFindString().Upper() ); if( result == wxNOT_FOUND ) return false; wxString prefix = aText.Left( result ); wxString suffix; if( aSearchData.GetFindString().length() + result < aText.length() ) suffix = aText.Right( aText.length() - ( aSearchData.GetFindString().length() + result ) ); wxLogTrace( traceFindReplace, wxT( "Replacing '%s', prefix '%s', replace '%s', suffix '%s'." ), GetChars( aText ), GetChars( prefix ), GetChars( aSearchData.GetReplaceString() ), GetChars( suffix ) ); aText = prefix + aSearchData.GetReplaceString() + suffix; return true; }
bool EDA_ITEM::Matches( const wxString& aText, wxFindReplaceData& aSearchData ) { wxString text = aText; wxString searchText = aSearchData.GetFindString(); // Don't match if searching for replaceable item and the item doesn't support text replace. if( (aSearchData.GetFlags() & FR_SEARCH_REPLACE) && !IsReplaceable() ) return false; if( aSearchData.GetFlags() & wxFR_WHOLEWORD ) return aText.IsSameAs( searchText, aSearchData.GetFlags() & wxFR_MATCHCASE ); if( aSearchData.GetFlags() & FR_MATCH_WILDCARD ) { if( aSearchData.GetFlags() & wxFR_MATCHCASE ) return text.Matches( searchText ); return text.MakeUpper().Matches( searchText.MakeUpper() ); } if( aSearchData.GetFlags() & wxFR_MATCHCASE ) return aText.Find( searchText ) != wxNOT_FOUND; return text.MakeUpper().Find( searchText.MakeUpper() ) != wxNOT_FOUND; }