Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:20

0001 #ifndef GENERS_SEARCHSPECIFIER_HH_
0002 #define GENERS_SEARCHSPECIFIER_HH_
0003 
0004 #include <string>
0005 
0006 #include "Alignment/Geners/interface/Regex.hh"
0007 
0008 namespace gs {
0009   class SearchSpecifier {
0010   public:
0011     inline SearchSpecifier(const char *exact) : tag_(exact ? exact : ""), useRegex_(false) {}
0012 
0013     inline SearchSpecifier(const std::string &exact) : tag_(exact), useRegex_(false) {}
0014 
0015     inline SearchSpecifier(const Regex &regex) : regex_(regex), useRegex_(true) {}
0016 
0017     // Note that the C++11 regex object does not specify a way to
0018     // extract the regular expression from it. Sometimes, however,
0019     // it is useful to have a way to print the expression searched.
0020     // The following special constructor helps: it can be used in
0021     // case one wants to use regex but also wants to remember the
0022     // regular expression itself. This constructor can also be useful
0023     // in case the code gets a command line switch on whether to use
0024     // regular expressions or not. Note that, for C++11 regex, the
0025     // regex flavor can no longer be specified (default is used).
0026     //
0027     inline SearchSpecifier(const std::string &expr, const bool useRegex)
0028         : tag_(expr), regex_(useRegex ? expr : std::string()), useRegex_(useRegex) {}
0029 
0030     inline bool useRegex() const { return useRegex_; }
0031     inline const std::string &pattern() const { return tag_; }
0032 
0033     bool matches(const std::string &sentence) const;
0034 
0035     SearchSpecifier() = delete;
0036 
0037   private:
0038     std::string tag_;
0039     Regex regex_;
0040     bool useRegex_;
0041   };
0042 }  // namespace gs
0043 
0044 #endif  // GENERS_SEARCHSPECIFIER_HH_