re_expand 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -6,14 +6,12 @@ Rakefile
6
6
  lib/re_expand.rb
7
7
  lib/Generator.rb
8
8
  lib/Node.rb
9
- lib/Asearch.rb
10
9
  lib/Scanner.rb
11
10
  script/console
12
11
  script/destroy
13
12
  script/generate
14
13
  test/test_helper.rb
15
14
  test/test_re_expand.rb
16
- test/test_asearch.rb
17
15
  test/test_generator.rb
18
16
  test/test_re_expand.rb
19
17
  test/test_scanner.rb
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ $hoe = Hoe.spec 're_expand' do
14
14
  self.developer 'Toshiyuki Masui', 'masui@pitecan.com'
15
15
  self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = [['asearch','>= 0.0.1']]
17
18
  # self.extra_deps = [['activesupport','>= 2.0.2']]
18
19
 
19
20
  end
data/lib/Generator.rb CHANGED
@@ -15,7 +15,8 @@
15
15
 
16
16
  require 'Scanner'
17
17
  require 'Node'
18
- require 'Asearch'
18
+
19
+ require 'asearch'
19
20
 
20
21
  module ReExpand
21
22
  class GenNode
data/lib/re_expand.rb CHANGED
@@ -3,14 +3,15 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
4
4
 
5
5
  module ReExpand
6
- VERSION = '0.0.4'
6
+ VERSION = '0.0.6'
7
7
  end
8
8
 
9
9
  require 'Generator'
10
10
  require 'Node'
11
- require 'Asearch'
12
11
  require 'Scanner'
13
12
 
13
+ # require 'asearch'
14
+
14
15
  class String
15
16
  # ExpandHelp用のライブラリを利用
16
17
  def expand(filterpat=' ')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: re_expand
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Toshiyuki Masui
@@ -15,12 +15,28 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-01 00:00:00 Z
18
+ date: 2012-05-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rdoc
21
+ name: asearch
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 29
29
+ segments:
30
+ - 0
31
+ - 0
32
+ - 1
33
+ version: 0.0.1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
24
40
  none: false
25
41
  requirements:
26
42
  - - ~>
@@ -31,11 +47,11 @@ dependencies:
31
47
  - 10
32
48
  version: "3.10"
33
49
  type: :development
34
- version_requirements: *id001
50
+ version_requirements: *id002
35
51
  - !ruby/object:Gem::Dependency
36
52
  name: newgem
37
53
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
54
+ requirement: &id003 !ruby/object:Gem::Requirement
39
55
  none: false
40
56
  requirements:
41
57
  - - ">="
@@ -47,11 +63,11 @@ dependencies:
47
63
  - 3
48
64
  version: 1.5.3
49
65
  type: :development
50
- version_requirements: *id002
66
+ version_requirements: *id003
51
67
  - !ruby/object:Gem::Dependency
52
68
  name: hoe
53
69
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
55
71
  none: false
56
72
  requirements:
57
73
  - - ~>
@@ -62,7 +78,7 @@ dependencies:
62
78
  - 12
63
79
  version: "2.12"
64
80
  type: :development
65
- version_requirements: *id003
81
+ version_requirements: *id004
66
82
  description: |-
67
83
  Generates all the text strings which match the given regexp.
68
84
  If a filter pattern is given, the output is filtered by the pattern.
@@ -85,14 +101,12 @@ files:
85
101
  - lib/re_expand.rb
86
102
  - lib/Generator.rb
87
103
  - lib/Node.rb
88
- - lib/Asearch.rb
89
104
  - lib/Scanner.rb
90
105
  - script/console
91
106
  - script/destroy
92
107
  - script/generate
93
108
  - test/test_helper.rb
94
109
  - test/test_re_expand.rb
95
- - test/test_asearch.rb
96
110
  - test/test_generator.rb
97
111
  - test/test_scanner.rb
98
112
  - .gemtest
@@ -131,7 +145,6 @@ signing_key:
131
145
  specification_version: 3
132
146
  summary: Generates all the text strings which match the given regexp
133
147
  test_files:
134
- - test/test_asearch.rb
135
148
  - test/test_generator.rb
