OLD | NEW |
| (Empty) |
1 // Copyright 2010 The RE2 Authors. All Rights Reserved. | |
2 // Use of this source code is governed by a BSD-style | |
3 // license that can be found in the LICENSE file. | |
4 | |
5 #ifndef RE2_SET_H | |
6 #define RE2_SET_H | |
7 | |
8 #include <utility> | |
9 #include <vector> | |
10 | |
11 #include "re2/re2.h" | |
12 | |
13 namespace re2 { | |
14 using std::vector; | |
15 | |
16 // An RE2::Set represents a collection of regexps that can | |
17 // be searched for simultaneously. | |
18 class RE2::Set { | |
19 public: | |
20 Set(const RE2::Options& options, RE2::Anchor anchor); | |
21 ~Set(); | |
22 | |
23 // Add adds regexp pattern to the set, interpreted using the RE2 options. | |
24 // (The RE2 constructor's default options parameter is RE2::UTF8.) | |
25 // Add returns the regexp index that will be used to identify | |
26 // it in the result of Match, or -1 if the regexp cannot be parsed. | |
27 // Indices are assigned in sequential order starting from 0. | |
28 // Error returns do not increment the index. | |
29 // If an error occurs and error != NULL, *error will hold an error message. | |
30 int Add(const StringPiece& pattern, string* error); | |
31 | |
32 // Compile prepares the Set for matching. | |
33 // Add must not be called again after Compile. | |
34 // Compile must be called before FullMatch or PartialMatch. | |
35 // Compile may return false if it runs out of memory. | |
36 bool Compile(); | |
37 | |
38 // Match returns true if text matches any of the regexps in the set. | |
39 // If so, it fills v with the indices of the matching regexps. | |
40 bool Match(const StringPiece& text, vector<int>* v) const; | |
41 | |
42 private: | |
43 RE2::Options options_; | |
44 RE2::Anchor anchor_; | |
45 vector<re2::Regexp*> re_; | |
46 re2::Prog* prog_; | |
47 bool compiled_; | |
48 //DISALLOW_COPY_AND_ASSIGN(Set); | |
49 Set(const Set&); | |
50 void operator=(const Set&); | |
51 }; | |
52 | |
53 } // namespace re2 | |
54 | |
55 #endif // RE2_SET_H | |
OLD | NEW |