#include <DQMStore.h>
Public Member Functions | |
fastmatch (std::string const &_fastString) | |
bool | match (std::string const &s) const |
~fastmatch () | |
Private Types | |
enum | MatchingHeuristicEnum { UseFull, OneStarStart, OneStarEnd, TwoStar } |
Private Member Functions | |
bool | compare_strings (std::string const &pattern, std::string const &input) const |
bool | compare_strings_reverse (std::string const &pattern, std::string const &input) const |
Private Attributes | |
std::string | fastString_ |
MatchingHeuristicEnum | matching_ |
lat::Regexp * | regexp_ |
Implements RegEx patterns which occur often in a high-performant mattern. For all other expressions, the full RegEx engine is used. Note: this class can only be used for lat::Regexp::Wildcard-like patterns.
Definition at line 43 of file DQMStore.h.
enum fastmatch::MatchingHeuristicEnum [private] |
Definition at line 46 of file DQMStore.h.
{ UseFull, OneStarStart, OneStarEnd, TwoStar };
fastmatch::fastmatch | ( | std::string const & | _fastString | ) |
Definition at line 122 of file DQMStore.cc.
References alignCSCRings::e, fastString_, matching_, NULL, OneStarEnd, OneStarStart, pos, raiseDQMError(), regexp_, and TwoStar.
: fastString_ (_fastString), matching_ (UseFull) { try { regexp_ = NULL; regexp_ = new lat::Regexp(fastString_, 0, lat::Regexp::Wildcard); regexp_->study(); } catch (lat::Error &e) { delete regexp_; raiseDQMError("DQMStore", "Invalid wildcard pattern '%s' in quality" " test specification", fastString_.c_str()); } // count stars ( "*" ) size_t starCount = 0; int pos = -1; while (true) { pos = fastString_.find("*", pos + 1 ); if ((size_t)pos == std::string::npos) break; starCount ++; } // investigate for heuristics if ((fastString_.find('"') != std::string::npos) || (fastString_.find(']') != std::string::npos) || (fastString_.find('?') != std::string::npos) || (fastString_.find('\\') != std::string::npos) || (starCount > 2)) { // no fast version can be used return; } // match for pattern "*MyString" and "MyString*" if (starCount == 1) { if (boost::algorithm::starts_with(fastString_, "*")) { matching_ = OneStarStart; fastString_.erase(0,1); return; } if (boost::algorithm::ends_with(fastString_, "*")) { matching_ = OneStarEnd; fastString_.erase(fastString_.length()-1,1); return; } } // match for pattern "*MyString*" if (starCount == 2) { if (boost::algorithm::starts_with(fastString_, "*") && boost::algorithm::ends_with(fastString_, "*")) { matching_ = TwoStar; fastString_.erase(0,1); fastString_.erase(fastString_.size() - 1, 1); return; } } }
fastmatch::~fastmatch | ( | ) |
bool fastmatch::compare_strings | ( | std::string const & | pattern, |
std::string const & | input | ||
) | const [private] |
Definition at line 219 of file DQMStore.cc.
Referenced by match().
{ if (input.size() < pattern.size()) return false; // compare the two strings character by character for equalness: // this does not create uneeded copies of std::string. The // boost::algorithm implementation does. std::string::const_iterator rit_pattern = pattern.begin(); std::string::const_iterator rit_input = input.begin(); for (; rit_pattern < pattern.end(); rit_pattern++, rit_input++) { if (*rit_pattern != *rit_input) // found a difference, fail return false; } return true; }
bool fastmatch::compare_strings_reverse | ( | std::string const & | pattern, |
std::string const & | input | ||
) | const [private] |
Definition at line 198 of file DQMStore.cc.
Referenced by match().
{ if (input.size() < pattern.size()) return false; // compare the two strings character by character for equalness: // this does not create uneeded copies of std::string. The // boost::algorithm implementation does std::string::const_reverse_iterator rit_pattern = pattern.rbegin(); std::string::const_reverse_iterator rit_input = input.rbegin(); for (; rit_pattern < pattern.rend(); rit_pattern++, rit_input++) { if (*rit_pattern != *rit_input) // found a difference, fail return false; } return true; }
bool fastmatch::match | ( | std::string const & | s | ) | const |
Definition at line 240 of file DQMStore.cc.
References compare_strings(), compare_strings_reverse(), fastString_, matching_, OneStarEnd, OneStarStart, regexp_, and TwoStar.
{ switch (matching_) { case OneStarStart: return compare_strings_reverse(fastString_, s); case OneStarEnd: return compare_strings(fastString_, s); case TwoStar: return (s.find(fastString_) != std::string::npos); default: return regexp_->match(s); } }
std::string fastmatch::fastString_ [private] |
Definition at line 63 of file DQMStore.h.
Referenced by fastmatch(), and match().
MatchingHeuristicEnum fastmatch::matching_ [private] |
Definition at line 64 of file DQMStore.h.
Referenced by fastmatch(), and match().
lat::Regexp* fastmatch::regexp_ [private] |
Definition at line 62 of file DQMStore.h.
Referenced by fastmatch(), match(), and ~fastmatch().