re2 1.19.2 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/actions/linux-alpine-node-16/Dockerfile +1 -1
- package/.github/actions/linux-alpine-node-18/Dockerfile +1 -1
- package/.github/actions/linux-alpine-node-20/Dockerfile +1 -1
- package/.gitmodules +5 -2
- package/README.md +1 -0
- package/binding.gyp +82 -25
- package/lib/replace.cc +4 -4
- package/package.json +1 -1
- package/tsconfig.json +2 -1
- package/vendor/re2/.bazelrc +16 -0
- package/vendor/re2/.github/bazel.sh +24 -0
- package/vendor/re2/.github/cmake.sh +12 -0
- package/vendor/re2/.github/workflows/ci-bazel.yml +17 -0
- package/vendor/re2/.github/workflows/ci-cmake.yml +108 -0
- package/vendor/re2/.github/workflows/ci.yml +89 -0
- package/vendor/re2/.github/workflows/pr.yml +26 -0
- package/vendor/re2/.github/workflows/python.yml +185 -0
- package/vendor/re2/AUTHORS +13 -0
- package/vendor/re2/BUILD.bazel +280 -0
- package/vendor/re2/CMakeLists.txt +268 -0
- package/vendor/re2/CONTRIBUTING.md +2 -0
- package/vendor/re2/CONTRIBUTORS +41 -0
- package/vendor/re2/Makefile +400 -0
- package/vendor/{README → re2/README} +5 -0
- package/vendor/re2/SECURITY.md +4 -0
- package/vendor/re2/WORKSPACE.bazel +62 -0
- package/vendor/re2/app/BUILD.bazel +19 -0
- package/vendor/re2/app/_re2.cc +94 -0
- package/vendor/re2/app/_re2.d.ts +23 -0
- package/vendor/re2/app/app.ts +111 -0
- package/vendor/re2/app/build.sh +50 -0
- package/vendor/re2/app/index.html +5 -0
- package/vendor/re2/app/package.json +14 -0
- package/vendor/re2/app/rollup.config.js +28 -0
- package/vendor/re2/app/tsconfig.json +17 -0
- package/vendor/re2/benchlog/benchplot.py +98 -0
- package/vendor/re2/benchlog/mktable +155 -0
- package/vendor/re2/doc/mksyntaxgo +42 -0
- package/vendor/re2/doc/mksyntaxhtml +42 -0
- package/vendor/re2/doc/mksyntaxwiki +36 -0
- package/vendor/re2/doc/syntax.html +477 -0
- package/vendor/re2/doc/syntax.txt +463 -0
- package/vendor/re2/lib/git/commit-msg.hook +104 -0
- package/vendor/re2/libre2.symbols +19 -0
- package/vendor/re2/libre2.symbols.darwin +15 -0
- package/vendor/re2/python/BUILD.bazel +36 -0
- package/vendor/re2/python/README +1 -0
- package/vendor/re2/python/_re2.cc +338 -0
- package/vendor/re2/python/re2.py +582 -0
- package/vendor/re2/python/re2_test.py +482 -0
- package/vendor/re2/python/setup.py +105 -0
- package/vendor/re2/{bitmap256.cc → re2/bitmap256.cc} +4 -4
- package/vendor/re2/{bitstate.cc → re2/bitstate.cc} +21 -25
- package/vendor/re2/{compile.cc → re2/compile.cc} +5 -4
- package/vendor/re2/{dfa.cc → re2/dfa.cc} +120 -101
- package/vendor/re2/{filtered_re2.cc → re2/filtered_re2.cc} +8 -11
- package/vendor/re2/{filtered_re2.h → re2/filtered_re2.h} +5 -4
- package/vendor/re2/{fuzzing → re2/fuzzing}/re2_fuzzer.cc +4 -6
- package/vendor/re2/{mimics_pcre.cc → re2/mimics_pcre.cc} +0 -1
- package/vendor/re2/{nfa.cc → re2/nfa.cc} +34 -37
- package/vendor/re2/{onepass.cc → re2/onepass.cc} +25 -27
- package/vendor/re2/{parse.cc → re2/parse.cc} +118 -121
- package/vendor/re2/{prefilter.cc → re2/prefilter.cc} +2 -3
- package/vendor/re2/{prefilter.h → re2/prefilter.h} +0 -1
- package/vendor/re2/{prefilter_tree.cc → re2/prefilter_tree.cc} +4 -5
- package/vendor/re2/{prefilter_tree.h → re2/prefilter_tree.h} +1 -2
- package/vendor/re2/{prog.cc → re2/prog.cc} +20 -21
- package/vendor/re2/{prog.h → re2/prog.h} +21 -22
- package/vendor/re2/{re2.cc → re2/re2.cc} +51 -62
- package/vendor/re2/{re2.h → re2/re2.h} +78 -40
- package/vendor/re2/{regexp.cc → re2/regexp.cc} +11 -12
- package/vendor/re2/{regexp.h → re2/regexp.h} +9 -10
- package/vendor/re2/{set.cc → re2/set.cc} +3 -5
- package/vendor/re2/{set.h → re2/set.h} +4 -3
- package/vendor/re2/{simplify.cc → re2/simplify.cc} +1 -2
- package/vendor/re2/re2/stringpiece.h +24 -0
- package/vendor/re2/{testing → re2/testing}/backtrack.cc +22 -25
- package/vendor/re2/{testing → re2/testing}/charclass_test.cc +23 -21
- package/vendor/re2/{testing → re2/testing}/compile_test.cc +5 -4
- package/vendor/re2/{testing → re2/testing}/dfa_test.cc +36 -30
- package/vendor/re2/{testing → re2/testing}/dump.cc +8 -8
- package/vendor/re2/{testing → re2/testing}/exhaustive1_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive2_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive3_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive_tester.cc +36 -32
- package/vendor/re2/{testing → re2/testing}/exhaustive_tester.h +0 -1
- package/vendor/re2/{testing → re2/testing}/filtered_re2_test.cc +9 -8
- package/vendor/re2/{testing → re2/testing}/mimics_pcre_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/null_walker.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/parse_test.cc +13 -12
- package/vendor/re2/{testing → re2/testing}/possible_match_test.cc +15 -14
- package/vendor/re2/{testing → re2/testing}/random_test.cc +13 -12
- package/vendor/re2/{testing → re2/testing}/re2_arg_test.cc +25 -2
- package/vendor/re2/{testing → re2/testing}/re2_test.cc +49 -47
- package/vendor/re2/{testing → re2/testing}/regexp_benchmark.cc +144 -145
- package/vendor/re2/{testing → re2/testing}/regexp_generator.cc +18 -14
- package/vendor/re2/{testing → re2/testing}/regexp_generator.h +3 -4
- package/vendor/re2/{testing → re2/testing}/regexp_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/required_prefix_test.cc +5 -4
- package/vendor/re2/{testing → re2/testing}/search_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/set_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/simplify_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/string_generator.cc +3 -3
- package/vendor/re2/{testing → re2/testing}/string_generator.h +5 -6
- package/vendor/re2/{testing → re2/testing}/string_generator_test.cc +2 -2
- package/vendor/re2/{testing → re2/testing}/tester.cc +77 -78
- package/vendor/re2/{testing → re2/testing}/tester.h +13 -15
- package/vendor/re2/{tostring.cc → re2/tostring.cc} +7 -8
- package/vendor/re2/{unicode_casefold.h → re2/unicode_casefold.h} +0 -1
- package/vendor/re2/{unicode_groups.h → re2/unicode_groups.h} +0 -1
- package/vendor/re2/{walker-inl.h → re2/walker-inl.h} +2 -1
- package/vendor/re2/re2.pc.in +9 -0
- package/vendor/re2/re2Config.cmake.in +28 -0
- package/vendor/re2/runtests +33 -0
- package/vendor/re2/testinstall.cc +27 -0
- package/vendor/re2/ucs2.diff +567 -0
- package/vendor/{util → re2/util}/logging.h +2 -2
- package/vendor/{util → re2/util}/pcre.cc +47 -116
- package/vendor/{util → re2/util}/pcre.h +53 -63
- package/vendor/re2/util/strutil.cc +26 -0
- package/vendor/{util → re2/util}/strutil.h +0 -5
- package/vendor/re2/stringpiece.cc +0 -65
- package/vendor/re2/stringpiece.h +0 -213
- package/vendor/util/benchmark.cc +0 -131
- package/vendor/util/benchmark.h +0 -156
- package/vendor/util/flags.h +0 -26
- package/vendor/util/mix.h +0 -41
- package/vendor/util/mutex.h +0 -164
- package/vendor/util/strutil.cc +0 -149
- package/vendor/util/test.cc +0 -34
- package/vendor/util/test.h +0 -50
- package/vendor/util/util.h +0 -42
- /package/vendor/{LICENSE → re2/LICENSE} +0 -0
- /package/vendor/re2/{bitmap256.h → re2/bitmap256.h} +0 -0
- /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/LICENSE +0 -0
- /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/include/fuzzer/FuzzedDataProvider.h +0 -0
- /package/vendor/re2/{make_perl_groups.pl → re2/make_perl_groups.pl} +0 -0
- /package/vendor/re2/{make_unicode_casefold.py → re2/make_unicode_casefold.py} +0 -0
- /package/vendor/re2/{make_unicode_groups.py → re2/make_unicode_groups.py} +0 -0
- /package/vendor/re2/{perl_groups.cc → re2/perl_groups.cc} +0 -0
- /package/vendor/re2/{pod_array.h → re2/pod_array.h} +0 -0
- /package/vendor/re2/{sparse_array.h → re2/sparse_array.h} +0 -0
- /package/vendor/re2/{sparse_set.h → re2/sparse_set.h} +0 -0
- /package/vendor/re2/{unicode.py → re2/unicode.py} +0 -0
- /package/vendor/re2/{unicode_casefold.cc → re2/unicode_casefold.cc} +0 -0
- /package/vendor/re2/{unicode_groups.cc → re2/unicode_groups.cc} +0 -0
- /package/vendor/{util → re2/util}/fuzz.cc +0 -0
- /package/vendor/{util → re2/util}/malloc_counter.h +0 -0
- /package/vendor/{util → re2/util}/rune.cc +0 -0
- /package/vendor/{util → re2/util}/utf.h +0 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// Copyright 2019 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
|
+
#include <memory>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <tuple>
|
|
8
|
+
#include <utility>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
#include <pybind11/pybind11.h>
|
|
12
|
+
#include <pybind11/stl.h>
|
|
13
|
+
#include "absl/strings/string_view.h"
|
|
14
|
+
#include "re2/filtered_re2.h"
|
|
15
|
+
#include "re2/re2.h"
|
|
16
|
+
#include "re2/set.h"
|
|
17
|
+
|
|
18
|
+
#ifdef _WIN32
|
|
19
|
+
#include <basetsd.h>
|
|
20
|
+
#define ssize_t SSIZE_T
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
namespace re2_python {
|
|
24
|
+
|
|
25
|
+
// This is conventional.
|
|
26
|
+
namespace py = pybind11;
|
|
27
|
+
|
|
28
|
+
// In terms of the pybind11 API, a py::buffer is merely a py::object that
|
|
29
|
+
// supports the buffer interface/protocol and you must explicitly request
|
|
30
|
+
// a py::buffer_info in order to access the actual bytes. Under the hood,
|
|
31
|
+
// the py::buffer_info manages a reference count to the py::buffer, so it
|
|
32
|
+
// must be constructed and subsequently destructed while holding the GIL.
|
|
33
|
+
static inline absl::string_view FromBytes(const py::buffer_info& bytes) {
|
|
34
|
+
char* data = reinterpret_cast<char*>(bytes.ptr);
|
|
35
|
+
ssize_t size = bytes.size;
|
|
36
|
+
return absl::string_view(data, size);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static inline int OneCharLen(const char* ptr) {
|
|
40
|
+
return "\1\1\1\1\1\1\1\1\1\1\1\1\2\2\3\4"[(*ptr & 0xFF) >> 4];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Helper function for when Python encodes str to bytes and then needs to
|
|
44
|
+
// convert str offsets to bytes offsets. Assumes that text is valid UTF-8.
|
|
45
|
+
ssize_t CharLenToBytes(py::buffer buffer, ssize_t pos, ssize_t len) {
|
|
46
|
+
auto bytes = buffer.request();
|
|
47
|
+
auto text = FromBytes(bytes);
|
|
48
|
+
auto ptr = text.data() + pos;
|
|
49
|
+
auto end = text.data() + text.size();
|
|
50
|
+
while (ptr < end && len > 0) {
|
|
51
|
+
ptr += OneCharLen(ptr);
|
|
52
|
+
--len;
|
|
53
|
+
}
|
|
54
|
+
return ptr - (text.data() + pos);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Helper function for when Python decodes bytes to str and then needs to
|
|
58
|
+
// convert bytes offsets to str offsets. Assumes that text is valid UTF-8.
|
|
59
|
+
ssize_t BytesToCharLen(py::buffer buffer, ssize_t pos, ssize_t endpos) {
|
|
60
|
+
auto bytes = buffer.request();
|
|
61
|
+
auto text = FromBytes(bytes);
|
|
62
|
+
auto ptr = text.data() + pos;
|
|
63
|
+
auto end = text.data() + endpos;
|
|
64
|
+
ssize_t len = 0;
|
|
65
|
+
while (ptr < end) {
|
|
66
|
+
ptr += OneCharLen(ptr);
|
|
67
|
+
++len;
|
|
68
|
+
}
|
|
69
|
+
return len;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
std::unique_ptr<RE2> RE2InitShim(py::buffer buffer,
|
|
73
|
+
const RE2::Options& options) {
|
|
74
|
+
auto bytes = buffer.request();
|
|
75
|
+
auto pattern = FromBytes(bytes);
|
|
76
|
+
return std::make_unique<RE2>(pattern, options);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
py::bytes RE2ErrorShim(const RE2& self) {
|
|
80
|
+
// Return std::string as bytes. That is, without decoding to str.
|
|
81
|
+
return self.error();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
std::vector<std::pair<py::bytes, int>> RE2NamedCapturingGroupsShim(
|
|
85
|
+
const RE2& self) {
|
|
86
|
+
const int num_groups = self.NumberOfCapturingGroups();
|
|
87
|
+
std::vector<std::pair<py::bytes, int>> groups;
|
|
88
|
+
groups.reserve(num_groups);
|
|
89
|
+
for (const auto& it : self.NamedCapturingGroups()) {
|
|
90
|
+
groups.emplace_back(it.first, it.second);
|
|
91
|
+
}
|
|
92
|
+
return groups;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
std::vector<int> RE2ProgramFanoutShim(const RE2& self) {
|
|
96
|
+
std::vector<int> histogram;
|
|
97
|
+
self.ProgramFanout(&histogram);
|
|
98
|
+
return histogram;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
std::vector<int> RE2ReverseProgramFanoutShim(const RE2& self) {
|
|
102
|
+
std::vector<int> histogram;
|
|
103
|
+
self.ReverseProgramFanout(&histogram);
|
|
104
|
+
return histogram;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
std::tuple<bool, py::bytes, py::bytes> RE2PossibleMatchRangeShim(
|
|
108
|
+
const RE2& self, int maxlen) {
|
|
109
|
+
std::string min, max;
|
|
110
|
+
// Return std::string as bytes. That is, without decoding to str.
|
|
111
|
+
return {self.PossibleMatchRange(&min, &max, maxlen), min, max};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
std::vector<std::pair<ssize_t, ssize_t>> RE2MatchShim(const RE2& self,
|
|
115
|
+
RE2::Anchor anchor,
|
|
116
|
+
py::buffer buffer,
|
|
117
|
+
ssize_t pos,
|
|
118
|
+
ssize_t endpos) {
|
|
119
|
+
auto bytes = buffer.request();
|
|
120
|
+
auto text = FromBytes(bytes);
|
|
121
|
+
const int num_groups = self.NumberOfCapturingGroups() + 1; // need $0
|
|
122
|
+
std::vector<absl::string_view> groups;
|
|
123
|
+
groups.resize(num_groups);
|
|
124
|
+
py::gil_scoped_release release_gil;
|
|
125
|
+
if (!self.Match(text, pos, endpos, anchor, groups.data(), groups.size())) {
|
|
126
|
+
// Ensure that groups are null before converting to spans!
|
|
127
|
+
for (auto& it : groups) {
|
|
128
|
+
it = absl::string_view();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
std::vector<std::pair<ssize_t, ssize_t>> spans;
|
|
132
|
+
spans.reserve(num_groups);
|
|
133
|
+
for (const auto& it : groups) {
|
|
134
|
+
if (it.data() == NULL) {
|
|
135
|
+
spans.emplace_back(-1, -1);
|
|
136
|
+
} else {
|
|
137
|
+
spans.emplace_back(it.data() - text.data(),
|
|
138
|
+
it.data() - text.data() + it.size());
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return spans;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
py::bytes RE2QuoteMetaShim(py::buffer buffer) {
|
|
145
|
+
auto bytes = buffer.request();
|
|
146
|
+
auto pattern = FromBytes(bytes);
|
|
147
|
+
// Return std::string as bytes. That is, without decoding to str.
|
|
148
|
+
return RE2::QuoteMeta(pattern);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
class Set {
|
|
152
|
+
public:
|
|
153
|
+
Set(RE2::Anchor anchor, const RE2::Options& options)
|
|
154
|
+
: set_(options, anchor) {}
|
|
155
|
+
|
|
156
|
+
~Set() = default;
|
|
157
|
+
|
|
158
|
+
// Not copyable or movable.
|
|
159
|
+
Set(const Set&) = delete;
|
|
160
|
+
Set& operator=(const Set&) = delete;
|
|
161
|
+
|
|
162
|
+
int Add(py::buffer buffer) {
|
|
163
|
+
auto bytes = buffer.request();
|
|
164
|
+
auto pattern = FromBytes(bytes);
|
|
165
|
+
int index = set_.Add(pattern, /*error=*/NULL); // -1 on error
|
|
166
|
+
return index;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
bool Compile() {
|
|
170
|
+
// Compiling can fail.
|
|
171
|
+
return set_.Compile();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
std::vector<int> Match(py::buffer buffer) const {
|
|
175
|
+
auto bytes = buffer.request();
|
|
176
|
+
auto text = FromBytes(bytes);
|
|
177
|
+
std::vector<int> matches;
|
|
178
|
+
py::gil_scoped_release release_gil;
|
|
179
|
+
set_.Match(text, &matches);
|
|
180
|
+
return matches;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private:
|
|
184
|
+
RE2::Set set_;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
class Filter {
|
|
188
|
+
public:
|
|
189
|
+
Filter() = default;
|
|
190
|
+
~Filter() = default;
|
|
191
|
+
|
|
192
|
+
// Not copyable or movable.
|
|
193
|
+
Filter(const Filter&) = delete;
|
|
194
|
+
Filter& operator=(const Filter&) = delete;
|
|
195
|
+
|
|
196
|
+
int Add(py::buffer buffer, const RE2::Options& options) {
|
|
197
|
+
auto bytes = buffer.request();
|
|
198
|
+
auto pattern = FromBytes(bytes);
|
|
199
|
+
int index = -1; // not clobbered on error
|
|
200
|
+
filter_.Add(pattern, options, &index);
|
|
201
|
+
return index;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
bool Compile() {
|
|
205
|
+
std::vector<std::string> atoms;
|
|
206
|
+
filter_.Compile(&atoms);
|
|
207
|
+
RE2::Options options;
|
|
208
|
+
options.set_literal(true);
|
|
209
|
+
options.set_case_sensitive(false);
|
|
210
|
+
set_ = std::make_unique<RE2::Set>(options, RE2::UNANCHORED);
|
|
211
|
+
for (int i = 0; i < static_cast<int>(atoms.size()); ++i) {
|
|
212
|
+
if (set_->Add(atoms[i], /*error=*/NULL) != i) {
|
|
213
|
+
// Should never happen: the atom is a literal!
|
|
214
|
+
py::pybind11_fail("set_->Add() failed");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// Compiling can fail.
|
|
218
|
+
return set_->Compile();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
std::vector<int> Match(py::buffer buffer, bool potential) const {
|
|
222
|
+
auto bytes = buffer.request();
|
|
223
|
+
auto text = FromBytes(bytes);
|
|
224
|
+
std::vector<int> atoms;
|
|
225
|
+
py::gil_scoped_release release_gil;
|
|
226
|
+
set_->Match(text, &atoms);
|
|
227
|
+
std::vector<int> matches;
|
|
228
|
+
if (potential) {
|
|
229
|
+
filter_.AllPotentials(atoms, &matches);
|
|
230
|
+
} else {
|
|
231
|
+
filter_.AllMatches(text, atoms, &matches);
|
|
232
|
+
}
|
|
233
|
+
return matches;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const RE2& GetRE2(int index) const {
|
|
237
|
+
return filter_.GetRE2(index);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private:
|
|
241
|
+
re2::FilteredRE2 filter_;
|
|
242
|
+
std::unique_ptr<RE2::Set> set_;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
PYBIND11_MODULE(_re2, module) {
|
|
246
|
+
module.def("CharLenToBytes", &CharLenToBytes);
|
|
247
|
+
module.def("BytesToCharLen", &BytesToCharLen);
|
|
248
|
+
|
|
249
|
+
// CLASSES
|
|
250
|
+
// class RE2
|
|
251
|
+
// enum Anchor
|
|
252
|
+
// class Options
|
|
253
|
+
// enum Encoding
|
|
254
|
+
// class Set
|
|
255
|
+
// class Filter
|
|
256
|
+
py::class_<RE2> re2(module, "RE2");
|
|
257
|
+
py::enum_<RE2::Anchor> anchor(re2, "Anchor");
|
|
258
|
+
py::class_<RE2::Options> options(re2, "Options");
|
|
259
|
+
py::enum_<RE2::Options::Encoding> encoding(options, "Encoding");
|
|
260
|
+
py::class_<Set> set(module, "Set");
|
|
261
|
+
py::class_<Filter> filter(module, "Filter");
|
|
262
|
+
|
|
263
|
+
anchor.value("UNANCHORED", RE2::Anchor::UNANCHORED);
|
|
264
|
+
anchor.value("ANCHOR_START", RE2::Anchor::ANCHOR_START);
|
|
265
|
+
anchor.value("ANCHOR_BOTH", RE2::Anchor::ANCHOR_BOTH);
|
|
266
|
+
|
|
267
|
+
encoding.value("UTF8", RE2::Options::Encoding::EncodingUTF8);
|
|
268
|
+
encoding.value("LATIN1", RE2::Options::Encoding::EncodingLatin1);
|
|
269
|
+
|
|
270
|
+
options.def(py::init<>())
|
|
271
|
+
.def_property("max_mem", //
|
|
272
|
+
&RE2::Options::max_mem, //
|
|
273
|
+
&RE2::Options::set_max_mem) //
|
|
274
|
+
.def_property("encoding", //
|
|
275
|
+
&RE2::Options::encoding, //
|
|
276
|
+
&RE2::Options::set_encoding) //
|
|
277
|
+
.def_property("posix_syntax", //
|
|
278
|
+
&RE2::Options::posix_syntax, //
|
|
279
|
+
&RE2::Options::set_posix_syntax) //
|
|
280
|
+
.def_property("longest_match", //
|
|
281
|
+
&RE2::Options::longest_match, //
|
|
282
|
+
&RE2::Options::set_longest_match) //
|
|
283
|
+
.def_property("log_errors", //
|
|
284
|
+
&RE2::Options::log_errors, //
|
|
285
|
+
&RE2::Options::set_log_errors) //
|
|
286
|
+
.def_property("literal", //
|
|
287
|
+
&RE2::Options::literal, //
|
|
288
|
+
&RE2::Options::set_literal) //
|
|
289
|
+
.def_property("never_nl", //
|
|
290
|
+
&RE2::Options::never_nl, //
|
|
291
|
+
&RE2::Options::set_never_nl) //
|
|
292
|
+
.def_property("dot_nl", //
|
|
293
|
+
&RE2::Options::dot_nl, //
|
|
294
|
+
&RE2::Options::set_dot_nl) //
|
|
295
|
+
.def_property("never_capture", //
|
|
296
|
+
&RE2::Options::never_capture, //
|
|
297
|
+
&RE2::Options::set_never_capture) //
|
|
298
|
+
.def_property("case_sensitive", //
|
|
299
|
+
&RE2::Options::case_sensitive, //
|
|
300
|
+
&RE2::Options::set_case_sensitive) //
|
|
301
|
+
.def_property("perl_classes", //
|
|
302
|
+
&RE2::Options::perl_classes, //
|
|
303
|
+
&RE2::Options::set_perl_classes) //
|
|
304
|
+
.def_property("word_boundary", //
|
|
305
|
+
&RE2::Options::word_boundary, //
|
|
306
|
+
&RE2::Options::set_word_boundary) //
|
|
307
|
+
.def_property("one_line", //
|
|
308
|
+
&RE2::Options::one_line, //
|
|
309
|
+
&RE2::Options::set_one_line); //
|
|
310
|
+
|
|
311
|
+
re2.def(py::init(&RE2InitShim))
|
|
312
|
+
.def("ok", &RE2::ok)
|
|
313
|
+
.def("error", &RE2ErrorShim)
|
|
314
|
+
.def("options", &RE2::options)
|
|
315
|
+
.def("NumberOfCapturingGroups", &RE2::NumberOfCapturingGroups)
|
|
316
|
+
.def("NamedCapturingGroups", &RE2NamedCapturingGroupsShim)
|
|
317
|
+
.def("ProgramSize", &RE2::ProgramSize)
|
|
318
|
+
.def("ReverseProgramSize", &RE2::ReverseProgramSize)
|
|
319
|
+
.def("ProgramFanout", &RE2ProgramFanoutShim)
|
|
320
|
+
.def("ReverseProgramFanout", &RE2ReverseProgramFanoutShim)
|
|
321
|
+
.def("PossibleMatchRange", &RE2PossibleMatchRangeShim)
|
|
322
|
+
.def("Match", &RE2MatchShim)
|
|
323
|
+
.def_static("QuoteMeta", &RE2QuoteMetaShim);
|
|
324
|
+
|
|
325
|
+
set.def(py::init<RE2::Anchor, const RE2::Options&>())
|
|
326
|
+
.def("Add", &Set::Add)
|
|
327
|
+
.def("Compile", &Set::Compile)
|
|
328
|
+
.def("Match", &Set::Match);
|
|
329
|
+
|
|
330
|
+
filter.def(py::init<>())
|
|
331
|
+
.def("Add", &Filter::Add)
|
|
332
|
+
.def("Compile", &Filter::Compile)
|
|
333
|
+
.def("Match", &Filter::Match)
|
|
334
|
+
.def("GetRE2", &Filter::GetRE2,
|
|
335
|
+
py::return_value_policy::reference_internal);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
} // namespace re2_python
|