KiCad PCB EDA Suite
EDA_PATTERN_MATCH_WILDCARD Class Reference

#include <eda_pattern_match.h>

Inheritance diagram for EDA_PATTERN_MATCH_WILDCARD:
EDA_PATTERN_MATCH_REGEX EDA_PATTERN_MATCH

Public Member Functions

virtual bool SetPattern (const wxString &aPattern) override
 Set the pattern against which candidates will be matched. More...
 
virtual int Find (const wxString &aCandidate) const override
 Return the location of a match iff a given candidate string matches the set pattern. More...
 

Protected Attributes

wxString m_pattern
 
wxRegEx m_regex
 

Detailed Description

Definition at line 92 of file eda_pattern_match.h.

Member Function Documentation

int EDA_PATTERN_MATCH_WILDCARD::Find ( const wxString &  aCandidate) const
overridevirtual

Return the location of a match iff a given candidate string matches the set pattern.

Otherwise, return EDA_PATTERN_NOT_FOUND.

Reimplemented from EDA_PATTERN_MATCH_REGEX.

Definition at line 135 of file eda_pattern_match.cpp.

References EDA_PATTERN_MATCH_REGEX::Find().

Referenced by DIALOG_SELECT_NET_FROM_LIST::buildNetsList(), COMPONENT::MatchesFootprintFilters(), and FOOTPRINTS_LISTBOX::SetFootprints().

136 {
137  return EDA_PATTERN_MATCH_REGEX::Find( aCandidate );
138 }
virtual int Find(const wxString &aCandidate) const override
Return the location of a match iff a given candidate string matches the set pattern.
bool EDA_PATTERN_MATCH_WILDCARD::SetPattern ( const wxString &  aPattern)
overridevirtual

Set the pattern against which candidates will be matched.

If the pattern can not be processed, returns false.

Reimplemented from EDA_PATTERN_MATCH_REGEX.

Definition at line 101 of file eda_pattern_match.cpp.

References EDA_PATTERN_MATCH_REGEX::SetPattern().

Referenced by DIALOG_SELECT_NET_FROM_LIST::buildNetsList(), COMPONENT::MatchesFootprintFilters(), and FOOTPRINTS_LISTBOX::SetFootprints().

102 {
103  // Compile the wildcard string to a regular expression
104  wxString regex;
105  regex.Alloc( 2 * aPattern.Length() ); // no need to keep resizing, we know the size roughly
106 
107  const wxString to_replace = wxT( ".*+?^${}()|[]/\\" );
108 
109  for( wxString::const_iterator it = aPattern.begin(); it < aPattern.end(); ++it )
110  {
111  wxUniChar c = *it;
112  if( c == '?' )
113  {
114  regex += wxT( "." );
115  }
116  else if( c == '*' )
117  {
118  regex += wxT( ".*" );
119  }
120  else if( to_replace.Find( c ) != wxNOT_FOUND )
121  {
122  regex += "\\";
123  regex += c;
124  }
125  else
126  {
127  regex += c;
128  }
129  }
130 
131  return EDA_PATTERN_MATCH_REGEX::SetPattern( regex );
132 }
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.

Member Data Documentation

wxString EDA_PATTERN_MATCH_REGEX::m_pattern
protectedinherited
wxRegEx EDA_PATTERN_MATCH_REGEX::m_regex
protectedinherited

The documentation for this class was generated from the following files: