re2 2.4.3-aarch64-linux → 2.5.0-aarch64-linux
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.
- checksums.yaml +4 -4
- data/README.md +236 -192
- data/ext/re2/extconf.rb +6 -70
- data/ext/re2/re2.cc +450 -263
- data/ext/re2/recipes.rb +8 -0
- data/lib/2.6/re2.so +0 -0
- data/lib/2.7/re2.so +0 -0
- data/lib/3.0/re2.so +0 -0
- data/lib/3.1/re2.so +0 -0
- data/lib/3.2/re2.so +0 -0
- data/lib/re2/regexp.rb +69 -0
- data/lib/re2/scanner.rb +8 -0
- data/lib/re2/string.rb +9 -59
- data/lib/re2/version.rb +9 -1
- data/lib/re2.rb +7 -3
- data/re2.gemspec +1 -0
- data/spec/kernel_spec.rb +2 -2
- data/spec/re2/match_data_spec.rb +64 -25
- data/spec/re2/regexp_spec.rb +492 -113
- data/spec/re2/scanner_spec.rb +3 -8
- data/spec/re2/set_spec.rb +18 -18
- data/spec/re2_spec.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63dead02fd50e66e67c4a3dcffaafae264842980bc13fe7ea26664de2c58cf5f
|
4
|
+
data.tar.gz: 4eb055c939db8088f671cdb87a7b1e43936f5985cfa98280a78f550efe80a8e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 825ad2cc8b322a046b263a5a491f2f2fc58a9b0a1f894f2ec95884e978a392d88afd467a093aff732d9f057c4d98c90eb4da98fdb9c639d28550d89add9f492a
|
7
|
+
data.tar.gz: f36a361482d3b9b4ebd6308a112ec9d9f1daede0599218551292b95f42bb58919afa3da180941d38738113ebfe86a0470d831f1ae89db6e1ca57440dd8b2542a
|
data/README.md
CHANGED
@@ -1,205 +1,232 @@
|
|
1
|
-
re2 [](https://github.com/mudge/re2/actions)
|
2
|
-
===
|
1
|
+
# re2 [](https://github.com/mudge/re2/actions)
|
3
2
|
|
4
3
|
Ruby bindings to [RE2][], a "fast, safe, thread-friendly alternative to
|
5
4
|
backtracking regular expression engines like those used in PCRE, Perl, and
|
6
5
|
Python".
|
7
6
|
|
8
|
-
**Current version:** 2.
|
9
|
-
**Supported Ruby versions:** 2.6, 2.7, 3.0, 3.1, 3.2
|
7
|
+
**Current version:** 2.5.0
|
10
8
|
**Bundled RE2 version:** libre2.11 (2023-11-01)
|
11
|
-
**Supported RE2 versions:** libre2.0 (< 2020-03-02), libre2.1 (2020-03-02), libre2.6 (2020-03-03), libre2.7 (2020-05-01), libre2.8 (2020-07-06), libre2.9 (2020-11-01), libre2.10 (2022-12-01), libre2.11 (2023-07-01)
|
12
9
|
|
13
|
-
|
14
|
-
|
10
|
+
```ruby
|
11
|
+
RE2('h.*o').full_match?("hello") #=> true
|
12
|
+
RE2('e').full_match?("hello") #=> false
|
13
|
+
RE2('h.*o').partial_match?("hello") #=> true
|
14
|
+
RE2('e').partial_match?("hello") #=> true
|
15
|
+
RE2('(\w+):(\d+)').full_match("ruby:1234")
|
16
|
+
#=> #<RE2::MatchData "ruby:1234" 1:"ruby" 2:"1234">
|
17
|
+
```
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
## Table of Contents
|
20
|
+
|
21
|
+
* [Why RE2?](#why-re2)
|
22
|
+
* [Usage](#usage)
|
23
|
+
* [Compiling regular expressions](#compiling-regular-expressions)
|
24
|
+
* [Matching interface](#matching-interface)
|
25
|
+
* [Submatch extraction](#submatch-extraction)
|
26
|
+
* [Scanning text incrementally](#scanning-text-incrementally)
|
27
|
+
* [Searching simultaneously](#searching-simultaneously)
|
28
|
+
* [Encoding](#encoding)
|
29
|
+
* [Requirements](#requirements)
|
30
|
+
* [Native gems](#native-gems)
|
31
|
+
* [Installing the `ruby` platform gem](#installing-the-ruby-platform-gem)
|
32
|
+
* [Using system libraries](#using-system-libraries)
|
33
|
+
* [Thanks](#thanks)
|
34
|
+
* [Contact](#contact)
|
35
|
+
* [License](#license)
|
36
|
+
* [Dependencies](#dependencies)
|
37
|
+
|
38
|
+
## Why RE2?
|
39
|
+
|
40
|
+
> RE2 was designed and implemented with an explicit goal of being able to
|
41
|
+
> handle regular expressions from untrusted users without risk. One of its
|
42
|
+
> primary guarantees is that the match time is linear in the length of the
|
43
|
+
> input string. It was also written with production concerns in mind: the
|
44
|
+
> parser, the compiler and the execution engines limit their memory usage by
|
45
|
+
> working within a configurable budget – failing gracefully when exhausted –
|
46
|
+
> and they avoid stack overflow by eschewing recursion.
|
47
|
+
|
48
|
+
— [Why RE2?](https://github.com/google/re2/wiki/WhyRE2)
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
Install re2 as a dependency:
|
19
53
|
|
20
|
-
|
21
|
-
|
54
|
+
```ruby
|
55
|
+
# In your Gemfile
|
56
|
+
gem "re2"
|
22
57
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- `x64-mingw32` / `x64-mingw-ucrt`
|
27
|
-
- `x86-linux` (requires: glibc >= 2.17)
|
28
|
-
- `x86_64-darwin`
|
29
|
-
- `x86_64-linux` (requires: glibc >= 2.17)
|
58
|
+
# Or without Bundler
|
59
|
+
gem install re2
|
60
|
+
```
|
30
61
|
|
31
|
-
|
32
|
-
installed as well as a C++ compiler such as [gcc][] (on Debian and Ubuntu, this
|
33
|
-
is provided by the [build-essential][] package). If you are using macOS, I
|
34
|
-
recommend installing RE2 with [Homebrew][] by running the following:
|
62
|
+
Include in your code:
|
35
63
|
|
36
|
-
|
64
|
+
```ruby
|
65
|
+
require "re2"
|
66
|
+
```
|
37
67
|
|
38
|
-
|
68
|
+
Full API documentation automatically generated from the latest version is
|
69
|
+
available at https://mudge.name/re2/.
|
39
70
|
|
40
|
-
|
71
|
+
While re2 uses the same naming scheme as Ruby's built-in regular expression
|
72
|
+
library (with [`Regexp`](https://mudge.name/re2/RE2/Regexp.html) and
|
73
|
+
[`MatchData`](https://mudge.name/re2/RE2/MatchData.html)), its API is slightly
|
74
|
+
different:
|
41
75
|
|
42
|
-
|
43
|
-
C++14 support such as [clang](http://clang.llvm.org/) 3.4 or
|
44
|
-
[gcc](https://gcc.gnu.org/) 5.
|
76
|
+
### Compiling regular expressions
|
45
77
|
|
46
|
-
|
47
|
-
|
48
|
-
|
78
|
+
> [!WARNING]
|
79
|
+
> RE2's regular expression syntax differs from PCRE and Ruby's built-in
|
80
|
+
> [`Regexp`](https://docs.ruby-lang.org/en/3.2/Regexp.html) library, see the
|
81
|
+
> [official syntax page](https://github.com/google/re2/wiki/Syntax) for more
|
82
|
+
> details.
|
49
83
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
84
|
+
The core class is [`RE2::Regexp`](https://mudge.name/re2/RE2/Regexp.html) which
|
85
|
+
takes a regular expression as a string and compiles it internally into an `RE2`
|
86
|
+
object. A global function `RE2` is available to concisely compile a new
|
87
|
+
`RE2::Regexp`:
|
54
88
|
|
55
|
-
|
56
|
-
|
57
|
-
|
89
|
+
```ruby
|
90
|
+
re = RE2('(\w+):(\d+)')
|
91
|
+
#=> #<RE2::Regexp /(\w+):(\d+)/>
|
92
|
+
re.ok? #=> true
|
58
93
|
|
59
|
-
|
94
|
+
re = RE2('abc)def')
|
95
|
+
re.ok? #=> false
|
96
|
+
re.error #=> "missing ): abc(def"
|
97
|
+
```
|
60
98
|
|
61
|
-
|
62
|
-
|
63
|
-
|
99
|
+
> [!TIP]
|
100
|
+
> Note the use of *single quotes* when passing the regular expression as
|
101
|
+
> a string to `RE2` so that the backslashes aren't interpreted as escapes.
|
64
102
|
|
65
|
-
|
66
|
-
-------------
|
103
|
+
When compiling a regular expression, an optional second argument can be used to change RE2's default options, e.g. stop logging syntax and execution errors to stderr with `log_errors`:
|
67
104
|
|
68
|
-
|
69
|
-
|
105
|
+
```ruby
|
106
|
+
RE2('abc)def', log_errors: false)
|
107
|
+
```
|
70
108
|
|
71
|
-
|
72
|
-
built-in [`Regexp`][Regexp] library, see the [official syntax page][] for more
|
73
|
-
details.
|
109
|
+
See the API documentation for [`RE2::Regexp#initialize`](https://mudge.name/re2/RE2/Regexp.html#initialize-instance_method) for all the available options.
|
74
110
|
|
75
|
-
|
76
|
-
-----
|
111
|
+
### Matching interface
|
77
112
|
|
78
|
-
|
79
|
-
library (with [`Regexp`](http://mudge.name/re2/RE2/Regexp.html) and
|
80
|
-
[`MatchData`](http://mudge.name/re2/RE2/MatchData.html)), its API is slightly
|
81
|
-
different:
|
113
|
+
There are two main methods for matching: [`RE2::Regexp#full_match?`](https://mudge.name/re2/RE2/Regexp.html#full_match%3F-instance_method) requires the regular expression to match the entire input text, and [`RE2::Regexp#partial_match?`](https://mudge.name/re2/RE2/Regexp.html#match%3F-instance_method) looks for a match for a substring of the input text, returning a boolean to indicate whether a match was successful or not.
|
82
114
|
|
83
|
-
```
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
=> #<RE2::MatchData "w1234" 1:"1" 2:"234">
|
90
|
-
> m[1]
|
91
|
-
=> "1"
|
92
|
-
> m.string
|
93
|
-
=> "w1234"
|
94
|
-
> m.begin(1)
|
95
|
-
=> 1
|
96
|
-
> m.end(1)
|
97
|
-
=> 2
|
98
|
-
> r =~ "w1234"
|
99
|
-
=> true
|
100
|
-
> r !~ "bob"
|
101
|
-
=> true
|
102
|
-
> r.match("bob")
|
103
|
-
=> nil
|
115
|
+
```ruby
|
116
|
+
RE2('h.*o').full_match?("hello") #=> true
|
117
|
+
RE2('e').full_match?("hello") #=> false
|
118
|
+
|
119
|
+
RE2('h.*o').partial_match?("hello") #=> true
|
120
|
+
RE2('e').partial_match?("hello") #=> true
|
104
121
|
```
|
105
122
|
|
106
|
-
|
107
|
-
[`RE2::Regexp.new`](http://mudge.name/re2/RE2/Regexp.html#initialize-instance_method)
|
108
|
-
(or `RE2::Regexp.compile`) can be quite verbose, a helper method has been
|
109
|
-
defined against `Kernel` so you can use a shorter version to create regular
|
110
|
-
expressions:
|
123
|
+
### Submatch extraction
|
111
124
|
|
112
|
-
|
113
|
-
>
|
114
|
-
|
115
|
-
|
125
|
+
> [!TIP]
|
126
|
+
> Only extract the number of submatches you need as performance is improved
|
127
|
+
> with fewer submatches (with the best performance when avoiding submatch
|
128
|
+
> extraction altogether).
|
116
129
|
|
117
|
-
|
118
|
-
in the following example:
|
130
|
+
Both matching methods have a second form that can extract submatches as [`RE2::MatchData`](https://mudge.name/re2/RE2/MatchData.html) objects: [`RE2::Regexp#full_match`](https://mudge.name/re2/RE2/Regexp.html#full_match-instance_method) and [`RE2::Regexp#partial_match`](https://mudge.name/re2/RE2/Regexp.html#partial_match-instance_method).
|
119
131
|
|
120
|
-
```
|
121
|
-
|
122
|
-
|
132
|
+
```ruby
|
133
|
+
m = RE2('(\w+):(\d+)').full_match("ruby:1234")
|
134
|
+
#=> #<RE2::MatchData "ruby:1234" 1:"ruby" 2:"1234">
|
135
|
+
|
136
|
+
m[0] #=> "ruby:1234"
|
137
|
+
m[1] #=> "ruby"
|
138
|
+
m[2] #=> "1234"
|
139
|
+
|
140
|
+
m = RE2('(\w+):(\d+)').full_match("r")
|
141
|
+
#=> nil
|
123
142
|
```
|
124
143
|
|
125
|
-
|
126
|
-
|
127
|
-
```
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
=> "Bob"
|
134
|
-
> m["age"]
|
135
|
-
=> "40"
|
144
|
+
`RE2::MatchData` supports retrieving submatches by numeric index or by name if present in the regular expression:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
m = RE2('(?P<word>\w+):(?P<number>\d+)').full_match("ruby:1234")
|
148
|
+
#=> #<RE2::MatchData "ruby:1234" 1:"ruby" 2:"1234">
|
149
|
+
|
150
|
+
m["word"] #=> "ruby"
|
151
|
+
m["number"] #=> "1234"
|
136
152
|
```
|
137
153
|
|
138
|
-
|
139
|
-
matches (similar in purpose to Ruby's
|
140
|
-
[`String#scan`](http://ruby-doc.org/core-2.0.0/String.html#method-i-scan)).
|
141
|
-
Calling `scan` will return an `RE2::Scanner` which is
|
142
|
-
[enumerable](http://ruby-doc.org/core-2.0.0/Enumerable.html) meaning you can
|
143
|
-
use `each` to iterate through the matches (and even use
|
144
|
-
[`Enumerator::Lazy`](http://ruby-doc.org/core-2.0/Enumerator/Lazy.html)):
|
154
|
+
They can also be used with Ruby's [pattern matching](https://docs.ruby-lang.org/en/3.2/syntax/pattern_matching_rdoc.html):
|
145
155
|
|
146
156
|
```ruby
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
157
|
+
case RE2('(\w+):(\d+)').full_match("ruby:1234")
|
158
|
+
in [word, number]
|
159
|
+
puts "Word: #{word}, Number: #{number}"
|
160
|
+
else
|
161
|
+
puts "No match"
|
151
162
|
end
|
163
|
+
# Word: ruby, Number: 1234
|
152
164
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
165
|
+
case RE2('(?P<word>\w+):(?P<number>\d+)').full_match("ruby:1234")
|
166
|
+
in word:, number:
|
167
|
+
puts "Word: #{word}, Number: #{number}"
|
168
|
+
else
|
169
|
+
puts "No match"
|
170
|
+
end
|
171
|
+
# Word: ruby, Number: 1234
|
158
172
|
```
|
159
173
|
|
160
|
-
|
161
|
-
string. Calling `RE2::Set#add` with a pattern will return an integer index of
|
162
|
-
the pattern. After all patterns have been added, the set can be compiled using
|
163
|
-
`RE2::Set#compile`, and then `RE2::Set#match` will return an `Array<Integer>`
|
164
|
-
containing the indices of all the patterns that matched.
|
174
|
+
By default, both `full_match` and `partial_match` will extract all submatches into the `RE2::MatchData` based on the number of capturing groups in the regular expression. This can be changed by passing an optional second argument when matching:
|
165
175
|
|
166
176
|
```ruby
|
167
|
-
|
168
|
-
|
169
|
-
set.add("def") #=> 1
|
170
|
-
set.add("ghi") #=> 2
|
171
|
-
set.compile #=> true
|
172
|
-
set.match("abcdefghi") #=> [0, 1, 2]
|
173
|
-
set.match("ghidefabc") #=> [2, 1, 0]
|
177
|
+
m = RE2('(\w+):(\d+)').full_match("ruby:1234", submatches: 1)
|
178
|
+
=> #<RE2::MatchData "ruby:1234" 1:"ruby">
|
174
179
|
```
|
175
180
|
|
176
|
-
|
181
|
+
> [!WARNING]
|
182
|
+
> If the regular expression has no capturing groups or you pass `submatches:
|
183
|
+
> 0`, the matching method will behave like its `full_match?` or
|
184
|
+
> `partial_match?` form and only return `true` or `false` rather than
|
185
|
+
> `RE2::MatchData`.
|
186
|
+
|
187
|
+
### Scanning text incrementally
|
188
|
+
|
189
|
+
If you want to repeatedly match regular expressions from the start of some input text, you can use [`RE2::Regexp#scan`](https://mudge.name/re2/RE2/Regexp.html#scan-instance_method) to return an `Enumerable` [`RE2::Scanner`](https://mudge.name/re2/RE2/Scanner.html) object which will lazily consume matches as you iterate over it:
|
177
190
|
|
178
191
|
```ruby
|
179
|
-
|
180
|
-
|
181
|
-
puts
|
182
|
-
else
|
183
|
-
puts "No match!"
|
192
|
+
scanner = RE2('(\w+)').scan(" one two three 4")
|
193
|
+
scanner.each do |match|
|
194
|
+
puts match.inspect
|
184
195
|
end
|
185
|
-
#
|
196
|
+
# ["one"]
|
197
|
+
# ["two"]
|
198
|
+
# ["three"]
|
199
|
+
# ["4"]
|
200
|
+
```
|
186
201
|
|
202
|
+
### Searching simultaneously
|
187
203
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
204
|
+
[`RE2::Set`](https://mudge.name/re2/RE2/Set.html) represents a collection of
|
205
|
+
regular expressions that can be searched for simultaneously. Calling
|
206
|
+
[`RE2::Set#add`](https://mudge.name/re2/RE2/Set.html#add-instance_method) with
|
207
|
+
a regular expression will return the integer index at which it is stored within
|
208
|
+
the set. After all patterns have been added, the set can be compiled using
|
209
|
+
[`RE2::Set#compile`](https://mudge.name/re2/RE2/Set.html#compile-instance_method),
|
210
|
+
and then
|
211
|
+
[`RE2::Set#match`](https://mudge.name/re2/RE2/Set.html#match-instance_method)
|
212
|
+
will return an array containing the indices of all the patterns that matched.
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
set = RE2::Set.new
|
216
|
+
set.add("abc") #=> 0
|
217
|
+
set.add("def") #=> 1
|
218
|
+
set.add("ghi") #=> 2
|
219
|
+
set.compile #=> true
|
220
|
+
set.match("abcdefghi") #=> [0, 1, 2]
|
221
|
+
set.match("ghidefabc") #=> [2, 1, 0]
|
195
222
|
```
|
196
223
|
|
197
|
-
Encoding
|
198
|
-
--------
|
224
|
+
### Encoding
|
199
225
|
|
200
|
-
|
201
|
-
|
202
|
-
|
226
|
+
> [!WARNING]
|
227
|
+
> Note RE2 only supports UTF-8 and ISO-8859-1 encoding so strings will be
|
228
|
+
> returned in UTF-8 by default or ISO-8859-1 if the `:utf8` option for the
|
229
|
+
> `RE2::Regexp` is set to `false` (any other encoding's behaviour is undefined).
|
203
230
|
|
204
231
|
For backward compatibility: re2 won't automatically convert string inputs to
|
205
232
|
the right encoding so this is the responsibility of the caller, e.g.
|
@@ -209,51 +236,77 @@ the right encoding so this is the responsibility of the caller, e.g.
|
|
209
236
|
RE2(non_utf8_pattern.encode("UTF-8")).match(non_utf8_text.encode("UTF-8"))
|
210
237
|
|
211
238
|
# If the :utf8 option is false, RE2 will process patterns and text as ISO-8859-1
|
212
|
-
RE2(non_latin1_pattern.encode("ISO-8859-1"), :
|
239
|
+
RE2(non_latin1_pattern.encode("ISO-8859-1"), utf8: false).match(non_latin1_text.encode("ISO-8859-1"))
|
213
240
|
```
|
214
241
|
|
215
|
-
|
216
|
-
--------
|
242
|
+
## Requirements
|
217
243
|
|
218
|
-
|
219
|
-
[`RE2::Regexp.new(re)`](https://github.com/google/re2/blob/2016-02-01/re2/re2.h#L100),
|
220
|
-
`RE2::Regexp.compile(re)` or `RE2(re)` (including specifying options, e.g.
|
221
|
-
`RE2::Regexp.new("pattern", :case_sensitive => false)`
|
244
|
+
This gem requires the following to run:
|
222
245
|
|
223
|
-
*
|
224
|
-
with `re2.match(text, number_of_matches)` such as `re2.match("123-234", 2)`)
|
246
|
+
* [Ruby](https://www.ruby-lang.org/en/) 2.6 to 3.3
|
225
247
|
|
226
|
-
|
248
|
+
It supports the following RE2 ABI versions:
|
227
249
|
|
228
|
-
*
|
229
|
-
statements) and `re2 !~ text`
|
250
|
+
* libre2.0 (prior to release 2020-03-02) to libre2.11 (2023-07-01 to 2023-11-01)
|
230
251
|
|
231
|
-
|
252
|
+
### Native gems
|
232
253
|
|
233
|
-
|
254
|
+
Where possible, a pre-compiled native gem will be provided for the following platforms:
|
234
255
|
|
235
|
-
*
|
236
|
-
|
256
|
+
* Linux `aarch64-linux` and `arm-linux` (requires [glibc](https://www.gnu.org/software/libc/) 2.29+)
|
257
|
+
* Linux `x86-linux` and `x86_64-linux` (requires [glibc](https://www.gnu.org/software/libc/) 2.17+) including [musl](https://musl.libc.org/)-based systems such as [Alpine](https://alpinelinux.org)
|
258
|
+
* macOS `x86_64-darwin` and `arm64-darwin`
|
259
|
+
* Windows `x64-mingw32` and `x64-mingw-ucrt`
|
237
260
|
|
238
|
-
|
261
|
+
### Installing the `ruby` platform gem
|
239
262
|
|
240
|
-
|
241
|
-
|
263
|
+
> [!WARNING]
|
264
|
+
> We strongly recommend using the native gems where possible to avoid the need
|
265
|
+
> for compiling the C++ extension and its dependencies which will take longer
|
266
|
+
> and be less reliable.
|
242
267
|
|
243
|
-
|
244
|
-
original)`
|
268
|
+
If you wish to compile the gem, you will need to explicitly install the `ruby` platform gem:
|
245
269
|
|
246
|
-
|
247
|
-
|
270
|
+
```ruby
|
271
|
+
# In your Gemfile with Bundler 2.3.18+
|
272
|
+
gem "re2", force_ruby_platform: true
|
273
|
+
|
274
|
+
# With Bundler 2.1+
|
275
|
+
bundle config set force_ruby_platform true
|
276
|
+
|
277
|
+
# With older versions of Bundler
|
278
|
+
bundle config force_ruby_platform true
|
279
|
+
|
280
|
+
# Without Bundler
|
281
|
+
gem install re2 --platform=ruby
|
282
|
+
```
|
283
|
+
|
284
|
+
You will need a full compiler toolchain for compiling Ruby C extensions (see
|
285
|
+
[Nokogiri's "The Compiler
|
286
|
+
Toolchain"](https://nokogiri.org/tutorials/installing_nokogiri.html#appendix-a-the-compiler-toolchain))
|
287
|
+
plus the toolchain required for compiling the vendored version of RE2 and its
|
288
|
+
dependency [Abseil][] which includes
|
289
|
+
[CMake](https://cmake.org) and a compiler with C++14 support such as
|
290
|
+
[clang](http://clang.llvm.org/) 3.4 or [gcc](https://gcc.gnu.org/) 5. On
|
291
|
+
Windows, you'll also need pkgconf 2.1.0+ to avoid [`undefined reference`
|
292
|
+
errors](https://github.com/pkgconf/pkgconf/issues/322) when attempting to
|
293
|
+
compile Abseil.
|
294
|
+
|
295
|
+
### Using system libraries
|
248
296
|
|
249
|
-
|
250
|
-
[`RE2.escape(unquoted)`](https://github.com/google/re2/blob/2016-02-01/re2/re2.h#L418) and
|
251
|
-
`RE2.quote(unquoted)`
|
297
|
+
If you already have RE2 installed, you can instruct the gem not to use its own vendored version:
|
252
298
|
|
253
|
-
|
299
|
+
```ruby
|
300
|
+
gem install re2 --platform=ruby -- --enable-system-libraries
|
301
|
+
|
302
|
+
# If RE2 is not installed in /usr/local, /usr, or /opt/homebrew:
|
303
|
+
gem install re2 --platform=ruby -- --enable-system-libraries --with-re2-dir=/path/to/re2/prefix
|
304
|
+
```
|
254
305
|
|
255
|
-
|
256
|
-
|
306
|
+
Alternatively, you can set the `RE2_USE_SYSTEM_LIBRARIES` environment variable instead of passing `--enable-system-libraries` to the `gem` command.
|
307
|
+
|
308
|
+
|
309
|
+
## Thanks
|
257
310
|
|
258
311
|
* Thanks to [Jason Woods](https://github.com/driskell) who contributed the
|
259
312
|
original implementations of `RE2::MatchData#begin` and `RE2::MatchData#end`.
|
@@ -278,30 +331,21 @@ Contributions
|
|
278
331
|
switch to Ruby's `TypedData` API and the resulting garbage collection
|
279
332
|
improvements in 2.4.0.
|
280
333
|
|
281
|
-
Contact
|
282
|
-
-------
|
334
|
+
## Contact
|
283
335
|
|
284
336
|
All issues and suggestions should go to [GitHub Issues](https://github.com/mudge/re2/issues).
|
285
337
|
|
286
|
-
License
|
287
|
-
-------
|
338
|
+
## License
|
288
339
|
|
289
340
|
This library is licensed under the BSD 3-Clause License, see `LICENSE.txt`.
|
290
341
|
|
291
|
-
|
292
|
-
|
342
|
+
Copyright © 2010, Paul Mucur.
|
343
|
+
|
344
|
+
### Dependencies
|
293
345
|
|
294
346
|
The source code of [RE2][] is distributed in the `ruby` platform gem. This code is licensed under the BSD 3-Clause License, see `LICENSE-DEPENDENCIES.txt`.
|
295
347
|
|
296
348
|
The source code of [Abseil][] is distributed in the `ruby` platform gem. This code is licensed under the Apache License 2.0, see `LICENSE-DEPENDENCIES.txt`.
|
297
349
|
|
298
350
|
[RE2]: https://github.com/google/re2
|
299
|
-
[gcc]: http://gcc.gnu.org/
|
300
|
-
[ruby-dev]: http://packages.debian.org/ruby-dev
|
301
|
-
[build-essential]: http://packages.debian.org/build-essential
|
302
|
-
[Regexp]: http://ruby-doc.org/core/classes/Regexp.html
|
303
|
-
[MatchData]: http://ruby-doc.org/core/classes/MatchData.html
|
304
|
-
[Homebrew]: http://mxcl.github.com/homebrew
|
305
|
-
[libre2-dev]: http://packages.debian.org/search?keywords=libre2-dev
|
306
|
-
[official syntax page]: https://github.com/google/re2/wiki/Syntax
|
307
351
|
[Abseil]: https://abseil.io
|
data/ext/re2/extconf.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# re2 (
|
2
|
-
# Ruby bindings to
|
1
|
+
# re2 (https://github.com/mudge/re2)
|
2
|
+
# Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to
|
3
|
+
# backtracking regular expression engines like those used in PCRE, Perl, and
|
4
|
+
# Python".
|
3
5
|
#
|
4
|
-
# Copyright (c) 2010
|
6
|
+
# Copyright (c) 2010, Paul Mucur (https://mudge.name)
|
5
7
|
# Released under the BSD Licence, please see LICENSE.txt
|
6
8
|
|
7
9
|
require 'mkmf'
|
@@ -271,65 +273,6 @@ def build_with_system_libraries
|
|
271
273
|
build_extension
|
272
274
|
end
|
273
275
|
|
274
|
-
# pkgconf v1.9.3 on Windows incorrectly sorts the output of `pkg-config
|
275
|
-
# --libs --static`, resulting in build failures: https://github.com/pkgconf/pkgconf/issues/268.
|
276
|
-
# To work around the issue, store the correct order of abseil flags here and add them manually
|
277
|
-
# for Windows.
|
278
|
-
#
|
279
|
-
# Note that `-ldbghelp` is incorrectly added before `-labsl_symbolize` in abseil:
|
280
|
-
# https://github.com/abseil/abseil-cpp/issues/1497
|
281
|
-
ABSL_LDFLAGS = %w[
|
282
|
-
-labsl_flags
|
283
|
-
-labsl_flags_internal
|
284
|
-
-labsl_flags_marshalling
|
285
|
-
-labsl_flags_reflection
|
286
|
-
-labsl_flags_private_handle_accessor
|
287
|
-
-labsl_flags_commandlineflag
|
288
|
-
-labsl_flags_commandlineflag_internal
|
289
|
-
-labsl_flags_config
|
290
|
-
-labsl_flags_program_name
|
291
|
-
-labsl_cord
|
292
|
-
-labsl_cordz_info
|
293
|
-
-labsl_cord_internal
|
294
|
-
-labsl_cordz_functions
|
295
|
-
-labsl_cordz_handle
|
296
|
-
-labsl_crc_cord_state
|
297
|
-
-labsl_crc32c
|
298
|
-
-labsl_crc_internal
|
299
|
-
-labsl_crc_cpu_detect
|
300
|
-
-labsl_raw_hash_set
|
301
|
-
-labsl_hash
|
302
|
-
-labsl_city
|
303
|
-
-labsl_bad_variant_access
|
304
|
-
-labsl_low_level_hash
|
305
|
-
-labsl_hashtablez_sampler
|
306
|
-
-labsl_exponential_biased
|
307
|
-
-labsl_bad_optional_access
|
308
|
-
-labsl_str_format_internal
|
309
|
-
-labsl_synchronization
|
310
|
-
-labsl_graphcycles_internal
|
311
|
-
-labsl_kernel_timeout_internal
|
312
|
-
-labsl_stacktrace
|
313
|
-
-labsl_symbolize
|
314
|
-
-ldbghelp
|
315
|
-
-labsl_debugging_internal
|
316
|
-
-labsl_demangle_internal
|
317
|
-
-labsl_malloc_internal
|
318
|
-
-labsl_time
|
319
|
-
-labsl_civil_time
|
320
|
-
-labsl_strings
|
321
|
-
-labsl_string_view
|
322
|
-
-labsl_strings_internal
|
323
|
-
-labsl_base
|
324
|
-
-ladvapi32
|
325
|
-
-labsl_spinlock_wait
|
326
|
-
-labsl_int128
|
327
|
-
-labsl_throw_delegate
|
328
|
-
-labsl_raw_logging_internal
|
329
|
-
-labsl_log_severity
|
330
|
-
-labsl_time_zone
|
331
|
-
].freeze
|
332
|
-
|
333
276
|
def libflag_to_filename(ldflag)
|
334
277
|
case ldflag
|
335
278
|
when /\A-l(.+)/
|
@@ -382,14 +325,7 @@ def add_flag(arg, lib_paths)
|
|
382
325
|
end
|
383
326
|
|
384
327
|
def add_static_ldflags(flags, lib_paths)
|
385
|
-
|
386
|
-
|
387
|
-
if MiniPortile.windows?
|
388
|
-
static_flags.each { |flag| add_flag(flag, lib_paths) unless ABSL_LDFLAGS.include?(flag) }
|
389
|
-
ABSL_LDFLAGS.each { |flag| add_flag(flag, lib_paths) }
|
390
|
-
else
|
391
|
-
static_flags.each { |flag| add_flag(flag, lib_paths) }
|
392
|
-
end
|
328
|
+
flags.strip.shellsplit.each { |flag| add_flag(flag, lib_paths) }
|
393
329
|
end
|
394
330
|
|
395
331
|
def build_with_vendored_libraries
|