KiCad PCB EDA Suite
EDA_PATTERN_MATCH_REGEX Class Reference

#include <eda_pattern_match.h>

Inheritance diagram for EDA_PATTERN_MATCH_REGEX:
EDA_PATTERN_MATCH EDA_PATTERN_MATCH_WILDCARD 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_pattern
 
wxRegEx m_regex
 

Detailed Description

Definition at line 102 of file eda_pattern_match.h.

Member Function Documentation

◆ Find()

EDA_PATTERN_MATCH::FIND_RESULT EDA_PATTERN_MATCH_REGEX::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.

Implements EDA_PATTERN_MATCH.

Reimplemented in EDA_PATTERN_MATCH_WILDCARD.

Definition at line 94 of file eda_pattern_match.cpp.

95{
96 if( m_regex.IsValid() )
97 {
98 if( m_regex.Matches( aCandidate ) )
99 {
100 size_t start, len;
101 m_regex.GetMatch( &start, &len, 0 );
102
103 return { static_cast<int>( std::min( start, static_cast<size_t>( INT_MAX ) ) ),
104 static_cast<int>( std::min( len, static_cast<size_t>( INT_MAX ) ) ) };
105 }
106 else
107 {
108 return {};
109 }
110 }
111 else
112 {
113 int loc = aCandidate.Find( m_pattern );
114
115 if( loc == wxNOT_FOUND )
116 return {};
117 else
118 return { loc, static_cast<int>( m_pattern.size() ) };
119 }
120}

References m_pattern, and m_regex.

Referenced by EDA_PATTERN_MATCH_WILDCARD::Find().

◆ GetPattern()

wxString const & EDA_PATTERN_MATCH_REGEX::GetPattern ( ) const
overridevirtual

Return the pattern passed to SetPattern().

Implements EDA_PATTERN_MATCH.

Reimplemented in EDA_PATTERN_MATCH_WILDCARD.

Definition at line 88 of file eda_pattern_match.cpp.

89{
90 return m_pattern;
91}

References m_pattern.

◆ SetPattern()

bool EDA_PATTERN_MATCH_REGEX::SetPattern ( const wxString &  aPattern)
overridevirtual

Set the pattern against which candidates will be matched.

If the pattern can not be processed, returns false.

Implements EDA_PATTERN_MATCH.

Reimplemented in EDA_PATTERN_MATCH_WILDCARD, and EDA_PATTERN_MATCH_WILDCARD_EXPLICIT.

Definition at line 76 of file eda_pattern_match.cpp.

77{
78 m_pattern = aPattern;
79
80 // Evil and undocumented: wxRegEx::Compile calls wxLogError on error, even
81 // though it promises to just return false. Silence the error.
82 WX_LOGLEVEL_CONTEXT ctx( wxLOG_FatalError );
83
84 return m_regex.Compile( aPattern, wxRE_ADVANCED );
85}
Context class to set wx loglevel for a block, and always restore it at the end.

References m_pattern, and m_regex.

Referenced by EDA_PATTERN_MATCH_WILDCARD::SetPattern(), and EDA_PATTERN_MATCH_WILDCARD_EXPLICIT::SetPattern().

Member Data Documentation

◆ m_pattern

wxString EDA_PATTERN_MATCH_REGEX::m_pattern
protected

Definition at line 110 of file eda_pattern_match.h.

Referenced by Find(), GetPattern(), and SetPattern().

◆ m_regex

wxRegEx EDA_PATTERN_MATCH_REGEX::m_regex
protected

Definition at line 111 of file eda_pattern_match.h.

Referenced by Find(), and SetPattern().


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