Skip to content

Commit

Permalink
pkg-0.0.2追加
Browse files Browse the repository at this point in the history
  • Loading branch information
masui committed Apr 30, 2012
1 parent e03848b commit 3e2edd6
Show file tree
Hide file tree
Showing 20 changed files with 832 additions and 0 deletions.
Binary file added pkg/re_expand-0.0.2.gem
Binary file not shown.
Empty file added pkg/re_expand-0.0.2/.gemtest
Empty file.
4 changes: 4 additions & 0 deletions pkg/re_expand-0.0.2/History.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== 0.0.1 2012-04-30

* 1 major enhancement:
* Initial release
20 changes: 20 additions & 0 deletions pkg/re_expand-0.0.2/Manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
History.txt
Manifest.txt
PostInstall.txt
README.rdoc
Rakefile
lib/re_expand.rb
lib/Generator.rb
lib/Node.rb
lib/Asearch.rb
lib/Scanner.rb
script/console
script/destroy
script/generate
test/test_helper.rb
test/test_re_expand.rb
test/test_asearch.rb
test/test_generator.rb
test/test_re_expand.rb
test/test_scanner.rb

7 changes: 7 additions & 0 deletions pkg/re_expand-0.0.2/PostInstall.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

For more information on re_expand, see http://re_expand.rubyforge.org

NOTE: Change this information in PostInstall.txt
You can also delete it if you don't want it.


43 changes: 43 additions & 0 deletions pkg/re_expand-0.0.2/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
= re_expand

* http://github.com/masui/expand-ruby

== DESCRIPTION:

Generates all the text strings which match the given regexp.
If a filter pattern is given, the output is filtered by the pattern.

== SYNOPSIS:

require 're_expand'
"test (a|b|c)".expand { |s|
puts s
}
# "test a", "test b", ...
"(a|b)(1|2)".expand
# => ['a1', 'a2', 'b1', 'b2']

== LICENSE:

(The MIT License)

Copyright (c) 2012 Toshiyuki Masui

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 changes: 26 additions & 0 deletions pkg/re_expand-0.0.2/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rubygems'
gem 'hoe', '>= 2.1.0'
require 'hoe'
require 'fileutils'
require './lib/re_expand'

Hoe.plugin :newgem
# Hoe.plugin :website
# Hoe.plugin :cucumberfeatures

# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)
$hoe = Hoe.spec 're_expand' do
self.developer 'Toshiyuki Masui', 'masui@pitecan.com'
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
self.rubyforge_name = self.name # TODO this is default value
# self.extra_deps = [['activesupport','>= 2.0.2']]

end

require 'newgem/tasks'
Dir['tasks/**/*.rake'].each { |t| load t }

# TODO - want other tests/tasks run by default? Add them to the list
# remove_task :default
# task :default => [:spec, :features]
105 changes: 105 additions & 0 deletions pkg/re_expand-0.0.2/lib/Asearch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-
# Asearch.rb
#
# Created by Toshiyuki Masui on 11/04/16.
# Copyright 2011 Pitecan Systems. All rights reserved.
#
# a = Asearch.new('abcde')
# a.match('abcde') => true
# a.match('abXcde',1) => true
#
# a = Asearch.new('abcde')
# initstate = a.initstate
# laststate = a.state(initstate,'abcde')
# laststate[0] & a.acceptpat => non-zero value
#

class Asearch
INITPAT = 0x80000000
MAXCHAR = 0x100

def isupper(c)
c >= 0x41 && c <= 0x5a
end

def islower(c)
c >= 0x61 && c <= 0x7a
end

def tolower(c)
c + 0x20
end

def toupper(c)
c - 0x20
end

def initialize(pat)
@shiftpat = []
@epsilon = 0
@acceptpat = 0
mask = INITPAT
(0...MAXCHAR).each { |c|
@shiftpat[c] = 0
}
chars = pat.unpack("C*")
chars.each { |c|
if c == 0x20 then
@epsilon |= mask
else
@shiftpat[c] |= mask
@shiftpat[toupper(c)] |= mask if islower(c)
@shiftpat[tolower(c)] |= mask if isupper(c)
mask >>= 1
end
}
@acceptpat = mask
end

attr_reader :acceptpat

def bin(val)
s = "00000000000000000000000000000000000000000" + sprintf("%b",val)
s[-32,100]
end

#
# 状態stateからテキストstrを認識したときの状態変化
#
def state(state=nil,str='')
if state.nil? then
state = initstate
end
i0 = state[0]
i1 = state[1]
i2 = state[2]
i3 = state[3]
chars = str.unpack("C*")
chars.each { |c|
mask = @shiftpat[c]
i3 = (i3 & @epsilon) | ((i3 & mask) >> 1) | (i2 >> 1) | i2
i2 = (i2 & @epsilon) | ((i2 & mask) >> 1) | (i1 >> 1) | i1
i1 = (i1 & @epsilon) | ((i1 & mask) >> 1) | (i0 >> 1) | i0
i0 = (i0 & @epsilon) | ((i0 & mask) >> 1)
i1 |= (i0 >> 1)
i2 |= (i1 >> 1)
i3 |= (i2 >> 1)
}
#puts bin(i3)
#puts bin(i2)
#puts bin(i1)
#puts bin(i0)
#puts bin(acceptpat | INITPAT)
[i0, i1, i2, i3]
end

def initstate
[INITPAT, 0, 0, 0]
end

def match(str, ambig=0)
s = state(initstate,str)
s[ambig] & acceptpat != 0
end
end

Loading

0 comments on commit 3e2edd6

Please sign in to comment.