Binmode and ASCII-8BIT

e$B@>;3OB9-$G$9!#e(B

http://dontstopmusic.no-ip.org/diary/20080106.html#p02
e$B$r8+$F$A$g$C$HD4$Y$F$_$?$N$G$9$,!"e(B

  • binmode e$B$Ge(B external_encoding e$B$,e(B ASCII-8BIT e$B$K$J$ke(B
  • external_encoding e$B$,e(B ASCII-8BIT e$B$@$He(B ASCII-8BIT
    e$B0J30$N%(%s%3!<%G%#%s%0$Ne(B
    ascii_only e$B$G$O$J$$J8;zNs$,=PNO$G$-$J$$e(B
  • nil e$B$He(B ASCII-8BIT
    e$B$,F1$807$$$N%a%=%C%I$H0c$&07$$$N%a%=%C%I$,$"$ke(B
    e$B$H$$$&$N$O;EMM$G$7$g$&$+e(B?

e$B2~9T$NJQ49$@$1;_$a$F$[$7$$>l9g$Oe(B .binmode.set_encoding(nil)
e$B$Ke(B
e$B$J$k$N$G$7$g$&$+e(B?

% ruby-trunk -v
ruby 1.9.0 (2008-01-09 revision 0) [i686-linux]
% ruby-trunk -e ‘Encoding.find(nil)’
-e:1:in find': can't convert nil into String (TypeError) from -e:1:in
% ruby-trunk -e ‘p “”.encode(nil).encoding’
#Encoding:ASCII-8BIT
% ruby-trunk -e ‘p “”.encode(Encoding::ASCII_8BIT).encoding’
#Encoding:ASCII-8BIT
% ruby-trunk -e ‘p
STDERR.set_encoding(Encoding::ASCII_8BIT).external_encoding’
#Encoding:ASCII-8BIT
% ruby-trunk -e ‘p STDERR.set_encoding(nil).external_encoding’
nil
% ruby-trunk -e ‘p STDERR.binmode.external_encoding’
#Encoding:ASCII-8BIT
%

% ruby-trunk -E euc-jp -e ‘p “\xFF”.encoding’
#Encoding:EUC-JP
% ruby-trunk -E euc-jp -e ‘p
“\xFF”.force_encoding(Encoding::ASCII_8BIT).encoding’
#Encoding:ASCII-8BIT
% ruby-trunk -E euc-jp -e ‘p “\xFF”.force_encoding(nil).encoding’
#Encoding:ASCII-8BIT
%

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:32996] binmode and ASCII-8BIT”
on Wed, 9 Jan 2008 21:39:00 +0900, Kazuhiro NISHIYAMA
[email protected] writes:

|http://dontstopmusic.no-ip.org/diary/20080106.html#p02
|e$B$r8+$F$A$g$C$HD4$Y$F$_$?$N$G$9$,!“e(B
| * binmode e$B$Ge(B external_encoding e$B$,e(B ASCII-8BIT e$B$K$J$ke(B
| * external_encoding e$B$,e(B ASCII-8BIT e$B$@$He(B ASCII-8BIT e$B0J30$N%(%s%3!<%G%#%s%0$Ne(B
| ascii_only e$B$G$O$J$$J8;zNs$,=PNO$G$-$J$$e(B
| * nil e$B$He(B ASCII-8BIT e$B$,F1$807$$$N%a%=%C%I$H0c$&07$$$N%a%=%C%I$,$”$ke(B
|e$B$H$$$&$N$O;EMM$G$7$g$&$+e(B?

e$B=gHV$K!#e(B

  • binmode e$B$Ge(B external_encoding e$B$,e(B ASCII-8BIT e$B$K$J$ke(B

e$B;EMM!"$G$7$?!#e(BMartine$B$5$s$+$i;XE&$r<u$1$F!“e(Bencodinge$B$K$O<j$r2Ce(B
e$B$($J$$$h$&$K$9$k$3$H$K$7$^$7$?!#$,!”$^$@<BAu$KH?1G$5$l$F$^$;e(B
e$B$s!#e(B

  • external_encoding e$B$,e(B ASCII-8BIT e$B$@$He(B ASCII-8BIT
    e$B0J30$N%(%s%3!<%G%#%s%0$Ne(B
    ascii_only e$B$G$O$J$$J8;zNs$,=PNO$G$-$J$$e(B

e$BL@<(E*$K;XDj$7$?>l9g$K$OJQ49$,9T$o$l$^$9$+$i!“=PNO$N>l9g$K$Oe(B
e$B%(%s%3!<%G%#%s%0$r;XDj$7$J$$$3$H$r$*A&$a$7$^$9!#$?$@$7!”$3$Ne(B
e$B%(%s%H%j$N>l9g$K$Oe(Bbinmodee$B$,>!<j$K;XDj$7$F$$$k$o$1$G$9$,!#$3$le(B
e$B$O%P%0G’Dj$G$9!#e(B

  • nil e$B$He(B ASCII-8BIT
    e$B$,F1$807$$$N%a%=%C%I$H0c$&07$$$N%a%=%C%I$,$"$ke(B

Stringe$B$$h$Se(BEncodinge$B$G$Oe(Bnile$B$O%(%s%3!<%G%#%s%0$H$7$F;XDj$G$-e(B
e$B$^$;$s!#e(BIOe$B$K$
$$$F$O!V%(%s%3!<%G%#%s%0$r;XDj$7$J$$!W$H$$$&0Ue(B
e$BL#$K$J$j$^$9!#$=$l0J30$G!V0c$&07$$!W$,$"$l$P65$($F$/$@$5$$!#e(B

|e$B2~9T$NJQ49$@$1;_$a$F$[$7$$>l9g$Oe(B .binmode.set_encoding(nil) e$B$Ke(B
|e$B$J$k$N$G$7$g$&$+e(B?

binmodee$B$@$1$Ge(BOKe$B$K$J$kM=Dj$G$9!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:33000] Re: binmode and ASCII-8BIT”
on Thu, 10 Jan 2008 08:36:47 +0900, sheepman
[email protected] writes:

|IO.pipe e$B$NBhe(B2e$B0z?t$Ke(B nil e$B$r;XDj$7$?;~$KFbIt%(%s%3!<%G%#%s%0$,e(B
|e$B0J2<$N$h$&$K$J$k$N$O%P%0$G$7$g$&$+!#e(B
|
|$ cat pipe.rb
|p IO.pipe(Encoding::EUC_JP)[0].internal_encoding
|p IO.pipe(Encoding::EUC_JP, nil)[0].internal_encoding
|
|$ ruby-1.9 -Ks -v pipe.rb
|ruby 1.9.0 (2008-01-07 revision 0) [i686-linux]
|nil
|#Encoding:Windows-31J

e$B%P%0$G$9$M!#$"$j$,$H$&$4$6$$$^$9!#e(B

e$B$3$s$K$A$Oe(B sheepman e$B$G$9!#e(B

On Thu, 10 Jan 2008 02:26:30 +0900
Yukihiro M. [email protected] wrote:

  • nil e$B$He(B ASCII-8BIT e$B$,F1$807$$$N%a%=%C%I$H0c$&07$$$N%a%=%C%I$,$"$ke(B

Stringe$B$$h$Se(BEncodinge$B$G$Oe(Bnile$B$O%(%s%3!<%G%#%s%0$H$7$F;XDj$G$-e(B
e$B$^$;$s!#e(BIOe$B$K$
$$$F$O!V%(%s%3!<%G%#%s%0$r;XDj$7$J$$!W$H$$$&0Ue(B
e$BL#$K$J$j$^$9!#$=$l0J30$G!V0c$&07$$!W$,$"$l$P65$($F$/$@$5$$!#e(B

IO.pipe e$B$NBhe(B2e$B0z?t$Ke(B nil
e$B$r;XDj$7$?;~$KFbIt%(%s%3!<%G%#%s%0$,e(B
e$B0J2<$N$h$&$K$J$k$N$O%P%0$G$7$g$&$+!#e(B

$ cat pipe.rb
p IO.pipe(Encoding::EUC_JP)[0].internal_encoding
p IO.pipe(Encoding::EUC_JP, nil)[0].internal_encoding

$ ruby-1.9 -Ks -v pipe.rb
ruby 1.9.0 (2008-01-07 revision 0) [i686-linux]
nil
#Encoding:Windows-31J

e$B$J$+$@$G$9!#e(B

At Thu, 10 Jan 2008 02:26:30 +0900,
Yukihiro M. wrote in [ruby-dev:32998]:

  • nil e$B$He(B ASCII-8BIT e$B$,F1$807$$$N%a%=%C%I$H0c$&07$$$N%a%=%C%I$,$"$ke(B

Stringe$B$$h$Se(BEncodinge$B$G$Oe(Bnile$B$O%(%s%3!<%G%#%s%0$H$7$F;XDj$G$-e(B
e$B$^$;$s!#e(BIOe$B$K$
$$$F$O!V%(%s%3!<%G%#%s%0$r;XDj$7$J$$!W$H$$$&0Ue(B
e$BL#$K$J$j$^$9!#$=$l0J30$G!V0c$&07$$!W$,$"$l$P65$($F$/$@$5$$!#e(B

Stringe$B$G$H$$$&$N$Oe(Bforce_encodinge$B$G$7$g$&$+!#e(B

$ ./ruby -e ‘p “\u3000”.force_encoding(nil).encoding’
#Encoding:ASCII-8BIT

e$B$H$$$&$h$&$K!“8=>u$G$O%(%s%3!<%G%#%s%0;XDj$H$7$Fe(BEncodinge$B!”%(%s%3!<e(B
e$B%G%#%s%0L>$^$?$Oe(Bnile$B$r<u$1IU$1$^$9$,!"D>$9$Y$-$G$7$g$&$+!#e(B

Encoding.finde$B$K$D$$$F$O!"%(%s%3!<%G%#%s%0L>$+$ie(BEncodinge$B%%V%8%'e(B
e$B%/%H$rJV$9%a%=%C%I$J$N$G!"e(BStringe$B0J30e(BEncodinge$B$be(Bnile$B$b<u$1IU$1$^$;e(B
e$B$s!#$3$l$O>e5-$N!V%(%s%3!<%G%#%s%0;XDj!W$H$OJLJ
$G$"$k$H9M$($F$$e(B
e$B$^$9!#e(Bforce_encodinge$B$J$I$bK\Mhe(BEncodinge$B%%V%8%’%/%H$r<u$1<h$k$Y$-e(B
e$B$@$1$l$I!“4JJX$5$N$?$a$K%(%s%3!<%G%#%s%0L>$G$”$l$P<+F0E
$Ke(B
Encoding.finde$B$7$F$$$k$@$1$G!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:33002] Re: binmode and ASCII-8BIT”
on Thu, 10 Jan 2008 11:40:43 +0900, Nobuyoshi N.
[email protected] writes:

|Stringe$B$G$H$$$&$N$Oe(Bforce_encodinge$B$G$7$g$&$+!#e(B
|
| $ ./ruby -e ‘p “\u3000”.force_encoding(nil).encoding’
| #Encoding:ASCII-8BIT
|
|e$B$H$$$&$h$&$K!“8=>u$G$O%(%s%3!<%G%#%s%0;XDj$H$7$Fe(BEncodinge$B!”%(%s%3!<e(B
|e$B%G%#%s%0L>$^$?$Oe(Bnile$B$r<u$1IU$1$^$9$,!"D>$9$Y$-$G$7$g$&$+!#e(B

nile$B$Oe(BASCII-8BITe$B$r;XDj$7$?$3$H$K$J$k$h$&$G$9$M!#5v$9$3$H$N%ae(B
e$B%j%C%H$,;W$$$D$+$J$$$N$G$9$,!"$b$7%a%j%C%H$,$J$1$l$PD>$9$Y$-e(B
e$B$G$7$g$&$M!#e(B