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

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_pattern
 
wxRegEx m_regex
 

Detailed Description

Definition at line 86 of file eda_pattern_match.h.

Member Function Documentation

int EDA_PATTERN_MATCH_REGEX::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.

Implements EDA_PATTERN_MATCH.

Reimplemented in EDA_PATTERN_MATCH_WILDCARD.

Definition at line 91 of file eda_pattern_match.cpp.

References EDA_PATTERN_NOT_FOUND, m_pattern, and m_regex.

Referenced by EDA_PATTERN_MATCH_WILDCARD::Find().

92 {
93  if( m_regex.IsValid() )
94  {
95  if( m_regex.Matches( aCandidate ) )
96  {
97  size_t start, len;
98  m_regex.GetMatch( &start, &len, 0 );
99  return ( start > INT_MAX ) ? INT_MAX : start;
100  }
101  else
102  {
103  return EDA_PATTERN_NOT_FOUND;
104  }
105  }
106  else
107  {
108  int loc = aCandidate.Find( m_pattern );
109  return ( loc == wxNOT_FOUND ) ? EDA_PATTERN_NOT_FOUND : loc;
110  }
111 }
static const int EDA_PATTERN_NOT_FOUND
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 85 of file eda_pattern_match.cpp.

References m_pattern.

86 {
87  return m_pattern;
88 }
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.

Definition at line 73 of file eda_pattern_match.cpp.

References m_pattern, and m_regex.

Referenced by EDA_PATTERN_MATCH_WILDCARD::SetPattern().

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

Member Data Documentation

wxString EDA_PATTERN_MATCH_REGEX::m_pattern
protected

Definition at line 94 of file eda_pattern_match.h.

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

wxRegEx EDA_PATTERN_MATCH_REGEX::m_regex
protected

Definition at line 95 of file eda_pattern_match.h.

Referenced by Find(), and SetPattern().


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