1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#ifndef GENERS_SEARCHSPECIFIER_HH_
#define GENERS_SEARCHSPECIFIER_HH_
#include <string>
#include "Alignment/Geners/interface/Regex.hh"
namespace gs {
class SearchSpecifier {
public:
inline SearchSpecifier(const char *exact) : tag_(exact ? exact : ""), useRegex_(false) {}
inline SearchSpecifier(const std::string &exact) : tag_(exact), useRegex_(false) {}
inline SearchSpecifier(const Regex ®ex) : regex_(regex), useRegex_(true) {}
// Note that the C++11 regex object does not specify a way to
// extract the regular expression from it. Sometimes, however,
// it is useful to have a way to print the expression searched.
// The following special constructor helps: it can be used in
// case one wants to use regex but also wants to remember the
// regular expression itself. This constructor can also be useful
// in case the code gets a command line switch on whether to use
// regular expressions or not. Note that, for C++11 regex, the
// regex flavor can no longer be specified (default is used).
//
inline SearchSpecifier(const std::string &expr, const bool useRegex)
: tag_(expr), regex_(useRegex ? expr : std::string()), useRegex_(useRegex) {}
inline bool useRegex() const { return useRegex_; }
inline const std::string &pattern() const { return tag_; }
bool matches(const std::string &sentence) const;
SearchSpecifier() = delete;
private:
std::string tag_;
Regex regex_;
bool useRegex_;
};
} // namespace gs
#endif // GENERS_SEARCHSPECIFIER_HH_
|