re2 0.5.0 → 0.6.0.pre
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 +7 -0
- data/LICENSE.txt +1 -1
- data/README.md +71 -19
- data/Rakefile +1 -3
- data/ext/re2/re2.cc +353 -201
- data/lib/re2.rb +7 -0
- data/lib/re2/consumer.rb +15 -0
- data/lib/re2/string.rb +1 -1
- data/spec/re2/consumer_spec.rb +90 -0
- data/spec/re2/match_data_spec.rb +16 -0
- data/spec/re2/regexp_spec.rb +9 -0
- data/spec/re2/string_spec.rb +2 -2
- data/spec/re2_spec.rb +8 -0
- metadata +26 -19
data/lib/re2.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# re2 (http://github.com/mudge/re2)
|
2
|
+
# Ruby bindings to re2, an "efficient, principled regular expression library"
|
3
|
+
#
|
4
|
+
# Copyright (c) 2010-2013, Paul Mucur (http://mudge.name)
|
5
|
+
# Released under the BSD Licence, please see LICENSE.txt
|
6
|
+
require "re2.so"
|
7
|
+
require "re2/consumer"
|
data/lib/re2/consumer.rb
ADDED
data/lib/re2/string.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# re2 (http://github.com/mudge/re2)
|
2
2
|
# Ruby bindings to re2, an "efficient, principled regular expression library"
|
3
3
|
#
|
4
|
-
# Copyright (c) 2010-
|
4
|
+
# Copyright (c) 2010-2013, Paul Mucur (http://mudge.name)
|
5
5
|
# Released under the BSD Licence, please see LICENSE.txt
|
6
6
|
|
7
7
|
require "re2"
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RE2::Consumer do
|
4
|
+
describe "#regexp" do
|
5
|
+
it "returns the original pattern for the consumer" do
|
6
|
+
re = RE2::Regexp.new('(\w+)')
|
7
|
+
consumer = re.consume("It is a truth")
|
8
|
+
|
9
|
+
consumer.regexp.must_be_same_as(re)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#string" do
|
14
|
+
it "returns the original text for the consumer" do
|
15
|
+
re = RE2::Regexp.new('(\w+)')
|
16
|
+
text = "It is a truth"
|
17
|
+
consumer = re.consume(text)
|
18
|
+
|
19
|
+
consumer.string.must_be_same_as(text)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#consume" do
|
24
|
+
it "returns the next array of matches" do
|
25
|
+
r = RE2::Regexp.new('(\w+)')
|
26
|
+
consumer = r.consume("It is a truth universally acknowledged")
|
27
|
+
consumer.consume.must_equal(["It"])
|
28
|
+
consumer.consume.must_equal(["is"])
|
29
|
+
consumer.consume.must_equal(["a"])
|
30
|
+
consumer.consume.must_equal(["truth"])
|
31
|
+
consumer.consume.must_equal(["universally"])
|
32
|
+
consumer.consume.must_equal(["acknowledged"])
|
33
|
+
consumer.consume.must_be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns an empty array if there are no capturing groups" do
|
37
|
+
r = RE2::Regexp.new('\w+')
|
38
|
+
consumer = r.consume("Foo bar")
|
39
|
+
consumer.consume.must_equal([])
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns nil if there is no match" do
|
43
|
+
r = RE2::Regexp.new('\d+')
|
44
|
+
consumer = r.consume("Foo bar")
|
45
|
+
consumer.consume.must_be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is enumerable" do
|
50
|
+
r = RE2::Regexp.new('(\d)')
|
51
|
+
consumer = r.consume("There are 1 some 2 numbers 3")
|
52
|
+
consumer.must_be_kind_of(Enumerable)
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#each" do
|
56
|
+
it "yields each match" do
|
57
|
+
r = RE2::Regexp.new('(\d)')
|
58
|
+
consumer = r.consume("There are 1 some 2 numbers 3")
|
59
|
+
matches = []
|
60
|
+
consumer.each do |match|
|
61
|
+
matches << match
|
62
|
+
end
|
63
|
+
|
64
|
+
matches.must_equal([["1"], ["2"], ["3"]])
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns an enumerator when not given a block" do
|
68
|
+
r = RE2::Regexp.new('(\d)')
|
69
|
+
consumer = r.consume("There are 1 some 2 numbers 3")
|
70
|
+
|
71
|
+
# Prior to Ruby 1.9, Enumerator was within Enumerable.
|
72
|
+
if defined?(Enumerator)
|
73
|
+
consumer.each.must_be_kind_of(Enumerator)
|
74
|
+
elsif defined?(Enumerable::Enumerator)
|
75
|
+
consumer.each.must_be_kind_of(Enumerable::Enumerator)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#rewind" do
|
81
|
+
it "resets any consumption" do
|
82
|
+
r = RE2::Regexp.new('(\d)')
|
83
|
+
consumer = r.consume("There are 1 some 2 numbers 3")
|
84
|
+
consumer.to_enum.first.must_equal(["1"])
|
85
|
+
consumer.to_enum.first.must_equal(["2"])
|
86
|
+
consumer.rewind
|
87
|
+
consumer.to_enum.first.must_equal(["1"])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/spec/re2/match_data_spec.rb
CHANGED
@@ -68,6 +68,22 @@ describe RE2::MatchData do
|
|
68
68
|
md["missing"].must_be_nil
|
69
69
|
md[:missing].must_be_nil
|
70
70
|
end
|
71
|
+
|
72
|
+
if String.method_defined?(:encoding)
|
73
|
+
it "returns UTF-8 encoded strings by default" do
|
74
|
+
md = RE2::Regexp.new('(?P<name>\S+)').match("bob")
|
75
|
+
md[0].encoding.name.must_equal("UTF-8")
|
76
|
+
md["name"].encoding.name.must_equal("UTF-8")
|
77
|
+
md[:name].encoding.name.must_equal("UTF-8")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns Latin 1 strings encoding when utf-8 is false" do
|
81
|
+
md = RE2::Regexp.new('(?P<name>\S+)', :utf8 => false).match('bob')
|
82
|
+
md[0].encoding.name.must_equal("ISO-8859-1")
|
83
|
+
md["name"].encoding.name.must_equal("ISO-8859-1")
|
84
|
+
md[:name].encoding.name.must_equal("ISO-8859-1")
|
85
|
+
end
|
86
|
+
end
|
71
87
|
end
|
72
88
|
|
73
89
|
describe "#string" do
|
data/spec/re2/regexp_spec.rb
CHANGED
@@ -391,4 +391,13 @@ describe RE2::Regexp do
|
|
391
391
|
groups["rob"].must_equal(3)
|
392
392
|
end
|
393
393
|
end
|
394
|
+
|
395
|
+
describe "#consume" do
|
396
|
+
it "returns a consumer" do
|
397
|
+
r = RE2::Regexp.new('(\w+)')
|
398
|
+
consumer = r.consume("It is a truth universally acknowledged")
|
399
|
+
|
400
|
+
consumer.must_be_instance_of(RE2::Consumer)
|
401
|
+
end
|
402
|
+
end
|
394
403
|
end
|
data/spec/re2/string_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe RE2::String do
|
|
11
11
|
"My name is Robert Paulson".re2_sub!('Robert', 'Crobert').must_equal("My name is Crobert Paulson")
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "does perform an in-place replacement" do
|
15
15
|
string = "My name is Robert Paulson"
|
16
16
|
string.re2_sub!('Robert', 'Crobert').must_be_same_as(string)
|
17
17
|
end
|
@@ -22,7 +22,7 @@ describe RE2::String do
|
|
22
22
|
"My name is Robert Paulson".re2_gsub!('a', 'e').must_equal("My neme is Robert Peulson")
|
23
23
|
end
|
24
24
|
|
25
|
-
it "
|
25
|
+
it "does perform an in-place replacement" do
|
26
26
|
string = "My name is Robert Paulson"
|
27
27
|
string.re2_gsub!('a', 'e').must_be_same_as(string)
|
28
28
|
end
|
data/spec/re2_spec.rb
CHANGED
@@ -36,6 +36,14 @@ describe RE2 do
|
|
36
36
|
|
37
37
|
proc { RE2.Replace(frozen_name, "o", "a") }.must_raise(TypeError, RuntimeError)
|
38
38
|
end
|
39
|
+
|
40
|
+
if String.method_defined?(:encoding)
|
41
|
+
it "preserves the original string's encoding" do
|
42
|
+
original = "Foo"
|
43
|
+
replacement = RE2.Replace(original, "oo", "ah")
|
44
|
+
original.encoding.must_equal(replacement.encoding)
|
45
|
+
end
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
describe "#GlobalReplace" do
|
metadata
CHANGED
@@ -1,38 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: re2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0.pre
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Paul Mucur
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-09-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake-compiler
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: minitest
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
description: Ruby bindings to re2, "an efficient, principled regular expression library".
|
37
42
|
email: ruby.re2@librelist.com
|
38
43
|
executables: []
|
@@ -42,6 +47,8 @@ extra_rdoc_files: []
|
|
42
47
|
files:
|
43
48
|
- ext/re2/extconf.rb
|
44
49
|
- ext/re2/re2.cc
|
50
|
+
- lib/re2.rb
|
51
|
+
- lib/re2/consumer.rb
|
45
52
|
- lib/re2/string.rb
|
46
53
|
- LICENSE.txt
|
47
54
|
- README.md
|
@@ -52,29 +59,29 @@ files:
|
|
52
59
|
- spec/re2/regexp_spec.rb
|
53
60
|
- spec/re2/match_data_spec.rb
|
54
61
|
- spec/re2/string_spec.rb
|
62
|
+
- spec/re2/consumer_spec.rb
|
55
63
|
homepage: http://github.com/mudge/re2
|
56
64
|
licenses: []
|
65
|
+
metadata: {}
|
57
66
|
post_install_message:
|
58
67
|
rdoc_options: []
|
59
68
|
require_paths:
|
60
69
|
- lib
|
61
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
71
|
requirements:
|
64
|
-
- -
|
72
|
+
- - '>='
|
65
73
|
- !ruby/object:Gem::Version
|
66
74
|
version: '0'
|
67
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
76
|
requirements:
|
70
|
-
- -
|
77
|
+
- - '>'
|
71
78
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
79
|
+
version: 1.3.1
|
73
80
|
requirements: []
|
74
81
|
rubyforge_project:
|
75
|
-
rubygems_version:
|
82
|
+
rubygems_version: 2.0.3
|
76
83
|
signing_key:
|
77
|
-
specification_version:
|
84
|
+
specification_version: 4
|
78
85
|
summary: Ruby bindings to re2.
|
79
86
|
test_files:
|
80
87
|
- spec/spec_helper.rb
|
@@ -83,4 +90,4 @@ test_files:
|
|
83
90
|
- spec/re2/regexp_spec.rb
|
84
91
|
- spec/re2/match_data_spec.rb
|
85
92
|
- spec/re2/string_spec.rb
|
86
|
-
|
93
|
+
- spec/re2/consumer_spec.rb
|