From: "杉原 透修" Date: 2005-10-19T09:00:33+09:00 Subject: [ruby-list:41337] Re: rexmlの文字エンコードライブラリの変更 $BCfEDMM(B $B$42sEz$"$j$,$H$&$4$6$$$^$9!#(B $B65$($F$$$?$@$$$?2<5-%3!<%I$rDI5-$9$k$3$H$G(B Uconv$B$G$N%(%s%3!<%I$,M-8z$K$J$C$F$$$k$h$&$G$9!#(B -------------------------------------------- require "rexml/document" require "rexml/encodings/ICONV" module REXML::Encoding @encoding_methods.delete("ICONV") end -------------------------------------------- $B$b$H$b$H(BIconv$B$NMxMQ$OA[Dj$7$F$$$J$+$C$?$?$a(B $B$3$NJ}K!$G$J$s$H$+$J$k$+$H;W$$$^$9!#(B $B$"$j$,$H$&$4$6$$$^$7$?!#(B > $B$J$+$@$G$9!#(B > > At Tue, 18 Oct 2005 09:58:43 +0900, > $B?y86!!F)=$(B wrote in [ruby-list:41325]: > > rexml$B$K!V-!!WEy$NFC > $B0J2<$N%3!<%I$G:F8=$7$^$9!#(B > > iconv$B$r0l@Z;H$o$J$$$h$&$K$9$k$N$G$h$1$l$P!"JQ49%a%=%C%IEPO?$N%F!<(B > $B%V%k$+$i>C$7$F$7$^$&$H$$$&J}K!$O$"$j$^$9!#(B > > > require "rexml/document" > require "rexml/encodings/ICONV" > module REXML::Encoding > @encoding_methods.delete("ICONV") > end > > $B$"$k$$$O(Brexml/encodings/ICONV.rb$B$r$9$G$KFI$_9~$s$@$3$H$K$7$FEP(B > $BO?$5$;$J$$$H$+!#(B > > $" << "rexml/encodings/ICONV.rb" > > $B$I$A$i$bFbIt9=B$$K6/$/0MB8$9$k$H$$$&E@$G$OK>$^$7$/$J$$$N$O3N$+(B > $B$G$9$,!#(B > > > $BC1$K(BIconv$B$GJ8;z%(%s%3!<%I$K<:GT$7$F$$$k$@$1$@$H;W$&$N$G$9$,(B > > Iconv$B$h$j$b(BUconv$B$rM%@h$7$FJ8;z%(%s%3!<%I=PMh$J$$$+$H9M$($F$$$^$9!#(B > > iconv$B$O$h$/$$$($PHFMQ!"$V$C$A$c$1(B($BBgK\$N5,3J$+$i$7$F(B)$BCfESH>C<$J(B > $B$N$G!";d$b@lMQ$NJQ49$rM%@h$7$?$[$&$,$$$$$N$G$O$J$$$+$H;W$$$^$9(B > $B$,!"(Brexml$B$N:n $B$;$s!#(B > > > ruby$B%$%s%9%H!<%k;~$K(Biconv$BL58z%*%W%7%g%s$bL5$$$h$&$G$9$N$G(Brexml$B$N%=!<%9(B > > $B$rJQ99$9$kI,MW$,$"$k$+$H;W$&$N$G$9$,!"1|$,?<$/=$@52U=j$,H=L@$7$F$*$j$^$;$s!#(B > > $B2<5-%5%$%H$GBP1~$5$l$F$$$i$C$7$c$kJ}$b$*$i$l$k$h$&$G$9$,!"=$@52U=j(B > > $B$K$D$$$F!"$I$J$?$+$465<($$$?$@$1$J$$$G$7$g$&$+!)(B > > --without-iconv$B$G%3%s%Q%$%k$7$J$/$9$k$H$$$&%Q%C%A(B[1]$B$O$^$@F~$C(B > $B$F$^$;$s$M!#(Bext/iconv/extconf.rb$B$r>C$7$F$*$/$@$1$G$b%3%s%Q%$%k(B > $B$5$l$J$/$O$J$j$^$9$,!#(B > > [1] http://www.dm4lab.to/~usa/ruby/d/200510b.html#id20051016_P1_2 > > > Index: lib/rexml/encoding.rb > =================================================================== > RCS file: /cvs/ruby/src/ruby/lib/rexml/encoding.rb,v > retrieving revision 1.5.2.1 > diff -U2 -p -w -r1.5.2.1 encoding.rb > --- lib/rexml/encoding.rb 19 May 2005 03:51:52 -0000 1.5.2.1 > +++ lib/rexml/encoding.rb 18 Oct 2005 02:10:51 -0000 > @@ -26,26 +26,20 @@ module REXML > $VERBOSE = false > return if defined? @encoding and enc == @encoding > - if enc and enc != UTF_8 > - @encoding = enc.upcase > + if enc > + 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 > - require 'rexml/encodings/ICONV.rb' > - Encoding.apply(self, "ICONV") > + require File.join("rexml", "encodings", "#{enc}.rb") > + return Encoding.apply(self, enc) > 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 > - else > - @encoding = UTF_8 > - require 'rexml/encodings/UTF-8.rb' > - Encoding.apply(self, @encoding) > - end > + puts err.message > + raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv." > ensure > $VERBOSE = old_verbosity > > > -- > --- $BKM$NA0$K(BBug$B$O$J$$!#(B > --- $BKM$N8e$m$K(BBug$B$O$G$-$k!#(B > $BCfED(B $B?-1Y(B >