mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rexml/encoding.rb (encoding=): give priority to particular
conversion to iconv. [ruby-core:06520] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d0e78ab05d
commit
c9e950b7b8
5 changed files with 62 additions and 33 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Fri Dec 9 23:31:02 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/rexml/encoding.rb (encoding=): give priority to particular
|
||||||
|
conversion to iconv. [ruby-core:06520]
|
||||||
|
|
||||||
Thu Dec 8 02:07:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Dec 8 02:07:19 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (umethod_bind): adjust invoking class for module method.
|
* eval.c (umethod_bind): adjust invoking class for module method.
|
||||||
|
|
|
@ -25,28 +25,22 @@ module REXML
|
||||||
begin
|
begin
|
||||||
$VERBOSE = false
|
$VERBOSE = false
|
||||||
return if defined? @encoding and enc == @encoding
|
return if defined? @encoding and enc == @encoding
|
||||||
if enc and enc != UTF_8
|
if enc
|
||||||
@encoding = enc.upcase
|
raise ArgumentError, "Bad encoding name #{enc}" unless /\A[\w-]+\z/n =~ enc
|
||||||
|
@encoding = enc.upcase.untaint
|
||||||
|
else
|
||||||
|
@encoding = UTF_8
|
||||||
|
end
|
||||||
|
err = nil
|
||||||
|
[@encoding, "ICONV"].each do |enc|
|
||||||
begin
|
begin
|
||||||
require 'rexml/encodings/ICONV.rb'
|
require File.join("rexml", "encodings", "#{enc}.rb")
|
||||||
Encoding.apply(self, "ICONV")
|
return Encoding.apply(self, enc)
|
||||||
rescue LoadError, Exception => err
|
rescue LoadError, Exception => err
|
||||||
raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/
|
|
||||||
@encoding.untaint
|
|
||||||
enc_file = File.join( "rexml", "encodings", "#@encoding.rb" )
|
|
||||||
begin
|
|
||||||
require enc_file
|
|
||||||
Encoding.apply(self, @encoding)
|
|
||||||
rescue LoadError
|
|
||||||
puts $!.message
|
|
||||||
raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv."
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
puts err.message
|
||||||
@encoding = UTF_8
|
raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv."
|
||||||
require 'rexml/encodings/UTF-8.rb'
|
|
||||||
Encoding.apply(self, @encoding)
|
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
$VERBOSE = old_verbosity
|
$VERBOSE = old_verbosity
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,28 @@
|
||||||
require 'uconv'
|
|
||||||
|
|
||||||
module REXML
|
module REXML
|
||||||
module Encoding
|
module Encoding
|
||||||
def decode_eucjp(str)
|
begin
|
||||||
Uconv::euctou8(str)
|
require 'uconv'
|
||||||
end
|
|
||||||
|
|
||||||
def encode_eucjp content
|
def decode_eucjp(str)
|
||||||
Uconv::u8toeuc(content)
|
Uconv::euctou8(str)
|
||||||
|
end
|
||||||
|
|
||||||
|
def encode_eucjp content
|
||||||
|
Uconv::u8toeuc(content)
|
||||||
|
end
|
||||||
|
rescue LoadError
|
||||||
|
require 'nkf'
|
||||||
|
|
||||||
|
EUCTOU8 = '-Ewm0'
|
||||||
|
U8TOEUC = '-Wem0'
|
||||||
|
|
||||||
|
def decode_eucjp(str)
|
||||||
|
NKF.nkf(EUCTOU8, str)
|
||||||
|
end
|
||||||
|
|
||||||
|
def encode_eucjp content
|
||||||
|
NKF.nkf(U8TOEUC, content)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
register("EUC-JP") do |obj|
|
register("EUC-JP") do |obj|
|
||||||
|
|
|
@ -1,13 +1,28 @@
|
||||||
require 'uconv'
|
|
||||||
|
|
||||||
module REXML
|
module REXML
|
||||||
module Encoding
|
module Encoding
|
||||||
def decode_sjis content
|
begin
|
||||||
Uconv::sjistou8(content)
|
require 'uconv'
|
||||||
end
|
|
||||||
|
|
||||||
def encode_sjis(str)
|
def decode_sjis content
|
||||||
Uconv::u8tosjis(str)
|
Uconv::sjistou8(content)
|
||||||
|
end
|
||||||
|
|
||||||
|
def encode_sjis(str)
|
||||||
|
Uconv::u8tosjis(str)
|
||||||
|
end
|
||||||
|
rescue LoadError
|
||||||
|
require 'nkf'
|
||||||
|
|
||||||
|
SJISTOU8 = '-Swm0'
|
||||||
|
U8TOSJIS = '-Wsm0'
|
||||||
|
|
||||||
|
def decode_sjis(str)
|
||||||
|
NKF.nkf(SJISTOU8, str)
|
||||||
|
end
|
||||||
|
|
||||||
|
def encode_sjis content
|
||||||
|
NKF.nkf(U8TOSJIS, content)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
b = proc do |obj|
|
b = proc do |obj|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
load 'rexml/encodings/SHIFT-JIS.rb'
|
require 'rexml/encodings/SHIFT-JIS'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue