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

◆ Find()

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 155 of file eda_pattern_match.cpp.

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

References EDA_PATTERN_MATCH_REGEX::Find().

Referenced by DIALOG_SELECT_NET_FROM_LIST::netFilterMatches().

◆ GetPattern()

wxString const & EDA_PATTERN_MATCH_WILDCARD::GetPattern ( ) const
overridevirtualinherited

Return the pattern passed to SetPattern().

Reimplemented from EDA_PATTERN_MATCH_REGEX.

Definition at line 149 of file eda_pattern_match.cpp.

150 {
151  return m_wildcard_pattern;
152 }

References EDA_PATTERN_MATCH_WILDCARD::m_wildcard_pattern.

Referenced by DIALOG_SELECT_NET_FROM_LIST::netFilterMatches().

◆ SetPattern()

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 161 of file eda_pattern_match.cpp.

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

References EDA_PATTERN_MATCH_WILDCARD::m_wildcard_pattern, and EDA_PATTERN_MATCH_REGEX::SetPattern().

Member Data Documentation

◆ m_pattern

wxString EDA_PATTERN_MATCH_REGEX::m_pattern
protectedinherited

◆ m_regex

wxRegEx EDA_PATTERN_MATCH_REGEX::m_regex
protectedinherited

◆ m_wildcard_pattern

wxString EDA_PATTERN_MATCH_WILDCARD::m_wildcard_pattern
protectedinherited

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