|
10 | 10 | my $maxMemory = ($_ = $model->getParameterByName('maxMemory')) ? $_->getValueAt(0)->getCppExpression() : 1000000; |
11 | 11 | %> |
12 | 12 |
|
13 | | -bool MY_OPERATOR::RegexFullMatch(const rstring & str) { |
14 | | - return RE2::FullMatch(str, _regex) == 1; |
| 13 | +template<typename T> |
| 14 | +bool MY_OPERATOR::RegexFullMatch(const T & data) { |
| 15 | + return RE2::FullMatch(getStringPiece(data), _regex) == 1; |
15 | 16 | } |
16 | 17 |
|
17 | | -bool MY_OPERATOR::RegexFullMatch(const blob & blb) { |
18 | | - return RE2::FullMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regex) == 1; |
19 | | -} |
20 | | - |
21 | | -bool MY_OPERATOR::RegexFullMatch(const rstring & str, const rstring & pattern) { |
22 | | - |
23 | | - AutoPortMutex am(_mutex, *this); |
24 | | - if(_regexMap.count(pattern) == 0) { |
25 | | - rstring pat = pattern; |
26 | | - _regexMap.insert(pat, new RE2(pattern, _options)); |
27 | | - } |
28 | | - |
29 | | - return RE2::FullMatch(str, _regexMap.at(pattern)) == 1; |
30 | | -} |
31 | | - |
32 | | -bool MY_OPERATOR::RegexFullMatch(const blob & blb, const rstring & pattern) { |
33 | | - |
| 18 | +template<typename T> |
| 19 | +bool MY_OPERATOR::RegexFullMatch(const T & data, const rstring & pattern) { |
34 | 20 | AutoPortMutex am(_mutex, *this); |
35 | | - if(_regexMap.count(pattern) == 0) { |
36 | | - rstring pat = pattern; |
37 | | - _regexMap.insert(pat, new RE2(pattern, _options)); |
| 21 | + if(_regexMap.count(static_cast<string>(pattern)) == 0) { |
| 22 | + _regexMap.insert(static_cast<string>(pattern), std::auto_ptr<RE2>(new RE2(getStringPiece(pattern), _options))); |
38 | 23 | } |
39 | 24 |
|
40 | | - return RE2::FullMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regexMap.at(pattern)) == 1; |
| 25 | + return RE2::FullMatch(getStringPiece(data), _regexMap.at(static_cast<string>(pattern))) == 1; |
41 | 26 | } |
42 | 27 |
|
43 | | -bool MY_OPERATOR::RegexPartialMatch(const rstring & str) { |
44 | | - return RE2::PartialMatch(str, _regex) == 1; |
| 28 | +template<typename T> |
| 29 | +bool MY_OPERATOR::RegexPartialMatch(const T & data) { |
| 30 | + return RE2::PartialMatch(getStringPiece(data), _regex) == 1; |
45 | 31 | } |
46 | 32 |
|
47 | | -bool MY_OPERATOR::RegexPartialMatch(const blob & blb) { |
48 | | - return RE2::PartialMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regex) == 1; |
49 | | -} |
50 | | - |
51 | | -bool MY_OPERATOR::RegexPartialMatch(const rstring & str, const rstring & pattern) { |
52 | | - |
| 33 | +template<typename T> |
| 34 | +bool MY_OPERATOR::RegexPartialMatch(const T & data, const rstring & pattern) { |
53 | 35 | AutoPortMutex am(_mutex, *this); |
54 | 36 | if(_regexMap.count(pattern) == 0) { |
55 | | - rstring pat = pattern; |
56 | | - _regexMap.insert(pat, new RE2(pattern, _options)); |
| 37 | + _regexMap.insert(static_cast<string>(pattern), std::auto_ptr<RE2>(new RE2(getStringPiece(pattern), _options))); |
57 | 38 | } |
58 | 39 |
|
59 | | - return RE2::PartialMatch(str, _regexMap.at(pattern)) == 1; |
60 | | -} |
61 | | - |
62 | | -bool MY_OPERATOR::RegexPartialMatch(const blob & blb, const rstring & pattern) { |
63 | | - |
64 | | - AutoPortMutex am(_mutex, *this); |
65 | | - if(_regexMap.count(pattern) == 0) { |
66 | | - rstring pat = pattern; |
67 | | - _regexMap.insert(pat, new RE2(pattern, _options)); |
68 | | - } |
69 | | - |
70 | | - return RE2::PartialMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), _regexMap.at(pattern)) == 1; |
71 | | -} |
72 | | - |
73 | | -bool MY_OPERATOR::RegexSimpleMatch(const rstring & str, const rstring & pattern) { |
74 | | - return RE2::PartialMatch(str, pattern) == 1; |
| 40 | + return RE2::PartialMatch(getStringPiece(data), _regexMap.at(static_cast<string>(pattern))) == 1; |
75 | 41 | } |
76 | 42 |
|
77 | | -bool MY_OPERATOR::RegexSimpleMatch(const blob & blb, const rstring & pattern) { |
78 | | - return RE2::PartialMatch(re2::StringPiece(reinterpret_cast<const char*>(blb.getData()), blb.getSize()), pattern) == 1; |
| 43 | +template<typename T> |
| 44 | +bool MY_OPERATOR::RegexSimpleMatch(const T & data, const rstring & pattern) { |
| 45 | + return RE2::PartialMatch(getStringPiece(data), getStringPiece(pattern)) == 1; |
79 | 46 | } |
80 | 47 |
|
81 | | -MY_OPERATOR::MY_OPERATOR() : _options(), _regex(re2::StringPiece(<%=$pattern%>), _options) { |
| 48 | +MY_OPERATOR::MY_OPERATOR() : _options(), _regex(getStringPiece(<%=$pattern%>), _options) { |
82 | 49 | _options.set_log_errors(<%=$logErrors%>); |
83 | 50 | _options.set_max_mem(<%=$maxMemory%>); |
84 | 51 | } |
|
0 commit comments