milkode 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.6.2
@@ -479,25 +479,37 @@ EOF
479
479
  private :searchData
480
480
 
481
481
  def file2data(file)
482
+ FindGrep::file2lines(file, @option.kcode)
483
+ end
484
+ private :file2data
485
+
486
+ def self.file2lines(file, kcode)
482
487
  data = file.read
483
488
 
484
489
  unless Milkode::Util::ruby19?
485
- if (@option.kcode != Kconv::NOCONV)
490
+ if (kcode != Kconv::NOCONV)
486
491
  file_kcode = Kconv::guess(data)
487
492
 
488
- if (file_kcode != @option.kcode)
489
- # puts "encode!! #{fpath} : #{@option.kcode} <- #{file_kcode}"
490
- data = data.kconv(@option.kcode, file_kcode)
493
+ if (file_kcode != kcode)
494
+ # puts "encode!! #{fpath} : #{kcode} <- #{file_kcode}"
495
+ data = data.kconv(kcode, file_kcode)
491
496
  end
492
497
  end
493
498
  else
494
- data = data.kconv(@option.kcode)
499
+ # @memo ファイルエンコーディングに相違が起きている可能性があるため対策
500
+ # 本当はファイルを開く時にエンコーディングを指定するのが正しい
501
+
502
+ # 方法1 : 強制的にバイナリ化
503
+ # data.force_encoding("Binary")
504
+ # data = data.kconv(kcode)
505
+
506
+ # 方法2 : 入力エンコーディングを強制的に指定
507
+ data = data.kconv(kcode, Kconv::guess(data))
495
508
  end
496
509
 
497
- data = data.split("\n");
510
+ data = data.split($/)
498
511
  end
499
- private :file2data
500
-
512
+
501
513
  def match?(line)
502
514
  match_datas = []
503
515
  @patternRegexps.each {|v| match_datas << v.match(line)}
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{milkode}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ongaeshi"]
12
- s.date = %q{2012-04-05}
12
+ s.date = %q{2012-04-17}
13
13
  s.description = %q{Line based local source code search engine & grep-command & web-app.}
14
14
  s.email = %q{ongaeshi0621@gmail.com}
15
15
  s.executables = ["gmilk", "milk"]
@@ -107,6 +107,7 @@ Gem::Specification.new do |s|
107
107
  "test/test_database.rb",
108
108
  "test/test_dbdir.rb",
109
109
  "test/test_dir.rb",
110
+ "test/test_findgrep.rb",
110
111
  "test/test_gren_util.rb",
111
112
  "test/test_helper.rb",
112
113
  "test/test_ignore_checker.rb",
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2012/04/15
7
+
8
+ require 'test_helper'
9
+ require 'file_assert'
10
+ require 'milkode/findgrep/findgrep'
11
+
12
+ module FindGrep
13
+ class TestFindGrep < Test::Unit::TestCase
14
+ def test_basic
15
+
16
+ # 外部エンコーディング
17
+ # p Encoding.default_external
18
+ # p $stdout.external_encoding
19
+ # 内部エンコーディング
20
+ # p Encoding.default_internal
21
+ # p $stdout.internal_encoding
22
+
23
+ # Kconv::NOCONV
24
+ # Kconv::SJIS
25
+ # Kconv::UTF8
26
+
27
+ Dir.chdir(File.join(File.dirname(__FILE__))) do
28
+ File.open('data/.gitignore') do |f|
29
+ assert_equal '#*.swp', FindGrep::file2lines(f, Kconv::UTF8)[-1]
30
+ end
31
+
32
+ File.open('data/a_project/cdstk.rb') do |f|
33
+ # assert_equal 'end', FindGrep::file2lines(f, Kconv::UTF8)[-1]
34
+ assert_equal 'end', FindGrep::file2lines(f, Kconv::SJIS)[-1]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - ongaeshi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-05 00:00:00 +09:00
18
+ date: 2012-04-17 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -324,6 +324,7 @@ files:
324
324
  - test/test_database.rb
325
325
  - test/test_dbdir.rb
326
326
  - test/test_dir.rb
327
+ - test/test_findgrep.rb
327
328
  - test/test_gren_util.rb
328
329
  - test/test_helper.rb
329
330
  - test/test_ignore_checker.rb