stringglob 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stringglob.rb +18 -11
- data/lib/stringglob/version.rb +1 -1
- data/test/test_stringglob.rb +3 -3
- metadata +21 -40
data/lib/stringglob.rb
CHANGED
@@ -1,34 +1,41 @@
|
|
1
1
|
## Ruby StringGlob: Generate a Regexp object from a glob(3) pattern
|
2
|
-
## (Port Text::Glob 0.08 from Perl to Ruby)
|
3
|
-
## Copyright (c) 2002, 2003, 2006, 2007 Richard Clamp. All Rights Reserved.
|
4
|
-
## Copyright (c) 2009-2011 SATOH Fumiyasu @ OSS Technology Inc.
|
5
|
-
## <http://www.osstech.co.jp/>
|
6
2
|
##
|
7
|
-
##
|
8
|
-
##
|
9
|
-
##
|
3
|
+
## Author:: SATOH Fumiyasu
|
4
|
+
## Copyright:: (c) 2007-2011 SATOH Fumiyasu @ OSS Technology, Corp.
|
5
|
+
## License:: You can redistribute it and/or modify it under the same term as Ruby.
|
6
|
+
## Date:: 2011-06-21, since 2009-07-15
|
7
|
+
##
|
8
|
+
|
9
|
+
## This is a Ruby version of Perl Text::Glob 0.08
|
10
|
+
## Copyright (c) 2002, 2003, 2006, 2007 Richard Clamp. All Rights Reserved.
|
10
11
|
|
11
12
|
require "stringglob/version"
|
12
13
|
|
14
|
+
## Generate a Regexp object from a glob(3) pattern
|
13
15
|
module StringGlob
|
16
|
+
## Ignore case
|
14
17
|
IGNORE_CASE = 1 << 0
|
15
|
-
|
16
|
-
|
18
|
+
## Leading star '*' mathces leading dot '.'
|
19
|
+
STAR_MATCHES_LEADING_DOT = 1 << 1
|
20
|
+
## Star '*' mathces slash '/'
|
21
|
+
STAR_MATCHES_SLASH = 1 << 2
|
17
22
|
|
23
|
+
## Returns a Regex object which is the equivalent of the globbing pattern.
|
18
24
|
def regexp(glob, opt = 0, code = nil)
|
19
25
|
re = regexp_string(glob, opt)
|
20
26
|
return Regexp.new("\\A#{re}\\z", nil, code)
|
21
27
|
end
|
22
28
|
module_function :regexp
|
23
29
|
|
30
|
+
## Returns a regexp String object which is the equivalent of the globbing pattern.
|
24
31
|
def regexp_string(glob, opt = 0)
|
25
32
|
re_str = ''
|
26
33
|
in_curlies = 0
|
27
34
|
escaping = false
|
28
35
|
first_byte = true
|
29
36
|
asterisk = false
|
30
|
-
strict_leading_dot = (opt &
|
31
|
-
strict_wildcard_slash = (opt &
|
37
|
+
strict_leading_dot = (opt & STAR_MATCHES_LEADING_DOT == 0)
|
38
|
+
strict_wildcard_slash = (opt & STAR_MATCHES_SLASH == 0)
|
32
39
|
glob.scan(/./m) do |glob_c|
|
33
40
|
if first_byte
|
34
41
|
if strict_leading_dot
|
data/lib/stringglob/version.rb
CHANGED
data/test/test_stringglob.rb
CHANGED
@@ -39,21 +39,21 @@ class StringGlobTest < Test::Unit::TestCase
|
|
39
39
|
## strict . rule match
|
40
40
|
assert_not_nil SG.regexp('.*.foo').match('.file.foo')
|
41
41
|
## relaxed . rule
|
42
|
-
assert_not_nil SG.regexp('*.foo', SG::
|
42
|
+
assert_not_nil SG.regexp('*.foo', SG::STAR_MATCHES_LEADING_DOT).match('.file.foo')
|
43
43
|
|
44
44
|
## strict wildcard / fail
|
45
45
|
assert_nil SG.regexp('*.fo?').match('foo/file.fob')
|
46
46
|
## strict wildcard / match
|
47
47
|
assert_not_nil SG.regexp('*/*.fo?').match('foo/file.fob')
|
48
48
|
## relaxed wildcard /
|
49
|
-
assert_not_nil SG.regexp('*.fo?', SG::
|
49
|
+
assert_not_nil SG.regexp('*.fo?', SG::STAR_MATCHES_SLASH).match('foo/file.fob')
|
50
50
|
|
51
51
|
## more strict wildcard / fail
|
52
52
|
assert_nil SG.regexp('foo/*.foo').match('foo/.foo')
|
53
53
|
## more strict wildcard / match
|
54
54
|
assert_not_nil SG.regexp('foo/.f*').match('foo/.foo')
|
55
55
|
## relaxed wildcard /
|
56
|
-
assert_not_nil SG.regexp('*.foo', SG::
|
56
|
+
assert_not_nil SG.regexp('*.foo', SG::STAR_MATCHES_SLASH).match('foo/.foo')
|
57
57
|
|
58
58
|
## properly escape +
|
59
59
|
assert_not_nil SG.regexp('f+.foo').match('f+.foo')
|
metadata
CHANGED
@@ -1,33 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: stringglob
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- SATOH Fumiyasu
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-09-26 00:00:00 Z
|
12
|
+
date: 2011-10-31 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Generate a Regexp object from a glob(3) pattern
|
22
|
-
email:
|
15
|
+
email:
|
23
16
|
- fumiyas@osstech.co.jp
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- .gitignore
|
32
22
|
- Gemfile
|
33
23
|
- Rakefile
|
@@ -35,38 +25,29 @@ files:
|
|
35
25
|
- lib/stringglob/version.rb
|
36
26
|
- stringglob.gemspec
|
37
27
|
- test/test_stringglob.rb
|
38
|
-
homepage:
|
28
|
+
homepage: ''
|
39
29
|
licenses: []
|
40
|
-
|
41
30
|
post_install_message:
|
42
31
|
rdoc_options: []
|
43
|
-
|
44
|
-
require_paths:
|
32
|
+
require_paths:
|
45
33
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
35
|
none: false
|
48
|
-
requirements:
|
49
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
|
52
|
-
|
53
|
-
- 0
|
54
|
-
version: "0"
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
41
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
64
46
|
requirements: []
|
65
|
-
|
66
47
|
rubyforge_project: stringglob
|
67
|
-
rubygems_version: 1.
|
48
|
+
rubygems_version: 1.8.10
|
68
49
|
signing_key:
|
69
50
|
specification_version: 3
|
70
51
|
summary: Generate a Regexp object from a glob(3) pattern
|
71
|
-
test_files:
|
52
|
+
test_files:
|
72
53
|
- test/test_stringglob.rb
|