OSDN Git Service

Fixed an encoding issue for mk_rate 20140726
authorDaigo Moriwaki <daigo@debian.org>
Sat, 26 Jul 2014 06:58:40 +0000 (15:58 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 26 Jul 2014 07:33:18 +0000 (16:33 +0900)
mk_rate
utils/csa-filter.rb

diff --git a/mk_rate b/mk_rate
index b540963..6090225 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
@@ -679,7 +679,7 @@ def parse(line)
   end
 
   if state == "abnormal"
-    csa = CsaFileReader.new file
+    csa = CsaFileReader.new(file, "EUC-JP")
     if $options["abnormal-threshold"] == 0 || csa.ply <= $options["abnormal-threshold"]
       return
     end
index 0a863fe..72a8662 100755 (executable)
@@ -44,21 +44,21 @@ class CsaFileReader
   attr_reader :start_time, :end_time
   attr_reader :ply
 
-  def initialize(file_name)
+  def initialize(file_name, encoding="Shift_JIS:EUC-JP")
     @file_name = file_name
+    @encoding = encoding
     @ply = 0
     grep
   end
 
   def grep
-    @str = File.open(@file_name, "r:Shift_JIS:EUC-JP").read
+    @str = File.open(@file_name, "r:#{@encoding}").read
 
 
     if /^N\+(.*)$/ =~ @str then @black_name = $1.strip end
     if /^N\-(.*)$/ =~ @str then @white_name = $1.strip end
     if /^'summary:(.*)$/ =~ @str
       @state, p1, p2 = $1.split(":").map {|a| a.strip}    
-      return if @state == "abnormal"
       p1_name, p1_mark = p1.split(" ")
       p2_name, p2_mark = p2.split(" ")
       if p1_name == @black_name