regexp_trie 0.2.0 → 0.3.0
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/.travis.yml +4 -1
- data/README.md +12 -3
- data/example/synopsis.rb +2 -0
- data/lib/regexp_trie.rb +4 -4
- data/lib/regexp_trie/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 262475174a73825ef9b5bfaa579b082876858b0f
|
4
|
+
data.tar.gz: e38772708d15f5a0ad150af20d46e0d786422d92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7003a856fd99399cf1e566a8a30847183edac6feb06f25173882ebe4aca9655c7cdba435a617fce7af4ff12f315234aee294b1d63ec319bb0c87aa65e177cb08
|
7
|
+
data.tar.gz: ed1a28a0651d084aa186b9a1519fe2beeb06f7ebcbcfc18f712865b64d8d64e19ab99cad67d0bb89607083d5ab623872541e58d89a3d550bb4d85eb036501756
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
# RegexpTrie
|
1
|
+
# RegexpTrie [](https://travis-ci.org/gfx/ruby-regexp_trie) [](https://badge.fury.io/rb/regexp_trie)
|
2
2
|
|
3
3
|
## Synopsis
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
#!/usr/bin/env ruby
|
7
7
|
require 'regexp_trie'
|
8
|
+
|
8
9
|
# like Regexp.union()
|
9
|
-
p RegexpTrie.union(%w(foobar fooxar foozap fooza)) #
|
10
|
+
p RegexpTrie.union(%w(foobar fooxar foozap fooza)) # /foo(?:bar|xar|zap?)/
|
11
|
+
p RegexpTrie.union(%w(foobar fooxar foozap fooza), option: Regexp::IGNORECASE) # /foo(?:bar|xar|zap?)/i
|
10
12
|
|
11
13
|
# or object-oriented interface
|
12
14
|
rt = RegexpTrie.new
|
13
15
|
%w(foobar fooxar foozap fooza).each do |word|
|
14
16
|
rt.add(word)
|
15
17
|
end
|
16
|
-
p rt.to_regexp #
|
18
|
+
p rt.to_regexp # /foo(?:bar|xar|zap?)/
|
17
19
|
```
|
18
20
|
|
19
21
|
See also the original [Regexp::Trie in Perl](https://metacpan.org/pod/Regexp::Trie).
|
@@ -46,6 +48,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
46
48
|
|
47
49
|
Bug reports and pull requests are welcome on GitHub at https://github.com/gfx/regexp_trie.
|
48
50
|
|
51
|
+
## See Also
|
52
|
+
|
53
|
+
* https://metacpan.org/pod/Regexp::Assemble
|
54
|
+
* https://metacpan.org/pod/Regexp::Trie
|
55
|
+
|
49
56
|
## License
|
50
57
|
|
51
58
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
59
|
+
|
60
|
+
The original code is @dankogai's [Regexp::Trie](https://metacpan.org/pod/Regexp::Trie).
|
data/example/synopsis.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'regexp_trie'
|
3
|
+
|
3
4
|
# like Regexp.union()
|
4
5
|
p RegexpTrie.union(%w(foobar fooxar foozap fooza)) # /foo(?:bar|xar|zap?)/
|
6
|
+
p RegexpTrie.union(%w(foobar fooxar foozap fooza), option: Regexp::IGNORECASE) # /foo(?:bar|xar|zap?)/i
|
5
7
|
|
6
8
|
# or object-oriented interface
|
7
9
|
rt = RegexpTrie.new
|
data/lib/regexp_trie.rb
CHANGED
@@ -17,7 +17,7 @@ class RegexpTrie
|
|
17
17
|
@head = {}
|
18
18
|
end
|
19
19
|
|
20
|
-
# @param [String]
|
20
|
+
# @param [String] str
|
21
21
|
def add(str)
|
22
22
|
return self unless str && str.size > 0
|
23
23
|
|
@@ -26,7 +26,7 @@ class RegexpTrie
|
|
26
26
|
entry[c] ||= {}
|
27
27
|
entry = entry[c]
|
28
28
|
end
|
29
|
-
entry[
|
29
|
+
entry[:end] = true
|
30
30
|
self
|
31
31
|
end
|
32
32
|
|
@@ -42,7 +42,7 @@ class RegexpTrie
|
|
42
42
|
private
|
43
43
|
|
44
44
|
def build(entry)
|
45
|
-
return nil if entry[
|
45
|
+
return nil if entry[:end] && entry.size == 1
|
46
46
|
|
47
47
|
alt = []
|
48
48
|
cc = []
|
@@ -72,7 +72,7 @@ class RegexpTrie
|
|
72
72
|
if cconly
|
73
73
|
"#{result}?"
|
74
74
|
else
|
75
|
-
"(?:#{
|
75
|
+
"(?:#{result})?"
|
76
76
|
end
|
77
77
|
else
|
78
78
|
result
|
data/lib/regexp_trie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regexp_trie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FUJI Goro (gfx)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.5.1
|
112
|
+
rubygems_version: 2.4.5.1
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Optimized Regexp builder with Trie
|