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

References EDA_PATTERN_NOT_FOUND, m_pattern, and m_regex.

Referenced by EDA_PATTERN_MATCH_WILDCARD::Find().

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

References m_pattern.

85 {
86  return m_pattern;
87 }
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 72 of file eda_pattern_match.cpp.

References m_pattern, and m_regex.

Referenced by EDA_PATTERN_MATCH_WILDCARD::SetPattern().

73 {
74  m_pattern = aPattern;
75 
76  // Evil and undocumented: wxRegEx::Compile calls wxLogError on error, even
77  // though it promises to just return false. Silence the error.
78  WX_LOGLEVEL_CONTEXT ctx( wxLOG_FatalError );
79 
80  return m_regex.Compile( aPattern, wxRE_ADVANCED );
81 }
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 93 of file eda_pattern_match.h.

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

wxRegEx EDA_PATTERN_MATCH_REGEX::m_regex
protected

Definition at line 94 of file eda_pattern_match.h.

Referenced by Find(), and SetPattern().


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