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 EDA_PATTERN_MATCH_WILDCARD_EXPLICIT

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 FIND_RESULT Find (const wxString &aCandidate) const override
 Return the location and possibly length 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 122 of file eda_pattern_match.h.

Member Function Documentation

◆ Find()

EDA_PATTERN_MATCH::FIND_RESULT EDA_PATTERN_MATCH_WILDCARD::Find ( const wxString &  aCandidate) const
overridevirtual

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

Otherwise, return an invalid FIND_RESULT.

Reimplemented from EDA_PATTERN_MATCH_REGEX.

Definition at line 180 of file eda_pattern_match.cpp.

181{
182 return EDA_PATTERN_MATCH_REGEX::Find( aCandidate );
183}
virtual FIND_RESULT Find(const wxString &aCandidate) const override
Return the location and possibly length of a match iff a given candidate string matches the set patte...

References EDA_PATTERN_MATCH_REGEX::Find().

◆ GetPattern()

wxString const & EDA_PATTERN_MATCH_WILDCARD::GetPattern ( ) const
overridevirtual

Return the pattern passed to SetPattern().

Reimplemented from EDA_PATTERN_MATCH_REGEX.

Definition at line 174 of file eda_pattern_match.cpp.

175{
176 return m_wildcard_pattern;
177}

References m_wildcard_pattern.

◆ SetPattern()

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.

Reimplemented in EDA_PATTERN_MATCH_WILDCARD_EXPLICIT.

Definition at line 137 of file eda_pattern_match.cpp.

138{
139 m_wildcard_pattern = aPattern;
140
141 // Compile the wildcard string to a regular expression
142 wxString regex;
143 regex.Alloc( 2 * aPattern.Length() ); // no need to keep resizing, we know the size roughly
144
145 const wxString to_replace = wxT( ".*+?^${}()|[]/\\" );
146
147 for( wxString::const_iterator it = aPattern.begin(); it < aPattern.end(); ++it )
148 {
149 wxUniChar c = *it;
150
151 if( c == '?' )
152 {
153 regex += wxT( "." );
154 }
155 else if( c == '*' )
156 {
157 regex += wxT( ".*" );
158 }
159 else if( to_replace.Find( c ) != wxNOT_FOUND )
160 {
161 regex += "\\";
162 regex += c;
163 }
164 else
165 {
166 regex += c;
167 }
168 }
169
171}
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.

References 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
protected

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