[Hiki-cvs 1564] hiki/hiki @ 07f6685 [remove-ruby18] remove condition unless defined Encoding class

Zurück zum Archiv-Index

SHIBATA Hiroshi syste****@okkez*****
2013年 7月 15日 (月) 15:42:13 JST


SHIBATA Hiroshi	2013-07-15 15:42:13 +0900 (Mon, 15 Jul 2013)

  New Revision: 07f6685443bb5e72d6b2a01d1ffb8e4f4da7bd98
  https://github.com/hiki/hiki/commit/07f6685443bb5e72d6b2a01d1ffb8e4f4da7bd98

  Message:
    remove condition unless defined Encoding class

  Modified files:
    hiki.cgi
    hiki/util.rb
    test/hikifarm_test.rb
    test/repos_git_test.rb
    test/repos_hg_test.rb
    test/repos_svn_test.rb

  Modified: hiki.cgi (+4 -7)
===================================================================
--- hiki.cgi    2013-07-15 15:24:27 +0900 (d0217ad)
+++ hiki.cgi    2013-07-15 15:42:13 +0900 (0593520)
@@ -3,13 +3,10 @@
 # Copyright (C) 2002-2004 TAKEUCHI Hitoshi <hitos****@namar*****>
 
 BEGIN { $stdout.binmode }
-begin
-  # FIXME encoding can be different (eg. iso-8859-1 in
-  # hikiconf.rb.sample.en).
-  Encoding.default_external = 'utf-8'
-rescue NameError
-  $KCODE = 'e'
-end
+
+# FIXME encoding can be different (eg. iso-8859-1 in
+# hikiconf.rb.sample.en).
+Encoding.default_external = 'utf-8'
 
 begin
   if FileTest::symlink?( __FILE__ )

  Modified: hiki/util.rb (+13 -79)
===================================================================
--- hiki/util.rb    2013-07-15 15:24:27 +0900 (291b0ae)
+++ hiki/util.rb    2013-07-15 15:42:13 +0900 (cf08a1b)
@@ -56,14 +56,8 @@ class String
   end
 
   unless method_defined?(:b)
-    if Object.const_defined?(:Encoding)
-      def b
-        dup.force_encoding(Encoding::ASCII_8BIT)
-      end
-    else
-      def b
-        dup
-      end
+    def b
+      dup.force_encoding(Encoding::ASCII_8BIT)
     end
   end
 end
@@ -314,79 +308,19 @@ EOS
       end
     end
 
-    if Object.const_defined?(:Encoding)
-      # TODO remove this method in future release
-      def euc_to_utf8(str)
-        str.encode("UTF-8", "EUC-JP")
-      end
-
-      # TODO remove this method in future release
-      def utf8_to_euc(str)
-        str.encode("EUC-JP", "UTF-8")
-      end
-
-      # TODO remove this method in future release
-      def to_native(str, charset=nil)
-        str.encode(@charset, charset)
-      end
-    else
-      # TODO remove this method in future release
-      def euc_to_utf8(str)
-        if NKF.const_defined?(:UTF8)
-          return NKF.nkf('-m0 -w', str)
-        else
-          begin
-            require 'uconv'
-          rescue LoadError
-            raise "Please update to Ruby >= 1.8.2, or install either uconv or rbuconv."
-          end
-          return Uconv.euctou8(str)
-        end
-      end
+    # TODO remove this method in future release
+    def euc_to_utf8(str)
+      str.encode("UTF-8", "EUC-JP")
+    end
 
-      # TODO remove this method in future release
-      def utf8_to_euc(str)
-        if NKF.const_defined?(:UTF8)
-          return NKF.nkf('-m0 -e', str)
-        else
-          begin
-            require 'uconv'
-          rescue LoadError
-            raise "Please update to Ruby >= 1.8.2, or install either uconv or rbuconv."
-          end
-          return Uconv.u8toeuc(str)
-        end
-      end
+    # TODO remove this method in future release
+    def utf8_to_euc(str)
+      str.encode("EUC-JP", "UTF-8")
+    end
 
