regex_concat 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +16 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +17 -0
- data/VERSION +1 -0
- data/lib/regex_concat.rb +17 -0
- data/lib/regex_concat/version.rb +3 -0
- data/regex_concat.gemspec +22 -0
- data/spec/regex_concat_spec.rb +53 -0
- data/spec/spec_helper.rb +10 -0
- metadata +99 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Caius Durling
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# regex-concat
|
2
|
+
|
3
|
+
Extends the Regexp class with a concat method, which lets you concatenate any number of regular expression objects together.
|
4
|
+
|
5
|
+
If the regular expressions have any options (flags) set, then it adds together all the flags and sets the lot on the resulting regex.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
require "rubygems"
|
10
|
+
require "regex_concat"
|
11
|
+
|
12
|
+
a = /foo/
|
13
|
+
b = /bar/m
|
14
|
+
c = /(sed)/i
|
15
|
+
|
16
|
+
Regexp.concat(a, b, c) # => /foobar(sed)/mi
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
$ gem install caius-regex_concat --source=http://gems.github.com/
|
21
|
+
|
22
|
+
## Patches/Pull Requests
|
23
|
+
|
24
|
+
* Fork the project.
|
25
|
+
* Make your feature addition or bug fix.
|
26
|
+
* Add tests for it. This is important so I don't break it in a
|
27
|
+
future version unintentionally.
|
28
|
+
* Commit, do not mess with rakefile, version, or history.
|
29
|
+
(if you want to have your own version, that is fine but
|
30
|
+
bump version in a commit by itself I can ignore when I pull)
|
31
|
+
* Send me a pull request. Bonus points for topic branches.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
Copyright (c) 2009 Caius Durling. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
Rake::RDocTask.new do |rdoc|
|
11
|
+
version = RegexConcat::VERSION
|
12
|
+
|
13
|
+
rdoc.rdoc_dir = 'rdoc'
|
14
|
+
rdoc.title = "regex_concat #{version}"
|
15
|
+
rdoc.rdoc_files.include('README*')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.0
|
data/lib/regex_concat.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module RegexConcat
|
2
|
+
#
|
3
|
+
# Concatenates Regexp objects together into a new Regexp object.
|
4
|
+
# Keeps any flags, and adds them together. <tt>//i + //m == //im</tt>
|
5
|
+
#
|
6
|
+
# Regexp.concat(/foo/, /bar/) # => /foobar/
|
7
|
+
# Regexp.concat(/foo/i, /bar/) # => /foobar/i
|
8
|
+
# Regexp.concat(/foo/ix, /bar/m) # => /foobar/mix
|
9
|
+
#
|
10
|
+
def concat(*regexes)
|
11
|
+
allflags = regexes.inject(0) { |flags, re| flags | re.options }
|
12
|
+
patterns = regexes.map { |re| re.source }
|
13
|
+
Regexp.new(patterns.join, allflags)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Regexp.send(:extend, RegexConcat)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'regex_concat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "regex_concat"
|
8
|
+
gem.version = RegexConcat::VERSION
|
9
|
+
gem.authors = ["Caius Durling"]
|
10
|
+
gem.email = ["dev@caius.name"]
|
11
|
+
gem.description = %q{Extends the Regexp class with a concat method, which lets you concatenate any number of regular expression objects together.}
|
12
|
+
gem.summary = %q{Concatenate regular expressions}
|
13
|
+
gem.homepage = "http://github.com/caius/regex_concat"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Regexp, "concat" do
|
4
|
+
|
5
|
+
it "should respond to the method" do
|
6
|
+
Regexp.should respond_to(:concat)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should concat two regexps" do
|
10
|
+
Regexp.concat(/foo/, /bar/).should == /foobar/
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should concat three regexps" do
|
14
|
+
Regexp.concat(/foo/, /bar/, /sed/).should == /foobarsed/
|
15
|
+
end
|
16
|
+
|
17
|
+
4.upto(10) do |i|
|
18
|
+
instance_eval <<-EOF
|
19
|
+
it "should concat #{i} regexps" do
|
20
|
+
regexps = []
|
21
|
+
#{i}.times {
|
22
|
+
regexps << /foo/
|
23
|
+
}
|
24
|
+
str = "foo" * #{i}
|
25
|
+
|
26
|
+
Regexp.concat(*regexps).should == /\#{str}/
|
27
|
+
end
|
28
|
+
EOF
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should concat a lot of regexps" do
|
32
|
+
regexps = []
|
33
|
+
5000.times {
|
34
|
+
regexps << /foo/
|
35
|
+
}
|
36
|
+
str = "foo" * 5000
|
37
|
+
|
38
|
+
Regexp.concat(*regexps).should == /#{str}/
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "flags" do
|
42
|
+
|
43
|
+
it "should keep a flag on one of the regexes" do
|
44
|
+
Regexp.concat(/foo/i, /bar/).should == /foobar/i
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should concat two flags on two of the regexes" do
|
48
|
+
Regexp.concat(/foo/i, /bar/m).should == /foobar/im
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: regex_concat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Caius Durling
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Extends the Regexp class with a concat method, which lets you concatenate
|
47
|
+
any number of regular expression objects together.
|
48
|
+
email:
|
49
|
+
- dev@caius.name
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .document
|
55
|
+
- .gitignore
|
56
|
+
- .rspec
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- VERSION
|
62
|
+
- lib/regex_concat.rb
|
63
|
+
- lib/regex_concat/version.rb
|
64
|
+
- regex_concat.gemspec
|
65
|
+
- spec/regex_concat_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: http://github.com/caius/regex_concat
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
hash: -1797637039103144906
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
hash: -1797637039103144906
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.24
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Concatenate regular expressions
|
97
|
+
test_files:
|
98
|
+
- spec/regex_concat_spec.rb
|
99
|
+
- spec/spec_helper.rb
|