27#include <wx/tokenzr.h>
48 if( loc == wxNOT_FOUND )
51 return { loc,
static_cast<int>(
m_pattern.size() ) };
66 wxLog::SetLogLevel( level );
84 return m_regex.Compile( aPattern, wxRE_ADVANCED );
90 wxString pattern( aPattern );
92 if( !pattern.StartsWith( wxT(
"^" ) ) )
93 pattern = wxT(
"^" ) + pattern;
95 if( !pattern.EndsWith( wxT(
"$" ) ) )
96 pattern += wxT(
"$" );
112 if(
m_regex.Matches( aCandidate ) )
115 m_regex.GetMatch( &start, &len, 0 );
117 return {
static_cast<int>( std::min( start,
static_cast<size_t>( INT_MAX ) ) ),
118 static_cast<int>( std::min( len,
static_cast<size_t>( INT_MAX ) ) ) };
129 if( loc == wxNOT_FOUND )
132 return { loc,
static_cast<int>(
m_pattern.size() ) };
143 regex.Alloc( 2 * aPattern.Length() );
145 const wxString to_replace = wxT(
".*+?^${}()|[]/\\" );
147 for( wxString::const_iterator it = aPattern.begin(); it < aPattern.end(); ++it )
157 regex += wxT(
".*" );
159 else if( to_replace.Find( c ) != wxNOT_FOUND )
192 regex.Alloc( 2 * aPattern.Length() );
194 const wxString to_replace = wxT(
".*+?^${}()|[]/\\" );
198 for( wxString::const_iterator it = aPattern.begin(); it < aPattern.end(); ++it )
208 regex += wxT(
".*" );
210 else if( to_replace.Find( c ) != wxNOT_FOUND )
212 regex += wxS(
"\\" );
242 if( rel == wxS(
"<" ) )
244 else if( rel == wxS(
"<=" ) )
246 else if( rel == wxS(
"=" ) )
248 else if( rel == wxS(
">=" ) )
250 else if( rel == wxS(
">" ) )
261 else if( !val.ToCDouble( &
m_value ) )
266 auto unit_it =
m_units.find( unit.Lower() );
287 wxStringTokenizer tokenizer( aCandidate );
290 while( tokenizer.HasMoreTokens() )
292 const wxString token = tokenizer.GetNextToken();
293 int found_delta =
FindOne( token );
297 size_t found = (size_t) found_delta + lastpos;
298 return {
static_cast<int>( std::min( found,
static_cast<size_t>( INT_MAX ) ) ), 0 };
301 lastpos = tokenizer.GetPosition();
321 int istart = ( start > INT_MAX ) ? INT_MAX : start;
323 if( key.Lower() !=
m_key )
328 if( !val.ToCDouble( &val_parsed ) )
331 auto unit_it =
m_units.find( unit.Lower() );
334 val_parsed *= unit_it->second;
343 case ANY:
return istart;
350 R
"((\w+)[=:]([-+]?[\d.]+)(\w*))", wxRE_ADVANCED );
352 R"(^(\w+)(<|<=|=|>=|>)([-+]?[\d.]*)(\w*)$)", wxRE_ADVANCED );
354 { wxS(
"p" ), 1e-12 },
355 { wxS(
"n" ), 1e-9 },
356 { wxS(
"u" ), 1e-6 },
357 { wxS(
"m" ), 1e-3 },
360 { wxS(
"meg" ), 1e6 },
362 { wxS(
"t" ), 1e12 },
363 { wxS(
"ki" ), 1024. },
364 { wxS(
"mi" ), 1048576. },
365 { wxS(
"gi" ), 1073741824. },
366 { wxS(
"ti" ), 1099511627776. } };
371 m_pattern( aPattern )
377 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX>() );
378 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD>() );
379 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_RELATIONAL>() );
382 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_SUBSTR>() );
386 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX_EXPLICIT>() );
387 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD_EXPLICIT>() );
391 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX>() );
392 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD>() );
393 AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_SUBSTR>() );
402 aMatchersTriggered = 0;
404 for(
const std::unique_ptr<EDA_PATTERN_MATCH>& matcher :
m_matchers )
410 aMatchersTriggered += 1;
413 aPosition = local_find.
start;
428 std::unique_ptr<EDA_PATTERN_MATCH> aMatcher )
430 if ( aMatcher->SetPattern( aPattern ) )
431 m_matchers.push_back( std::move( aMatcher ) );
std::vector< std::unique_ptr< EDA_PATTERN_MATCH > > m_matchers
void AddMatcher(const wxString &aPattern, std::unique_ptr< EDA_PATTERN_MATCH > aMatcher)
EDA_COMBINED_MATCHER(const wxString &aPattern, COMBINED_MATCHER_CONTEXT aContext)
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
const wxString & GetPattern() const
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
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...
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
static wxRegEx m_regex_search
int FindOne(const wxString &aCandidate) const
static wxRegEx m_regex_description
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...
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
static const std::map< wxString, double > m_units
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
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...
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
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...
wxString m_wildcard_pattern
virtual bool SetPattern(const wxString &aPattern) override
Set the pattern against which candidates will be matched.
virtual wxString const & GetPattern() const override
Return the pattern passed to SetPattern().
Context class to set wx loglevel for a block, and always restore it at the end.
WX_LOGLEVEL_CONTEXT(wxLogLevel level)
Abstract pattern-matching tool and implementations.
static const int EDA_PATTERN_NOT_FOUND