KiCad PCB EDA Suite
EDA_PATTERN_MATCH_WILDCARD_EXPLICIT Class Reference

#include <eda_pattern_match.h>

Inheritance diagram for EDA_PATTERN_MATCH_WILDCARD_EXPLICIT:
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 111 of file eda_pattern_match.h.

Member Function Documentation

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

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
overridevirtualinherited

Return the pattern passed to SetPattern().

Reimplemented from EDA_PATTERN_MATCH_REGEX.

Definition at line 150 of file eda_pattern_match.cpp.

151 {
152  return m_wildcard_pattern;
153 }
bool EDA_PATTERN_MATCH_WILDCARD_EXPLICIT::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_WILDCARD.

Definition at line 162 of file eda_pattern_match.cpp.

References EDA_PATTERN_MATCH_REGEX::SetPattern().

163 {
164  m_wildcard_pattern = aPattern;
165 
166  // Compile the wildcard string to a regular expression
167  wxString regex;
168  regex.Alloc( 2 * aPattern.Length() ); // no need to keep resizing, we know the size roughly
169 
170  const wxString to_replace = wxT( ".*+?^${}()|[]/\\" );
171 
172  regex += wxT( "^" );
173  for( wxString::const_iterator it = aPattern.begin(); it < aPattern.end(); ++it )
174  {
175  wxUniChar c = *it;
176  if( c == '?' )
177  {
178  regex += wxT( "." );
179  }
180  else if( c == '*' )
181  {
182  regex += wxT( ".*" );
183  }
184  else if( to_replace.Find( c ) != wxNOT_FOUND )
185  {
186  regex += "\\";
187  regex += c;
188  }
189  else
190  {
191  regex += c;
192  }
193  }
194  regex += wxT( "$" );
195 
196  return EDA_PATTERN_MATCH_REGEX::SetPattern( regex );
197 }
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

Definition at line 94 of file eda_pattern_match.h.

wxRegEx EDA_PATTERN_MATCH_REGEX::m_regex
protectedinherited

Definition at line 95 of file eda_pattern_match.h.

wxString EDA_PATTERN_MATCH_WILDCARD::m_wildcard_pattern
protectedinherited

Definition at line 107 of file eda_pattern_match.h.


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