re2 2.4.2-x64-mingw-ucrt → 2.5.0-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0f0ea10edaa6865dc09105438dba89970dcb401bf49d561d8e8ebfe7b194bd6
4
- data.tar.gz: 93519d374b2f07d6ee4ba80c62e76ba8155275801965e67c7e96001ea421ddbf
3
+ metadata.gz: 3331cdfde92f9ff0c57e9890998ecfaa1fa2586e0b289f7250a6bcd7c4a66657
4
+ data.tar.gz: d67f193d2cd4429b943d1f4e56c0595d9bd1c6c545963cbe5c9c4ae9e18ab5fe
5
5
  SHA512:
6
- metadata.gz: 4538c379a616eea0db1cd0bd91d6e6688e1f6752c9c551045fabd4e84c89857062002f2004dec3c229a6ab5a63d00481f7025562c78d2ac242ecb7264f48e155
7
- data.tar.gz: d82ea9f337365512b248947637c1b1a37d6ea260ba76011ce6a3c52b6606e1240ac8a0addfc31a632a24039990584830581ed618b4aeb0999cd1b914ebd44b38
6
+ metadata.gz: 3c06ce89df1183059dab4bc1f883ef0e16df60811da56a036008ae55817e9c0abe2083b2bdd30f7c0ef78ad8fc33580a6df2a39c7557526f46bb8f3a720b2cff
7
+ data.tar.gz: 8ad005bc24204b1e9b6cdc6579349275abd2deec594ef8b3977c61c2bcfc3623abd321d8f690a294d1c3b8cabf4803a5ad825ddff9b63ad9306180d550478f72
data/README.md CHANGED
@@ -1,205 +1,232 @@
1
- re2 [![Build Status](https://github.com/mudge/re2/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mudge/re2/actions)
2
- ===
1
+ # re2 [![Build Status](https://github.com/mudge/re2/actions/workflows/tests.yml/badge.svg?branch=main)](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.4.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
- Installation
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
- The gem comes bundled with a version of [RE2][] and will compile itself (and
17
- any dependencies) on install. As compilation can take a while, precompiled
18
- native gems are available for Linux, Windows and macOS.
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
- In v2.0 and later, precompiled native gems are available for Ruby 2.6 to 3.2
21
- on these platforms:
54
+ ```ruby
55
+ # In your Gemfile
56
+ gem "re2"
22
57
 
23
- - `aarch64-linux` (requires: glibc >= 2.29)
24
- - `arm-linux` (requires: glibc >= 2.29)
25
- - `arm64-darwin`
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
- If you wish to opt out of using the bundled libraries, you will need RE2
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
- $ brew install re2
64
+ ```ruby
65
+ require "re2"
66
+ ```
37
67
 
38
- If you are using Debian, you can install the [libre2-dev][] package like so:
68
+ Full API documentation automatically generated from the latest version is
69
+ available at https://mudge.name/re2/.
39
70
 
40
- $ sudo apt-get install libre2-dev
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
- Recent versions of RE2 require [CMake](https://cmake.org) and a compiler with
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
- If you are using a packaged Ruby distribution, make sure you also have the
47
- Ruby header files installed such as those provided by the [ruby-dev][] package
48
- on Debian and Ubuntu.
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
- You can then install the library via RubyGems with `gem install re2 --platform=ruby --
51
- --enable-system-libraries` or `gem install re2 --platform=ruby -- --enable-system-libraries
52
- --with-re2-dir=/path/to/re2/prefix` if RE2 is not installed in any of the
53
- following default locations:
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
- * `/usr/local`
56
- * `/opt/homebrew`
57
- * `/usr`
89
+ ```ruby
90
+ re = RE2('(\w+):(\d+)')
91
+ #=> #<RE2::Regexp /(\w+):(\d+)/>
92
+ re.ok? #=> true
58
93
 
59
- Alternatively, you can set the `RE2_USE_SYSTEM_LIBRARIES` environment variable instead of passing `--enable-system-libraries` to the `gem` command.
94
+ re = RE2('abc)def')
95
+ re.ok? #=> false
96
+ re.error #=> "missing ): abc(def"
97
+ ```
60
98
 
61
- If you're using Bundler, you can use the
62
- [`force_ruby_platform`](https://bundler.io/v2.3/man/gemfile.5.html#FORCE_RUBY_PLATFORM)
63
- option in your Gemfile.
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
- Documentation
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
- Full documentation automatically generated from the latest version is
69
- available at <http://mudge.name/re2/>.
105
+ ```ruby
106
+ RE2('abc)def', log_errors: false)
107
+ ```
70
108
 
71
- Note that RE2's regular expression syntax differs from PCRE and Ruby's
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
- Usage
76
- -----
111
+ ### Matching interface
77
112
 
78
- While re2 uses the same naming scheme as Ruby's built-in regular expression
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
- ```console
84
- $ irb -rubygems
85
- > require 're2'
86
- > r = RE2::Regexp.new('w(\d)(\d+)')
87
- => #<RE2::Regexp /w(\d)(\d+)/>
88
- > m = r.match("w1234")
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
- As
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
- ```console
113
- > RE2('(\d+)')
114
- => #<RE2::Regexp /(\d+)/>
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
- Note the use of *single quotes* as double quotes will interpret `\d` as `d` as
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
- ```console
121
- > RE2("(\d+)")
122
- => #<RE2::Regexp /(d+)/>
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
- As of 0.3.0, you can use named groups:
126
-
127
- ```console
128
- > r = RE2::Regexp.new('(?P<name>\w+) (?P<age>\d+)')
129
- => #<RE2::Regexp /(?P<name>\w+) (?P<age>\d+)/>
130
- > m = r.match("Bob 40")
131
- => #<RE2::MatchData "Bob 40" 1:"Bob" 2:"40">
132
- > m[:name]
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
- As of 0.6.0, you can use `RE2::Regexp#scan` to incrementally scan text for
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
- re = RE2('(\w+)')
148
- scanner = re.scan("It is a truth universally acknowledged")
149
- scanner.each do |match|
150
- puts match
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
- scanner.rewind
154
-
155
- enum = scanner.to_enum
156
- enum.next #=> ["It"]
157
- enum.next #=> ["is"]
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
- As of 1.5.0, you can use `RE2::Set` to match multiple patterns against a
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
- set = RE2::Set.new
168
- set.add("abc") #=> 0
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
- As of 1.6.0, you can use [Ruby's pattern matching](https://docs.ruby-lang.org/en/3.0/syntax/pattern_matching_rdoc.html) against `RE2::MatchData` with both array patterns and hash patterns:
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
- case RE2('(\w+) (\d+)').match("Alice 42")
180
- in [name, age]
181
- puts "My name is #{name} and I am #{age} years old"
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
- # My name is Alice and I am 42 years old
196
+ # ["one"]
197
+ # ["two"]
198
+ # ["three"]
199
+ # ["4"]
200
+ ```
186
201
 
202
+ ### Searching simultaneously
187
203
 
188
- case RE2('(?P<name>\w+) (?P<age>\d+)').match("Alice 42")
189
- in {name:, age:}
190
- puts "My name is #{name} and I am #{age} years old"
191
- else
192
- puts "No match!"
193
- end
194
- # My name is Alice and I am 42 years old
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
- Note RE2 only supports UTF-8 and ISO-8859-1 encoding so strings will be
201
- returned in UTF-8 by default or ISO-8859-1 if the `:utf8` option for the
202
- `RE2::Regexp` is set to false (any other encoding's behaviour is undefined).
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"), :utf8 => false).match(non_latin1_text.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
- Features
216
- --------
242
+ ## Requirements
217
243
 
218
- * Pre-compiling regular expressions with
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
- * Extracting matches with `re2.match(text)` (and an exact number of matches
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
- * Extracting matches by name (both with strings and symbols)
248
+ It supports the following RE2 ABI versions:
227
249
 
228
- * Checking for matches with `re2 =~ text`, `re2 === text` (for use in `case`
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
- * Incrementally scanning text with `re2.scan(text)`
252
+ ### Native gems
232
253
 
233
- * Search a collection of patterns simultaneously with `RE2::Set`
254
+ Where possible, a pre-compiled native gem will be provided for the following platforms:
234
255
 
235
- * Checking regular expression compilation with `re2.ok?`, `re2.error` and
236
- `re2.error_arg`
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
- * Checking regular expression "cost" with `re2.program_size`
261
+ ### Installing the `ruby` platform gem
239
262
 
240
- * Checking the options for an expression with `re2.options` or individually
241
- with `re2.case_sensitive?`
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
- * Performing a single string replacement with `pattern.replace(replacement,
244
- original)`
268
+ If you wish to compile the gem, you will need to explicitly install the `ruby` platform gem:
245
269
 
246
- * Performing a global string replacement with
247
- `pattern.replace_all(replacement, original)`
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
- * Escaping regular expressions with
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
- * Pattern matching with `RE2::MatchData`
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
- Contributions
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
- Dependencies
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 (http://github.com/mudge/re2)
2
- # Ruby bindings to re2, an "efficient, principled regular expression library"
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-2012, Paul Mucur (http://mudge.name)
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
- static_flags = flags.strip.shellsplit
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