gren 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.ja.md +6 -0
- data/HISTORY.md +6 -0
- data/gren.gemspec +1 -1
- data/lib/gren/common/grenfiletest.rb +1 -1
- data/lib/gren/common/util.rb +5 -1
- data/lib/gren/findgrep/findgrep.rb +38 -43
- data/lib/gren/version.rb +1 -1
- metadata +5 -5
data/HISTORY.ja.md
CHANGED
data/HISTORY.md
CHANGED
data/gren.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["ongaeshi0621@gmail.com"]
|
11
11
|
gem.description = %q{gren is a next grep tool.}
|
12
12
|
gem.summary = %q{gren is a next grep tool. The basis is find+grep.}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "http://gren.ongaeshi.me"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
module GrenFileTest
|
4
|
-
IGNORE_FILE = /(\A#.*#\Z)|(~\Z)|(\A\.#)|(\.d\Z)|(\.map\Z)|(\.MAP\Z)/
|
4
|
+
IGNORE_FILE = /(\A#.*#\Z)|(~\Z)|(\A\.#)|(\.d\Z)|(\.map\Z)|(\.MAP\Z)|(\.xbm\Z)|(\.ppm\Z)|(\.ai\Z)|(\.png\Z)|(\.webarchive\Z)/
|
5
5
|
IGNORE_DIR = /(\A\.svn\Z)|(\A\.git\Z)|(\ACVS\Z)/
|
6
6
|
|
7
7
|
def self.ignoreDir?(fpath)
|
data/lib/gren/common/util.rb
CHANGED
@@ -93,12 +93,16 @@ module Gren
|
|
93
93
|
|
94
94
|
# StringIO patch
|
95
95
|
def pipe?(io)
|
96
|
-
io.instance_of?(IO) && File.pipe?(io)
|
96
|
+
!Platform.windows_os? && io.instance_of?(IO) && File.pipe?(io)
|
97
97
|
end
|
98
98
|
|
99
99
|
def downcase?(str)
|
100
100
|
str == str.downcase
|
101
101
|
end
|
102
102
|
|
103
|
+
def ruby19?
|
104
|
+
RUBY_VERSION >= '1.9.0'
|
105
|
+
end
|
106
|
+
|
103
107
|
end
|
104
108
|
end
|
@@ -69,7 +69,7 @@ module FindGrep
|
|
69
69
|
strs.each do |v|
|
70
70
|
option = 0
|
71
71
|
option |= Regexp::IGNORECASE if (@option.ignoreCase || (!@option.caseSensitive && Util::downcase?(v)))
|
72
|
-
regs << Regexp.new(v, option)
|
72
|
+
regs << Regexp.new(FindGrep::convline(v, @option.kcode), option)
|
73
73
|
end
|
74
74
|
|
75
75
|
regs
|
@@ -79,7 +79,11 @@ module FindGrep
|
|
79
79
|
unless Util.pipe?($stdin)
|
80
80
|
searchFromDir(stdout, @option.directory, 0)
|
81
81
|
else
|
82
|
-
|
82
|
+
begin
|
83
|
+
searchData(stdout, FindGrep::convline($stdin.read, @option.kcode).split($/), nil)
|
84
|
+
rescue ArgumentError
|
85
|
+
stdout.puts "invalid byte sequence : $stdin"
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
@result.time_stop
|
@@ -109,37 +113,7 @@ module FindGrep
|
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
112
|
-
|
113
|
-
sub = nil
|
114
|
-
|
115
|
-
list.each do |word|
|
116
|
-
e = key =~ word
|
117
|
-
if sub.nil?
|
118
|
-
sub = e
|
119
|
-
else
|
120
|
-
sub &= e
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
sub
|
125
|
-
end
|
126
|
-
|
127
|
-
def suffix_expression(record)
|
128
|
-
sub = nil
|
129
|
-
|
130
|
-
@option.suffixs.each do |word|
|
131
|
-
e = record.suffix =~ word
|
132
|
-
if sub.nil?
|
133
|
-
sub = e
|
134
|
-
else
|
135
|
-
sub |= e
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
sub
|
140
|
-
end
|
141
|
-
private :suffix_expression
|
142
|
-
|
116
|
+
private
|
143
117
|
|
144
118
|
def searchFromDir(stdout, dir, depth)
|
145
119
|
if (@option.depth != -1 && depth > @option.depth)
|
@@ -229,7 +203,11 @@ module FindGrep
|
|
229
203
|
@result.search_files << fpath_disp if (@option.debugMode)
|
230
204
|
|
231
205
|
open(fpath, "r") do |file|
|
232
|
-
|
206
|
+
begin
|
207
|
+
searchData(stdout, file2data(file), fpath_disp)
|
208
|
+
rescue ArgumentError
|
209
|
+
stdout.puts "invalid byte sequence : #{fpath}"
|
210
|
+
end
|
233
211
|
end
|
234
212
|
end
|
235
213
|
private :searchFile
|
@@ -264,20 +242,37 @@ module FindGrep
|
|
264
242
|
private :searchData
|
265
243
|
|
266
244
|
def file2data(file)
|
267
|
-
|
245
|
+
FindGrep::file2lines(file, @option.kcode)
|
246
|
+
end
|
247
|
+
|
248
|
+
def self.file2lines(file, kcode)
|
249
|
+
convline(file.read, kcode).split($/)
|
250
|
+
end
|
268
251
|
|
269
|
-
|
270
|
-
|
252
|
+
def self.convline(line, kcode)
|
253
|
+
if Util::ruby19?
|
254
|
+
# @memo ファイルエンコーディングに相違が起きている可能性があるため対策
|
255
|
+
# 本当はファイルを開く時にエンコーディングを指定するのが正しい
|
271
256
|
|
272
|
-
|
273
|
-
#
|
274
|
-
|
257
|
+
# 方法1 : 強制的にバイナリ化
|
258
|
+
# line.force_encoding("Binary")
|
259
|
+
# line = line.kconv(kcode)
|
260
|
+
|
261
|
+
# 方法2 : 入力エンコーディングを強制的に指定
|
262
|
+
line.kconv(kcode, Kconv::guess(line))
|
263
|
+
else
|
264
|
+
if (kcode != Kconv::NOCONV)
|
265
|
+
file_kcode = Kconv::guess(line)
|
266
|
+
|
267
|
+
if (file_kcode != kcode)
|
268
|
+
# puts "encode!! #{fpath} : #{kcode} <- #{file_kcode}"
|
269
|
+
line = line.kconv(kcode, file_kcode)
|
275
270
|
end
|
276
271
|
end
|
277
|
-
|
278
|
-
|
272
|
+
|
273
|
+
line
|
274
|
+
end
|
279
275
|
end
|
280
|
-
private :file2data
|
281
276
|
|
282
277
|
def match?(line)
|
283
278
|
match_datas = []
|
data/lib/gren/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gren
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: termcolor
|
16
|
-
requirement: &
|
16
|
+
requirement: &2157299740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2157299740
|
25
25
|
description: gren is a next grep tool.
|
26
26
|
email:
|
27
27
|
- ongaeshi0621@gmail.com
|
@@ -60,7 +60,7 @@ files:
|
|
60
60
|
- test/test_gren_util.rb
|
61
61
|
- test/test_helper.rb
|
62
62
|
- test/test_string_snip.rb
|
63
|
-
homepage:
|
63
|
+
homepage: http://gren.ongaeshi.me
|
64
64
|
licenses: []
|
65
65
|
post_install_message:
|
66
66
|
rdoc_options: []
|