re2 1.7.0 → 2.1.3
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/.rspec +2 -0
- data/Gemfile +5 -0
- data/LICENSE-DEPENDENCIES.txt +237 -0
- data/LICENSE.txt +1 -1
- data/README.md +79 -19
- data/Rakefile +125 -3
- data/dependencies.yml +9 -0
- data/ext/re2/extconf.rb +371 -57
- data/ext/re2/re2.cc +365 -353
- data/ext/re2/recipes.rb +43 -0
- data/lib/re2/version.rb +5 -0
- data/lib/re2.rb +8 -1
- data/ports/archives/20230125.3.tar.gz +0 -0
- data/ports/archives/re2-2023-09-01.tar.gz +0 -0
- data/re2.gemspec +44 -0
- data/spec/kernel_spec.rb +3 -3
- data/spec/re2/match_data_spec.rb +24 -0
- data/spec/re2/regexp_spec.rb +6 -0
- data/spec/re2/scanner_spec.rb +76 -22
- data/spec/re2/set_spec.rb +55 -2
- data/spec/re2/string_spec.rb +7 -3
- data/spec/re2_spec.rb +104 -10
- data/spec/spec_helper.rb +10 -0
- metadata +50 -11
data/spec/re2_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
RSpec.describe RE2 do
|
2
|
-
describe "
|
2
|
+
describe ".Replace" do
|
3
3
|
it "only replaces the first occurrence of the pattern" do
|
4
4
|
expect(RE2.Replace("woo", "o", "a")).to eq("wao")
|
5
5
|
end
|
@@ -15,29 +15,68 @@ RSpec.describe RE2 do
|
|
15
15
|
it "does not perform replacements in-place" do
|
16
16
|
name = "Robert"
|
17
17
|
replacement = RE2.Replace(name, "R", "Cr")
|
18
|
-
|
18
|
+
|
19
|
+
expect(name).not_to equal(replacement)
|
19
20
|
end
|
20
21
|
|
21
22
|
it "supports passing an RE2::Regexp as the pattern" do
|
22
23
|
re = RE2::Regexp.new('wo{2}')
|
24
|
+
|
23
25
|
expect(RE2.Replace("woo", re, "miaow")).to eq("miaow")
|
24
26
|
end
|
25
27
|
|
26
28
|
it "respects any passed RE2::Regexp's flags" do
|
27
29
|
re = RE2::Regexp.new('gOOD MORNING', :case_sensitive => false)
|
30
|
+
|
28
31
|
expect(RE2.Replace("Good morning", re, "hi")).to eq("hi")
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
it "supports passing something that can be coerced to a String as input" do
|
35
|
+
expect(RE2.Replace(StringLike.new("woo"), "oo", "ah")).to eq("wah")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "supports passing something that can be coerced to a String as a pattern" do
|
39
|
+
expect(RE2.Replace("woo", StringLike.new("oo"), "ah")).to eq("wah")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "supports passing something that can be coerced to a String as a replacement" do
|
43
|
+
expect(RE2.Replace("woo", "oo", StringLike.new("ah"))).to eq("wah")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns UTF-8 strings if the pattern is UTF-8" do
|
47
|
+
original = "Foo".encode("ISO-8859-1")
|
48
|
+
replacement = RE2.Replace(original, "oo", "ah")
|
49
|
+
|
50
|
+
expect(replacement.encoding).to eq(Encoding::UTF_8)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
|
54
|
+
original = "Foo"
|
55
|
+
replacement = RE2.Replace(original, RE2("oo", :utf8 => false), "ah")
|
56
|
+
|
57
|
+
expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns UTF-8 strings when given a String pattern" do
|
61
|
+
replacement = RE2.Replace("Foo", "oo".encode("ISO-8859-1"), "ah")
|
62
|
+
|
63
|
+
expect(replacement.encoding).to eq(Encoding::UTF_8)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises a Type Error for input that can't be converted to String" do
|
67
|
+
expect { RE2.Replace(0, "oo", "ah") }.to raise_error(TypeError)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raises a Type Error for a non-RE2::Regexp pattern that can't be converted to String" do
|
71
|
+
expect { RE2.Replace("woo", 0, "ah") }.to raise_error(TypeError)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "raises a Type Error for a replacement that can't be converted to String" do
|
75
|
+
expect { RE2.Replace("woo", "oo", 0) }.to raise_error(TypeError)
|
37
76
|
end
|
38
77
|
end
|
39
78
|
|
40
|
-
describe "
|
79
|
+
describe ".GlobalReplace" do
|
41
80
|
it "replaces every occurrence of a pattern" do
|
42
81
|
expect(RE2.GlobalReplace("woo", "o", "a")).to eq("waa")
|
43
82
|
end
|
@@ -53,23 +92,78 @@ RSpec.describe RE2 do
|
|
53
92
|
it "does not perform replacement in-place" do
|
54
93
|
name = "Robert"
|
55
94
|
replacement = RE2.GlobalReplace(name, "(?i)R", "w")
|
56
|
-
|
95
|
+
|
96
|
+
expect(name).not_to equal(replacement)
|
57
97
|
end
|
58
98
|
|
59
99
|
it "supports passing an RE2::Regexp as the pattern" do
|
60
100
|
re = RE2::Regexp.new('wo{2,}')
|
101
|
+
|
61
102
|
expect(RE2.GlobalReplace("woowooo", re, "miaow")).to eq("miaowmiaow")
|
62
103
|
end
|
63
104
|
|
64
105
|
it "respects any passed RE2::Regexp's flags" do
|
65
106
|
re = RE2::Regexp.new('gOOD MORNING', :case_sensitive => false)
|
107
|
+
|
66
108
|
expect(RE2.GlobalReplace("Good morning Good morning", re, "hi")).to eq("hi hi")
|
67
109
|
end
|
110
|
+
|
111
|
+
it "supports passing something that can be coerced to a String as input" do
|
112
|
+
expect(RE2.GlobalReplace(StringLike.new("woo"), "o", "a")).to eq("waa")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "supports passing something that can be coerced to a String as a pattern" do
|
116
|
+
expect(RE2.GlobalReplace("woo", StringLike.new("o"), "a")).to eq("waa")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "supports passing something that can be coerced to a String as a replacement" do
|
120
|
+
expect(RE2.GlobalReplace("woo", "o", StringLike.new("a"))).to eq("waa")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns UTF-8 strings if the pattern is UTF-8" do
|
124
|
+
original = "Foo".encode("ISO-8859-1")
|
125
|
+
replacement = RE2.GlobalReplace(original, "oo", "ah")
|
126
|
+
|
127
|
+
expect(replacement.encoding).to eq(Encoding::UTF_8)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
|
131
|
+
original = "Foo"
|
132
|
+
replacement = RE2.GlobalReplace(original, RE2("oo", :utf8 => false), "ah")
|
133
|
+
|
134
|
+
expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "returns UTF-8 strings when given a String pattern" do
|
138
|
+
replacement = RE2.GlobalReplace("Foo", "oo".encode("ISO-8859-1"), "ah")
|
139
|
+
|
140
|
+
expect(replacement.encoding).to eq(Encoding::UTF_8)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "raises a Type Error for input that can't be converted to String" do
|
144
|
+
expect { RE2.GlobalReplace(0, "o", "a") }.to raise_error(TypeError)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "raises a Type Error for a non-RE2::Regexp pattern that can't be converted to String" do
|
148
|
+
expect { RE2.GlobalReplace("woo", 0, "a") }.to raise_error(TypeError)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "raises a Type Error for a replacement that can't be converted to String" do
|
152
|
+
expect { RE2.GlobalReplace("woo", "o", 0) }.to raise_error(TypeError)
|
153
|
+
end
|
68
154
|
end
|
69
155
|
|
70
156
|
describe "#QuoteMeta" do
|
71
157
|
it "escapes a string so it can be used as a regular expression" do
|
72
158
|
expect(RE2.QuoteMeta("1.5-2.0?")).to eq('1\.5\-2\.0\?')
|
73
159
|
end
|
160
|
+
|
161
|
+
it "raises a Type Error for input that can't be converted to String" do
|
162
|
+
expect { RE2.QuoteMeta(0) }.to raise_error(TypeError)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "supports passing something that can be coerced to a String as input" do
|
166
|
+
expect(RE2.QuoteMeta(StringLike.new("1.5"))).to eq('1\.5')
|
167
|
+
end
|
74
168
|
end
|
75
169
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
require "re2"
|
2
2
|
|
3
|
+
# To test passing objects that can be coerced to a String.
|
4
|
+
class StringLike
|
5
|
+
attr_reader :str
|
6
|
+
alias_method :to_str, :str
|
7
|
+
|
8
|
+
def initialize(str)
|
9
|
+
@str = str
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
RSpec.configure do |config|
|
4
14
|
config.expect_with :rspec do |expectations|
|
5
15
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: re2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
8
|
-
|
8
|
+
- Stan Hu
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2023-
|
12
|
+
date: 2023-09-23 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake-compiler
|
@@ -16,14 +17,28 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
+
version: 1.2.1
|
20
21
|
type: :development
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
+
version: 1.2.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake-compiler-dock
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.3.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.3.0
|
27
42
|
- !ruby/object:Gem::Dependency
|
28
43
|
name: rspec
|
29
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,21 +53,45 @@ dependencies:
|
|
38
53
|
- - "~>"
|
39
54
|
- !ruby/object:Gem::Version
|
40
55
|
version: '3.2'
|
41
|
-
|
42
|
-
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mini_portile2
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.8.4
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.8.4
|
70
|
+
description: Ruby bindings to RE2, "a fast, safe, thread-friendly alternative to backtracking
|
71
|
+
regular expression engines like those used in PCRE, Perl, and Python".
|
72
|
+
email:
|
43
73
|
executables: []
|
44
74
|
extensions:
|
45
75
|
- ext/re2/extconf.rb
|
46
76
|
extra_rdoc_files: []
|
47
77
|
files:
|
78
|
+
- ".rspec"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE-DEPENDENCIES.txt
|
48
81
|
- LICENSE.txt
|
49
82
|
- README.md
|
50
83
|
- Rakefile
|
84
|
+
- dependencies.yml
|
51
85
|
- ext/re2/extconf.rb
|
52
86
|
- ext/re2/re2.cc
|
87
|
+
- ext/re2/recipes.rb
|
53
88
|
- lib/re2.rb
|
54
89
|
- lib/re2/scanner.rb
|
55
90
|
- lib/re2/string.rb
|
91
|
+
- lib/re2/version.rb
|
92
|
+
- ports/archives/20230125.3.tar.gz
|
93
|
+
- ports/archives/re2-2023-09-01.tar.gz
|
94
|
+
- re2.gemspec
|
56
95
|
- spec/kernel_spec.rb
|
57
96
|
- spec/re2/match_data_spec.rb
|
58
97
|
- spec/re2/regexp_spec.rb
|
@@ -65,7 +104,7 @@ homepage: https://github.com/mudge/re2
|
|
65
104
|
licenses:
|
66
105
|
- BSD-3-Clause
|
67
106
|
metadata: {}
|
68
|
-
post_install_message:
|
107
|
+
post_install_message:
|
69
108
|
rdoc_options: []
|
70
109
|
require_paths:
|
71
110
|
- lib
|
@@ -73,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
112
|
requirements:
|
74
113
|
- - ">="
|
75
114
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
115
|
+
version: 2.6.0
|
77
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
117
|
requirements:
|
79
118
|
- - ">="
|
@@ -81,9 +120,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
120
|
version: '0'
|
82
121
|
requirements: []
|
83
122
|
rubygems_version: 3.4.10
|
84
|
-
signing_key:
|
123
|
+
signing_key:
|
85
124
|
specification_version: 4
|
86
|
-
summary: Ruby bindings to
|
125
|
+
summary: Ruby bindings to RE2.
|
87
126
|
test_files:
|
88
127
|
- spec/spec_helper.rb
|
89
128
|
- spec/re2_spec.rb
|