re2 2.4.3 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/README.md +281 -192
- data/Rakefile +1 -1
- data/dependencies.yml +4 -4
- data/ext/re2/extconf.rb +250 -358
- data/ext/re2/re2.cc +505 -284
- data/ext/re2/recipes.rb +31 -20
- data/lib/re2/regexp.rb +72 -0
- data/lib/re2/scanner.rb +11 -0
- data/lib/re2/string.rb +12 -59
- data/lib/re2/version.rb +10 -1
- data/lib/re2.rb +9 -3
- data/ports/archives/20240116.1.tar.gz +0 -0
- data/ports/archives/re2-2024-04-01.tar.gz +0 -0
- data/re2.gemspec +5 -2
- data/spec/kernel_spec.rb +10 -2
- data/spec/re2/match_data_spec.rb +98 -28
- data/spec/re2/regexp_spec.rb +546 -113
- data/spec/re2/scanner_spec.rb +26 -9
- data/spec/re2/set_spec.rb +28 -18
- data/spec/re2/string_spec.rb +2 -0
- data/spec/re2_spec.rb +34 -4
- data/spec/spec_helper.rb +2 -0
- metadata +10 -9
- data/ports/archives/20230802.1.tar.gz +0 -0
- data/ports/archives/re2-2023-11-01.tar.gz +0 -0
data/ext/re2/recipes.rb
CHANGED
@@ -1,25 +1,15 @@
|
|
1
|
-
|
2
|
-
REQUIRED_MINI_PORTILE_VERSION = '~> 2.8.5' # keep this version in sync with the one in the gemspec
|
3
|
-
|
4
|
-
def build_recipe(name, version)
|
5
|
-
require 'rubygems'
|
6
|
-
gem('mini_portile2', REQUIRED_MINI_PORTILE_VERSION) # gemspec is not respected at install time
|
7
|
-
require 'mini_portile2'
|
1
|
+
# frozen_string_literal: true
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# ensures pkg-config and installed libraries will be in lib, not lib64
|
17
|
-
'-DCMAKE_INSTALL_LIBDIR=lib'
|
18
|
-
]
|
3
|
+
# re2 (https://github.com/mudge/re2)
|
4
|
+
# Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to
|
5
|
+
# backtracking regular expression engines like those used in PCRE, Perl, and
|
6
|
+
# Python".
|
7
|
+
#
|
8
|
+
# Copyright (c) 2010, Paul Mucur (https://mudge.name)
|
9
|
+
# Released under the BSD Licence, please see LICENSE.txt
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
11
|
+
PACKAGE_ROOT_DIR = File.expand_path('../..', __dir__)
|
12
|
+
REQUIRED_MINI_PORTILE_VERSION = '~> 2.8.5' # keep this version in sync with the one in the gemspec
|
23
13
|
|
24
14
|
def load_recipes
|
25
15
|
require 'yaml'
|
@@ -41,3 +31,24 @@ def load_recipes
|
|
41
31
|
|
42
32
|
[abseil_recipe, re2_recipe]
|
43
33
|
end
|
34
|
+
|
35
|
+
def build_recipe(name, version)
|
36
|
+
require 'rubygems'
|
37
|
+
gem('mini_portile2', REQUIRED_MINI_PORTILE_VERSION) # gemspec is not respected at install time
|
38
|
+
require 'mini_portile2'
|
39
|
+
|
40
|
+
MiniPortileCMake.new(name, version).tap do |recipe|
|
41
|
+
recipe.target = File.join(PACKAGE_ROOT_DIR, 'ports')
|
42
|
+
recipe.configure_options += [
|
43
|
+
# abseil needs a C++14 compiler
|
44
|
+
'-DCMAKE_CXX_STANDARD=14',
|
45
|
+
# needed for building the C extension shared library with -fPIC
|
46
|
+
'-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
|
47
|
+
# ensures pkg-config and installed libraries will be in lib, not lib64
|
48
|
+
'-DCMAKE_INSTALL_LIBDIR=lib',
|
49
|
+
'-DCMAKE_CXX_VISIBILITY_PRESET=hidden'
|
50
|
+
]
|
51
|
+
|
52
|
+
yield recipe
|
53
|
+
end
|
54
|
+
end
|
data/lib/re2/regexp.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# re2 (https://github.com/mudge/re2)
|
4
|
+
# Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to
|
5
|
+
# backtracking regular expression engines like those used in PCRE, Perl, and
|
6
|
+
# Python".
|
7
|
+
#
|
8
|
+
# Copyright (c) 2010, Paul Mucur (https://mudge.name)
|
9
|
+
# Released under the BSD Licence, please see LICENSE.txt
|
10
|
+
|
11
|
+
|
12
|
+
module RE2
|
13
|
+
class Regexp
|
14
|
+
# Match the pattern against any substring of the given `text` and return a
|
15
|
+
# {RE2::MatchData} instance with the specified number of submatches
|
16
|
+
# (defaults to the total number of capturing groups) or a boolean (if no
|
17
|
+
# submatches are required).
|
18
|
+
#
|
19
|
+
# The number of submatches has a significant impact on performance: requesting
|
20
|
+
# one submatch is much faster than requesting more than one and requesting
|
21
|
+
# zero submatches is faster still.
|
22
|
+
#
|
23
|
+
# @param [String] text the text to search
|
24
|
+
# @param [Hash] options the options with which to perform the match
|
25
|
+
# @option options [Integer] :submatches how many submatches to extract (0
|
26
|
+
# is fastest), defaults to the total number of capturing groups
|
27
|
+
# @return [RE2::MatchData, nil] if extracting any submatches
|
28
|
+
# @return [Boolean] if not extracting any submatches
|
29
|
+
# @raise [ArgumentError] if given a negative number of submatches
|
30
|
+
# @raise [NoMemoryError] if there was not enough memory to allocate the
|
31
|
+
# matches
|
32
|
+
# @raise [TypeError] if given non-numeric submatches or non-hash options
|
33
|
+
# @example
|
34
|
+
# r = RE2::Regexp.new('w(o)(o)')
|
35
|
+
# r.partial_match('woot') #=> #<RE2::MatchData "woo" 1:"o" 2:"o">
|
36
|
+
# r.partial_match('nope') #=> nil
|
37
|
+
# r.partial_match('woot', submatches: 1) #=> #<RE2::MatchData "woo" 1:"o">
|
38
|
+
# r.partial_match('woot', submatches: 0) #=> true
|
39
|
+
def partial_match(text, options = {})
|
40
|
+
match(text, Hash(options).merge(anchor: :unanchored))
|
41
|
+
end
|
42
|
+
|
43
|
+
# Match the pattern against the given `text` exactly and return a
|
44
|
+
# {RE2::MatchData} instance with the specified number of submatches
|
45
|
+
# (defaults to the total number of capturing groups) or a boolean (if no
|
46
|
+
# submatches are required).
|
47
|
+
#
|
48
|
+
# The number of submatches has a significant impact on performance: requesting
|
49
|
+
# one submatch is much faster than requesting more than one and requesting
|
50
|
+
# zero submatches is faster still.
|
51
|
+
#
|
52
|
+
# @param [String] text the text to search
|
53
|
+
# @param [Hash] options the options with which to perform the match
|
54
|
+
# @option options [Integer] :submatches how many submatches to extract (0
|
55
|
+
# is fastest), defaults to the total number of capturing groups
|
56
|
+
# @return [RE2::MatchData, nil] if extracting any submatches
|
57
|
+
# @return [Boolean] if not extracting any submatches
|
58
|
+
# @raise [ArgumentError] if given a negative number of submatches
|
59
|
+
# @raise [NoMemoryError] if there was not enough memory to allocate the
|
60
|
+
# matches
|
61
|
+
# @raise [TypeError] if given non-numeric submatches or non-hash options
|
62
|
+
# @example
|
63
|
+
# r = RE2::Regexp.new('w(o)(o)')
|
64
|
+
# r.full_match('woo') #=> #<RE2::MatchData "woo" 1:"o" 2:"o">
|
65
|
+
# r.full_match('woot') #=> nil
|
66
|
+
# r.full_match('woo', submatches: 1) #=> #<RE2::MatchData "woo" 1:"o">
|
67
|
+
# r.full_match('woo', submatches: 0) #=> true
|
68
|
+
def full_match(text, options = {})
|
69
|
+
match(text, Hash(options).merge(anchor: :anchor_both))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/re2/scanner.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# re2 (https://github.com/mudge/re2)
|
4
|
+
# Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to
|
5
|
+
# backtracking regular expression engines like those used in PCRE, Perl, and
|
6
|
+
# Python".
|
7
|
+
#
|
8
|
+
# Copyright (c) 2010, Paul Mucur (https://mudge.name)
|
9
|
+
# Released under the BSD Licence, please see LICENSE.txt
|
10
|
+
|
11
|
+
|
1
12
|
module RE2
|
2
13
|
class Scanner
|
3
14
|
include Enumerable
|
data/lib/re2/string.rb
CHANGED
@@ -1,81 +1,34 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# re2 (https://github.com/mudge/re2)
|
4
|
+
# Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to
|
5
|
+
# backtracking regular expression engines like those used in PCRE, Perl, and
|
6
|
+
# Python".
|
3
7
|
#
|
4
|
-
# Copyright (c) 2010
|
8
|
+
# Copyright (c) 2010, Paul Mucur (https://mudge.name)
|
5
9
|
# Released under the BSD Licence, please see LICENSE.txt
|
6
10
|
|
7
11
|
require "re2"
|
8
12
|
|
9
13
|
module RE2
|
14
|
+
# @deprecated Use methods on {RE2} and {RE2::Regexp} instead.
|
10
15
|
module String
|
11
|
-
|
12
|
-
# Replaces the first occurrence +pattern+ with +rewrite+ and returns a new
|
13
|
-
# string.
|
14
|
-
#
|
15
|
-
# @see RE2.Replace
|
16
|
+
# @deprecated Use {RE2.Replace} instead.
|
16
17
|
def re2_sub(*args)
|
17
18
|
RE2.Replace(self, *args)
|
18
19
|
end
|
19
20
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# @see RE2.GlobalReplace
|
21
|
+
# @deprecated Use {RE2.GlobalReplace} instead.
|
23
22
|
def re2_gsub(*args)
|
24
23
|
RE2.GlobalReplace(self, *args)
|
25
24
|
end
|
26
25
|
|
27
|
-
#
|
28
|
-
# or a {RE2::MatchData} instance.
|
29
|
-
#
|
30
|
-
# @return [Boolean, RE2::MatchData]
|
31
|
-
#
|
32
|
-
# @overload match(pattern)
|
33
|
-
# Returns an {RE2::MatchData} containing the matching
|
34
|
-
# pattern and all subpatterns resulting from looking for
|
35
|
-
# +pattern+.
|
36
|
-
#
|
37
|
-
# @param [String, RE2::Regexp] pattern the regular expression to match
|
38
|
-
# @return [RE2::MatchData] the matches
|
39
|
-
# @raise [NoMemoryError] if there was not enough memory to allocate the matches
|
40
|
-
# @example
|
41
|
-
# r = RE2::Regexp.new('w(o)(o)')
|
42
|
-
# "woo".re2_match(r) #=> #<RE2::MatchData "woo" 1:"o" 2:"o">
|
43
|
-
#
|
44
|
-
# @overload match(pattern, 0)
|
45
|
-
# Returns either true or false indicating whether a
|
46
|
-
# successful match was made.
|
47
|
-
#
|
48
|
-
# @param [String, RE2::Regexp] pattern the regular expression to match
|
49
|
-
# @return [Boolean] whether the match was successful
|
50
|
-
# @raise [NoMemoryError] if there was not enough memory to allocate the matches
|
51
|
-
# @example
|
52
|
-
# r = RE2::Regexp.new('w(o)(o)')
|
53
|
-
# "woo".re2_match(0) #=> true
|
54
|
-
# "bob".re2_match(0) #=> false
|
55
|
-
#
|
56
|
-
# @overload match(pattern, number_of_matches)
|
57
|
-
# See +match(pattern)+ but with a specific number of
|
58
|
-
# matches returned (padded with nils if necessary).
|
59
|
-
#
|
60
|
-
# @param [String, RE2::Regexp] pattern the regular expression to match
|
61
|
-
# @param [Integer] number_of_matches the number of matches to return
|
62
|
-
# @return [RE2::MatchData] the matches
|
63
|
-
# @raise [NoMemoryError] if there was not enough memory to allocate the matches
|
64
|
-
# @example
|
65
|
-
# r = RE2::Regexp.new('w(o)(o)')
|
66
|
-
# "woo".re2_match(r, 1) #=> #<RE2::MatchData "woo" 1:"o">
|
67
|
-
# "woo".re2_match(r, 3) #=> #<RE2::MatchData "woo" 1:"o" 2:"o" 3:nil>
|
26
|
+
# @deprecated Use {RE2::Regexp#match} instead.
|
68
27
|
def re2_match(pattern, *args)
|
69
28
|
RE2::Regexp.new(pattern).match(self, *args)
|
70
29
|
end
|
71
30
|
|
72
|
-
#
|
73
|
-
# The returned string, used as a regular expression, will exactly match the
|
74
|
-
# original string.
|
75
|
-
#
|
76
|
-
# @return [String] the escaped string
|
77
|
-
# @example
|
78
|
-
# "1.5-2.0?".escape #=> "1\.5\-2\.0\?"
|
31
|
+
# @deprecated Use {RE2.QuoteMeta} instead.
|
79
32
|
def re2_escape
|
80
33
|
RE2.QuoteMeta(self)
|
81
34
|
end
|
data/lib/re2/version.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# re2 (https://github.com/mudge/re2)
|
4
|
+
# Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to
|
5
|
+
# backtracking regular expression engines like those used in PCRE, Perl, and
|
6
|
+
# Python".
|
7
|
+
#
|
8
|
+
# Copyright (c) 2010, Paul Mucur (https://mudge.name)
|
9
|
+
# Released under the BSD Licence, please see LICENSE.txt
|
10
|
+
|
11
|
+
|
3
12
|
module RE2
|
4
|
-
VERSION = "2.
|
13
|
+
VERSION = "2.10.0"
|
5
14
|
end
|
data/lib/re2.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# re2 (https://github.com/mudge/re2)
|
4
|
+
# Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to
|
5
|
+
# backtracking regular expression engines like those used in PCRE, Perl, and
|
6
|
+
# Python".
|
3
7
|
#
|
4
|
-
# Copyright (c) 2010
|
8
|
+
# Copyright (c) 2010, Paul Mucur (https://mudge.name)
|
5
9
|
# Released under the BSD Licence, please see LICENSE.txt
|
10
|
+
|
6
11
|
begin
|
7
12
|
::RUBY_VERSION =~ /(\d+\.\d+)/
|
8
13
|
require_relative "#{Regexp.last_match(1)}/re2.so"
|
@@ -10,5 +15,6 @@ rescue LoadError
|
|
10
15
|
require 're2.so'
|
11
16
|
end
|
12
17
|
|
18
|
+
require "re2/regexp"
|
13
19
|
require "re2/scanner"
|
14
20
|
require "re2/version"
|
Binary file
|
Binary file
|
data/re2.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/re2/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
@@ -17,6 +19,7 @@ Gem::Specification.new do |s|
|
|
17
19
|
"ext/re2/recipes.rb",
|
18
20
|
"Gemfile",
|
19
21
|
"lib/re2.rb",
|
22
|
+
"lib/re2/regexp.rb",
|
20
23
|
"lib/re2/scanner.rb",
|
21
24
|
"lib/re2/string.rb",
|
22
25
|
"lib/re2/version.rb",
|
@@ -37,8 +40,8 @@ Gem::Specification.new do |s|
|
|
37
40
|
"spec/re2/set_spec.rb",
|
38
41
|
"spec/re2/scanner_spec.rb"
|
39
42
|
]
|
40
|
-
s.add_development_dependency("rake-compiler", "~> 1.2.
|
41
|
-
s.add_development_dependency("rake-compiler-dock", "~> 1.
|
43
|
+
s.add_development_dependency("rake-compiler", "~> 1.2.5")
|
44
|
+
s.add_development_dependency("rake-compiler-dock", "~> 1.4.0")
|
42
45
|
s.add_development_dependency("rspec", "~> 3.2")
|
43
46
|
s.add_runtime_dependency("mini_portile2", "~> 2.8.5") # keep version in sync with extconf.rb
|
44
47
|
end
|
data/spec/kernel_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Kernel do
|
2
4
|
describe ".RE2" do
|
3
5
|
it "returns an RE2::Regexp instance given a pattern" do
|
@@ -5,17 +7,23 @@ RSpec.describe Kernel do
|
|
5
7
|
end
|
6
8
|
|
7
9
|
it "returns an RE2::Regexp instance given a pattern and options" do
|
8
|
-
re = RE2('w(o)(o)', :
|
10
|
+
re = RE2('w(o)(o)', case_sensitive: false)
|
9
11
|
|
10
12
|
expect(re).not_to be_case_sensitive
|
11
13
|
end
|
12
14
|
|
15
|
+
it "accepts patterns containing null bytes" do
|
16
|
+
re = RE2("a\0b")
|
17
|
+
|
18
|
+
expect(re.pattern).to eq("a\0b")
|
19
|
+
end
|
20
|
+
|
13
21
|
it "raises an error if given an inappropriate type" do
|
14
22
|
expect { RE2(nil) }.to raise_error(TypeError)
|
15
23
|
end
|
16
24
|
|
17
25
|
it "allows invalid patterns to be created" do
|
18
|
-
re = RE2('???', :
|
26
|
+
re = RE2('???', log_errors: false)
|
19
27
|
|
20
28
|
expect(re).to be_a(RE2::Regexp)
|
21
29
|
end
|