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 wxString const & GetPattern () const override
 Return the pattern passed to SetPattern(). 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_wildcard_pattern
 
wxString m_pattern
 
wxRegEx m_regex
 

Detailed Description

Definition at line 99 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 156 of file eda_pattern_match.cpp.

References EDA_PATTERN_MATCH_REGEX::Find().

Referenced by DIALOG_SELECT_NET_FROM_LIST::buildNetsList().

157 {
158  return EDA_PATTERN_MATCH_REGEX::Find( aCandidate );
159 }
virtual int Find(const wxString &aCandidate) const override
Return the location of a match iff a given candidate string matches the set pattern.
wxString const & EDA_PATTERN_MATCH_WILDCARD::GetPattern ( ) const
overridevirtual

Return the pattern passed to SetPattern().

Reimplemented from EDA_PATTERN_MATCH_REGEX.

Definition at line 150 of file eda_pattern_match.cpp.

References m_wildcard_pattern.

151 {
152  return m_wildcard_pattern;
153 }
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 114 of file eda_pattern_match.cpp.

References m_wildcard_pattern, and EDA_PATTERN_MATCH_REGEX::SetPattern().

Referenced by DIALOG_SELECT_NET_FROM_LIST::buildNetsList(), and FOOTPRINT_FILTER::FilterByPattern().

115 {
116  m_wildcard_pattern = aPattern;
117 
118  // Compile the wildcard string to a regular expression
119  wxString regex;
120  regex.Alloc( 2 * aPattern.Length() ); // no need to keep resizing, we know the size roughly
121 
122  const wxString to_replace = wxT( ".*+?^${}()|[]/\\" );
123 
124  for( wxString::const_iterator it = aPattern.begin(); it < aPattern.end(); ++it )
125  {
126  wxUniChar c = *it;
127  if( c == '?' )
128  {
129  regex += wxT( "." );
130  }
131  else if( c == '*' )
132  {
133  regex += wxT( ".*" );
134  }
135  else if( to_replace.Find( c ) != wxNOT_FOUND )
136  {
137  regex += "\\";
138  regex += c;
139  }
140  else
141  {
142  regex += c;
143  }
144  }
145 
146  return EDA_PATTERN_MATCH_REGEX::SetPattern( regex );
147 }
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
wxString EDA_PATTERN_MATCH_WILDCARD::m_wildcard_pattern
protected

Definition at line 107 of file eda_pattern_match.h.

Referenced by GetPattern(), and SetPattern().


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