136
149
  - test/test_helper.rb
137
150
  - test/test_re_expand.rb
data/lib/Asearch.rb DELETED
@@ -1,105 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Asearch.rb
3
- #
4
- # Created by Toshiyuki Masui on 11/04/16.
5
- # Copyright 2011 Pitecan Systems. All rights reserved.
6
- #
7
- # a = Asearch.new('abcde')
8
- # a.match('abcde') => true
9
- # a.match('abXcde',1) => true
10
- #
11
- # a = Asearch.new('abcde')
12
- # initstate = a.initstate
13
- # laststate = a.state(initstate,'abcde')
14
- # laststate[0] & a.acceptpat => non-zero value
15
- #
16
-
17
- class Asearch
18
- INITPAT = 0x80000000
19
- MAXCHAR = 0x100
20
-
21
- def isupper(c)
22
- c >= 0x41 && c <= 0x5a
23
- end
24
-
25
- def islower(c)
26
- c >= 0x61 && c <= 0x7a
27
- end
28
-
29
- def tolower(c)
30
- c + 0x20
31
- end
32
-
33
- def toupper(c)
34
- c - 0x20
35
- end
36
-
37
- def initialize(pat)
38
- @shiftpat = []
39
- @epsilon = 0
40
- @acceptpat = 0
41
- mask = INITPAT
42
- (0...MAXCHAR).each { |c|
43
- @shiftpat[c] = 0
44
- }
45
- chars = pat.unpack("C*")
46
- chars.each { |c|
47
- if c == 0x20 then
48
- @epsilon |= mask
49
- else
50
- @shiftpat[c] |= mask
51
- @shiftpat[toupper(c)] |= mask if islower(c)
52
- @shiftpat[tolower(c)] |= mask if isupper(c)
53
- mask >>= 1
54
- end
55
- }
56
- @acceptpat = mask
57
- end
58
-
59
- attr_reader :acceptpat
60
-
61
- def bin(val)
62
- s = "00000000000000000000000000000000000000000" + sprintf("%b",val)
63
- s[-32,100]
64
- end
65
-
66
- #
67
- # 状態stateからテキストstrを認識したときの状態変化
68
- #
69
- def state(state=nil,str='')
70
- if state.nil? then
71
- state = initstate
72
- end
73
- i0 = state[0]
74
- i1 = state[1]
75
- i2 = state[2]
76
- i3 = state[3]
77
- chars = str.unpack("C*")
78
- chars.each { |c|
79
- mask = @shiftpat[c]
80
- i3 = (i3 & @epsilon) | ((i3 & mask) >> 1) | (i2 >> 1) | i2
81
- i2 = (i2 & @epsilon) | ((i2 & mask) >> 1) | (i1 >> 1) | i1
82
- i1 = (i1 & @epsilon) | ((i1 & mask) >> 1) | (i0 >> 1) | i0
83
- i0 = (i0 & @epsilon) | ((i0 & mask) >> 1)
84
- i1 |= (i0 >> 1)
85
- i2 |= (i1 >> 1)
86
- i3 |= (i2 >> 1)
87
- }
88
- #puts bin(i3)
89
- #puts bin(i2)
90
- #puts bin(i1)
91
- #puts bin(i0)
92
- #puts bin(acceptpat | INITPAT)
93
- [i0, i1, i2, i3]
94
- end
95
-
96
- def initstate
97
- [INITPAT, 0, 0, 0]
98
- end
99
-
100
- def match(str, ambig=0)
101
- s = state(initstate,str)
102
- s[ambig] & acceptpat != 0
103
- end
104
- end
105
-
data/test/test_asearch.rb DELETED
@@ -1,105 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'Asearch'
4
-
5
- class AsearchTest < Test::Unit::TestCase
6
- def setup
7
- end
8
-
9
- def teardown
10
- end
11
-
12
- def test_init
13
- a = Asearch.new('abc')
14
- state = a.initstate
15
- assert state[0] != 0
16
- assert state[1] == 0
17
- assert state[2] == 0
18
- end
19
-
20
- def test_match
21
- #
22
- # 状態を利用せず普通にマッチングを行なうメソッド
23
- #
24
- a = Asearch.new('abcde')
25
- assert a.match('abcde')
26
- assert a.match('abcde',1)
27
- assert !a.match('abcd')
28
- assert a.match('abcd',1)
29
- end
30
-
31
- def test_state
32
- #
33
- # "abcde"にマッチするかテスト
34
- #
35
- a = Asearch.new('abcde')
36
- initstate = a.initstate
37
- laststate = a.state(initstate,'abcde')
38
- assert((laststate[0] & a.acceptpat) != 0)
39
- laststate = a.state(initstate,'abcdf') # 1文字置換
40
- assert((laststate[0] & a.acceptpat) == 0)
41
- assert((laststate[1] & a.acceptpat) != 0)
42
- assert((laststate[2] & a.acceptpat) != 0)
43
- laststate = a.state(initstate,'abde') # 1文字欠損
44
- assert((laststate[0] & a.acceptpat) == 0)
45
- assert((laststate[1] & a.acceptpat) != 0)
46
- assert((laststate[2] & a.acceptpat) != 0)
47
- laststate = a.state(initstate,'abcfg') # 2文字置換
48
- assert((laststate[0] & a.acceptpat) == 0)
49
- assert((laststate[1] & a.acceptpat) == 0)
50
- assert((laststate[2] & a.acceptpat) != 0)
51
- laststate = a.state(initstate,'abe') # 2文字欠損
52
- assert((laststate[0] & a.acceptpat) == 0)
53
- assert((laststate[1] & a.acceptpat) == 0)
54
- assert((laststate[2] & a.acceptpat) != 0)
55
- laststate = a.state(initstate,'axbcde') # 1文字追加
56
- assert((laststate[0] & a.acceptpat) == 0)
57
- assert((laststate[1] & a.acceptpat) != 0)
58
- assert((laststate[2] & a.acceptpat) != 0)
59
- laststate = a.state(initstate,'axbcyde') # 2文字追加
60
- assert((laststate[0] & a.acceptpat) == 0)
61
- assert((laststate[1] & a.acceptpat) == 0)
62
- assert((laststate[2] & a.acceptpat) != 0)
63
- laststate = a.state(initstate,'ABCDF') # 大文字
64
- assert((laststate[0] & a.acceptpat) == 0)
65
- assert((laststate[1] & a.acceptpat) != 0)
66
- assert((laststate[2] & a.acceptpat) != 0)
67
-
68
- #
69
- # ワイルドカード
70
- #
71
- a = Asearch.new(' abc def')
72
- initstate = a.initstate
73
- laststate = a.state(initstate,'abcdef')
74
- assert((laststate[0] & a.acceptpat) != 0)
75
- initstate = a.initstate
76
- laststate = a.state(initstate,'abcXXXXdef')
77
- assert((laststate[0] & a.acceptpat) != 0)
78
- initstate = a.initstate
79
- laststate = a.state(initstate,'abcXXXXYYY')
80
- assert((laststate[0] & a.acceptpat) == 0)
81
- initstate = a.initstate
82
- laststate = a.state(initstate,'abcXXXXde')
83
- assert((laststate[0] & a.acceptpat) == 0)
84
- assert((laststate[1] & a.acceptpat) != 0)
85
- assert((laststate[2] & a.acceptpat) != 0)
86
- initstate = a.initstate
87
- laststate = a.state(initstate,'ZZZZZabcdef')
88
- assert((laststate[0] & a.acceptpat) != 0)
89
-
90
- #
91
- # 漢字
92
- #
93
- a = Asearch.new('漢字文字列')
94
- initstate = a.initstate
95
- laststate = a.state(initstate,'漢字文字列')
96
- assert((laststate[0] & a.acceptpat) != 0)
97
- laststate = a.state(initstate,'漢字文字')
98
- assert((laststate[0] & a.acceptpat) == 0)
99
- laststate = a.state(initstate,'漢字!文字列')
100
- assert((laststate[0] & a.acceptpat) == 0)
101
- assert((laststate[1] & a.acceptpat) != 0)
102
- end
103
-
104
- end
105
-