-      # TODO remove this method in future release
-      def to_native(str, charset=nil)
-        # XXX to_charset will be 'utf-8' in the future version
-        begin
-          Iconv.conv(@charset, charset || 'utf-8', str)
-        rescue
-          from = case charset
-                 when /^utf-8$/i
-                   'W'
-                 when /^shift_jis/i
-                   'S'
-                 when /^EUC-JP/i
-                   'E'
-                 else
-                   ''
-                 end
-          to = case @charset
-               when /^utf-8$/i
-                 'w'
-               when /\Ashift_jis\z/i
-                 's'
-               when /\Aeuc-jp\z/i
-                 'e'
-               else
-                 'e' # XXX what should we use?
-               end
-          NKF.nkf("-m0 -#{from}#{to}", str)
-        end
-      end
+    # TODO remove this method in future release
+    def to_native(str, charset=nil)
+      str.encode(@charset, charset)
     end
 
     def compare_by_line(doc1, doc2)

  Modified: test/hikifarm_test.rb (+0 -2)
===================================================================
--- test/hikifarm_test.rb    2013-07-15 15:24:27 +0900 (3354f8c)
+++ test/hikifarm_test.rb    2013-07-15 15:42:13 +0900 (8d8ef39)
@@ -1,5 +1,3 @@
-$KCODE = 'u' unless Object.const_defined?(:Encoding)
-
 require 'test_helper'
 load "#{File.dirname(__FILE__)}/../misc/hikifarm/index.cgi"
 

  Modified: test/repos_git_test.rb (+2 -6)
===================================================================
--- test/repos_git_test.rb    2013-07-15 15:24:27 +0900 (072ef29)
+++ test/repos_git_test.rb    2013-07-15 15:42:13 +0900 (aeab4b1)
@@ -139,9 +139,7 @@ class Repos_Git_Tests < Test::Unit::TestCase
     @repos.commit("FooBar")
 
     expected = ["ほげほげ", "FooBar"]
-    if Object.const_defined?(:Encoding)
-      expected = expected.map{|v| v.force_encoding("binary") }
-    end
+    expected = expected.map{|v| v.force_encoding("binary") }
 
     assert_equal(expected.sort, @repos.pages.sort)
   end
@@ -158,9 +156,7 @@ class Repos_Git_Tests < Test::Unit::TestCase
     end
 
     expected = ["ほげほげ", "FooBar"]
-    if Object.const_defined?(:Encoding)
-      expected = expected.map{|v| v.force_encoding("binary") }
-    end
+    expected = expected.map{|v| v.force_encoding("binary") }
 
     assert_equal(expected.sort, actuals.sort)
   end

  Modified: test/repos_hg_test.rb (+2 -6)
===================================================================
--- test/repos_hg_test.rb    2013-07-15 15:24:27 +0900 (214c590)
+++ test/repos_hg_test.rb    2013-07-15 15:42:13 +0900 (cac40e4)
@@ -126,9 +126,7 @@ class Repos_Hg_Tests < Test::Unit::TestCase
     @repos.commit("FooBar")
 
     expected = ["ほげほげ", "FooBar"]
-    if Object.const_defined?(:Encoding)
-      expected = expected.map{|v| v.force_encoding("binary") }
-    end
+    expected = expected.map{|v| v.force_encoding("binary") }
     assert_equal(expected.sort, @repos.pages.sort)
   end
 
@@ -144,9 +142,7 @@ class Repos_Hg_Tests < Test::Unit::TestCase
     end
 
     expected = ["ほげほげ", "FooBar"]
-    if Object.const_defined?(:Encoding)
-      expected = expected.map{|v| v.force_encoding("binary") }
-    end
+    expected = expected.map{|v| v.force_encoding("binary") }
 
     assert_equal(expected.sort, actuals.sort)
   end

  Modified: test/repos_svn_test.rb (+2 -6)
===================================================================
--- test/repos_svn_test.rb    2013-07-15 15:24:27 +0900 (27219c3)
+++ test/repos_svn_test.rb    2013-07-15 15:42:13 +0900 (48b14b3)
@@ -125,9 +125,7 @@ class Repos_SVN_Tests < Test::Unit::TestCase
     @repos.commit("FooBar")
 
     expected = ["ほげほげ", "FooBar"]
-    if Object.const_defined?(:Encoding)
-      expected = expected.map{|v| v.force_encoding("binary") }
-    end
+    expected = expected.map{|v| v.force_encoding("binary") }
     assert_equal(expected.sort, @repos.pages.sort)
   end
 
@@ -142,9 +140,7 @@ class Repos_SVN_Tests < Test::Unit::TestCase
       actuals << page
     end
     expected = ["ほげほげ", "FooBar"]
-    if Object.const_defined?(:Encoding)
-      expected = expected.map{|v| v.force_encoding("binary") }
-    end
+    expected = expected.map{|v| v.force_encoding("binary") }
     assert_equal(expected.sort, actuals.sort)
   end
 




Hiki-cvs メーリングリストの案内
Zurück zum Archiv-Index