TypeError from Encoding.compatible? (r18920)

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

r18920e$B$Ge(BEncoding.compatible?e$B$,e(BTypeErrore$B$r$"$2$k$h$&$K$J$j$^e(B
e$B$7$?$,!"$3$l$,0z?t%A%’%C%/$J$7$Ke(BBUILTIN_TYPE()e$B$r;H$C$F$$$k$?e(B
e$B$a!"e(Btest_m17n.rbe$B$,Mn$A$^$9!#e(B

e$B$G$9$,!"$=$b$=$be(Bcompatible?e$B$,Nc30$r$"$2$kI,MW$,$"$k$N$G$7$ge(B
e$B$&$+!#%3%s%Q%A$+$I$&$+%A%’%C%/[email protected]$1$J$N$KNc30$,>e$,$k$Ne(B
e$B$O;H$$$K$/$$5$$,$7$^$9!#:#$^$G$N$h$&$K$=$b$=$be(Bencodinge$B$NBP>]e(B
e$B$G$O$J$$;~e(Bnile$B!"e(Bcompatiblee$B$G$J$$;~e(Bfalsee$B!"e(Bcompatiblee$B$J;~e(Btruee$B$Ne(B
e$BJ}$,NI$$$h$&$K;W$$$^$9!#e(B

e$B$N$G!“8D?ME*$K$Oe(Br18920e$B$r%j%P!<%H$7$?$$$N$G$9$,!”$I$&$G$7$g$&!)e(B

e$B$b$7!“Nc30$r$”[email protected][email protected]$&$N$G$"$l$P!"e(BBUILTIN_TYPE()e$B$G$Oe(B
e$B$J$/!"e(BTYPE()e$B$r;H$&$Y$-$G$7$g$&!#e(B

[email protected]@%$G$9!#e(B

Yukihiro M. wrote:

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

r18920e$B$Ge(BEncoding.compatible?e$B$,e(BTypeErrore$B$r$"$2$k$h$&$K$J$j$^e(B
e$B$7$?$,!"$3$l$,0z?t%A%’%C%/$J$7$Ke(BBUILTIN_TYPE()e$B$r;H$C$F$$$k$?e(B
e$B$a!"e(Btest_m17n.rbe$B$,Mn$A$^$9!#e(B

e$B$b$7!“Nc30$r$”[email protected][email protected]$&$N$G$"$l$P!"e(BBUILTIN_TYPE()e$B$G$Oe(B
e$B$J$/!"e(BTYPE()e$B$r;H$&$Y$-$G$7$g$&!#e(B

e$B$3$Ne(B 2 e$B$D$O$H$j$"$($:[email protected]$7$^$7$?!#e(B

e$B:#$^$G$N$h$&$K$=$b$=$be(Bencodinge$B$NBP>]e(B
e$B$G$O$J$$;~e(Bnile$B!"e(Bcompatiblee$B$G$J$$;~e(Bfalsee$B!"e(Bcompatiblee$B$J;~e(Btruee$B$Ne(B
e$BJ}$,NI$$$h$&$K;W$$$^$9!#e(B

e$B$=$N$h$&$J;EMM$O=i<*$G$9!#e(B

  • call-seq:
  • Encoding.compatible?(str1, str2) => enc or nil
  • Checks the compatibility of two strings.
  • If they are compatible, means concatenatable,
  • returns an encoding which the concatinated string will be.
  • If they are not compatible, nil is returned.
    encoding.c e$B$Ne(B rdoc e$B$h$je(B

r18920 e$B0JA0$G$O0J2<$NDL$j$G$7$?!#e(B

  • encodinge$B$NBP>]$G$O$J$$;~e(B nil
  • compatible e$B$G$J$$;~$be(B nil
  • compatible e$B$J;~$O$I$3$K$*$$$Fe(B compatible e$B$+$K1~$8$Fe(B enc

    Encoding.compatible?("\u3042", “hoge”) #=> Encoding::UTF_8

    e$BEy$N7k2L$,M_$7$$$N$Ge(B enc e$B$G$"$kI,MW$,$"$ke(B

    [email protected]$$49$($l$P!"e(B2 e$B$D$Ne(B str e$B$r7k9g$7$?;~$Ne(B encoding

e$B$,JV$ke(B

e$B$=$7$F!"e(Br18920 e$B$G!"e(B

  • encodinge$B$NBP>]$G$O$J$$;~e(B TypeError
  • compatible e$B$G$J$$;~$be(B nil
  • compatible e$B$J;~$Oe(B enc

e$B$G$9$,!"$=$b$=$be(Bcompatible?e$B$,Nc30$r$"$2$kI,MW$,$"$k$N$G$7$ge(B
e$B$&$+!#%3%s%Q%A$+$I$&$+%A%’%C%/[email protected]$1$J$N$KNc30$,>e$,$k$Ne(B
e$B$O;H$$$K$/$$5$$,$7$^$9!#e(B

e$B$b$H$b$H!“e(BEncoding.compatible? e$B$N0z?t$Ke(B encoding
e$B$rM?$($k$He(B
e$B4|BT$7$?$H$*$j$KF0:n$7$J$$$H$$$&$N$,$”$j$^$7$F!"e(B

Encoding.compatible?(Encoding::UTF_8, Encoding::US_ASCII)
=> #Encoding:ASCII-8BIT

rb_enc_get_index() e$B$Oe(B encoding e$B$rBP>]$H$7$J$$$?$ae(B

e$B$3$N$h$&$J8m2r$r>7$/F0:n$r$9$k$h$j$O!"e(B
e$B7i$/Nc30$r=P$7$F$/$l$?J}$,$$$$$H9M$($^$7$?!#e(B

Encoding.compatible? e$B$,e(B encoding e$B$r<h$l$k$h$&$K$9$k$Y$-!"e(B

e$B$H$$$&0F$K$D$$$F$O8=:_;W0FCfe(B

e$B$^$D$b$H$5$s$N6D$k;[email protected]$,$"$k$N$G$h$$$H;W$&$N$G$9$,!"e(B
e$B8=9T$N;EMM$G$Oe(B compatible e$B$J;~$Ke(B enc e$B$rJV$90J>e!"e(B
false e$B$He(B nil
e$B$G6hJL$H$$$&J}K!$,;H$$$E$i$$$N$,%M%C%/$G$7$g$&$+!#e(B
enc / false / nil e$B$G$b$$$$$N$+$J$!!&!&!&!#e(B

r18920 e$B$N0U?^$Oe(B Encoding.compatible?
e$B$,BP1~$7$F$$$k%%V%8%’%/%H$H!"e(B
e$BBP1~$7$F$$$J$$%
%V%8%’%/%[email protected]$C$?$N$G!"e(B
[email protected]$o$j$O$J$$$N$G$9$,!&!&!&!#e(B

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

In message “Re: [ruby-dev:36049] Re: TypeError from Encoding.compatible?
(r18920)”
on Sat, 30 Aug 2008 08:16:21 +0900, “NARUSE, Yui”
[email protected] writes:

|> e$B:#$^$G$N$h$&$K$=$b$=$be(Bencodinge$B$NBP>]e(B
|> e$B$G$O$J$$;~e(Bnile$B!"e(Bcompatiblee$B$G$J$$;~e(Bfalsee$B!"e(Bcompatiblee$B$J;~e(Btruee$B$Ne(B
|> e$BJ}$,NI$$$h$&$K;W$$$^$9!#e(B
|
|e$B$=$N$h$&$J;EMM$O=i<*$G$9!#e(B

e$B$9$$$^$;$s!#e(Bencodinge$B$rJV$9$3$H$r<:G0$7$F$^$7$?!#e(B

|> e$B$G$9$,!"$=$b$=$be(Bcompatible?e$B$,Nc30$r$"$2$kI,MW$,$"$k$N$G$7$ge(B
|> e$B$&$+!#%3%s%Q%A$+$I$&$+%A%’%C%/[email protected]$1$J$N$KNc30$,>e$,$k$Ne(B
|> e$B$O;H$$$K$/$$5$$,$7$^$9!#e(B
|
|e$B$b$H$b$H!“e(BEncoding.compatible? e$B$N0z?t$Ke(B encoding e$B$rM?$($k$He(B
|e$B4|BT$7$?$H$*$j$KF0:n$7$J$$$H$$$&$N$,$”$j$^$7$F!"e(B
|> Encoding.compatible?(Encoding::UTF_8, Encoding::US_ASCII)
|=> #Encoding:ASCII-8BIT
|# rb_enc_get_index() e$B$Oe(B encoding e$B$rBP>]$H$7$J$$$?$ae(B
|
|e$B$3$N$h$&$J8m2r$r>7$/F0:n$r$9$k$h$j$O!"e(B
|e$B7i$/Nc30$r=P$7$F$/$l$?J}$,$$$$$H9M$($^$7$?!#e(B
|# Encoding.compatible? e$B$,e(B encoding e$B$r<h$l$k$h$&$K$9$k$Y$-!"e(B
|# e$B$H$$$&0F$K$D$$$F$O8=:_;W0FCfe(B

e$B$C$F$$$&$+!"$=$N!V;W0F!W$,=*$o$C$F$+$iJQ99$7$F$b$h$+$C$?$s$8$ce(B
e$B$J$$$s$G$9$+$M!#e(B

|e$B$^$D$b$H$5$s$N6D$k;[email protected]$,$"$k$N$G$h$$$H;W$&$N$G$9$,!"e(B
|e$B8=9T$N;EMM$G$Oe(B compatible e$B$J;~$Ke(B enc e$B$rJV$90J>e!"e(B
|false e$B$He(B nil e$B$G6hJL$H$$$&J}K!$,;H$$$E$i$$$N$,%M%C%/$G$7$g$&$+!#e(B
|enc / false / nil e$B$G$b$$$$$N$+$J$!!&!&!&!#e(B

e$B$d$C$Q$je(B enc / false / nil e$B$O$*$+$7$$5$$,$7$^$9$M!#$&!<$s!#e(B
true / false / nil e$B$K$7$F!":G>/8xG?t$J%(%s%3!<%G%#%s%0$r5ae(B
e$B$a$k%a%=%C%I$OJL$K;}$D$H$+e(B…e$B!#e(B

|r18920 e$B$N0U?^$Oe(B Encoding.compatible? e$B$,BP1~$7$F$$$k%%V%8%’%/%H$H!"e(B
|e$BBP1~$7$F$$$J$$%
%V%8%’%/%[email protected]$C$?$N$G!"e(B
|[email protected]$o$j$O$J$$$N$G$9$,!&!&!&!#e(B

Encoding.compatible?e$B$,[email protected]$K$9$kI,MW$,$"$k$H;We(B
e$B$$$^$9!#e(B

e$B$?$H$($P>-Mhe(BIOe$B$H$+e(BStringIOe$B$H$+!VJ8;zNs$N$h$&$K?6$kIq$&$J$K$+!We(B
e$B$r0z?t$K$H$k$h$&[email protected]$r9M$($k$H!":#$N$h$&$J%A%’%C%/e(B(e$BJ8;zNse(B
[email protected],I=8=$N$_e(B)e$B$O$"$^$jNI$/$J$$$h$&$J5$$,$7$^$9!#e(B

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

[email protected]@%$G$9!#e(B

r19357 e$B$G0J2<$NDL$jJQ99$7$^$7$?$,!"$$$+$,$G$7$g$&$+!#e(B

  • e$B$I$A$i$+$,e(B encoding e$B$r;}$?$J$$e(B
    -> nil

encoding e$B$r;}$D$+$I$&$+$NH=CG$O3F<+e(B encoding

e$B%a%=%C%I$NM-L5Ey$GH=CG$7$F$[$7$$e(B

  • compatible e$B$G$J$$e(B
    -> nil

  • compatible e$B$J>l9ge(B
    -> String e$B$He(B Regexp e$B$O8=>uDL$je(B
    -> Encoding e$B$rDI2C!"F0:n$Oe(B Regexp e$B$HF1MMe(B
    -> IO e$B$rDI2C!"e(Binternal_encoding e$B$+!"e(Bnil e$B$J$i$Pe(B
    external_encoding e$B$r8+$FH=CGe(B

e$B;29Me(B: [ruby-core:18595]

e$B<BAu$7$F$$$F;W$C$?$N$G$9$,!"e(B

IO#encoding:
internal_encoding e$B$,e(B Encoding e$B$rJV$;$P$=$l$r!“e(B
nil [email protected]$C$?$ie(B external_encoding e$B$rJV$9!#e(B
e$B$H$$$&$N$,$”$C$F$bNI$5$=$&$J5$$,$7$^$9$Me(B

[email protected]@%$G$9!#e(B

Yukihiro M. wrote:

|e$B$3$N$h$&$J8m2r$r>7$/F0:n$r$9$k$h$j$O!"e(B
|e$B7i$/Nc30$r=P$7$F$/$l$?J}$,$$$$$H9M$($^$7$?!#e(B
|# Encoding.compatible? e$B$,e(B encoding e$B$r<h$l$k$h$&$K$9$k$Y$-!"e(B
|# e$B$H$$$&0F$K$D$$$F$O8=:_;W0FCfe(B

e$B$C$F$$$&$+!"$=$N!V;W0F!W$,=*$o$C$F$+$iJQ99$7$F$b$h$+$C$?$s$8$ce(B
e$B$J$$$s$G$9$+$M!#e(B

1.9.1 e$B;EMM$Ne(B fix
e$B$,Gw$C$F$-$?$N$G!"$H$j$"$($::#$N$^$^$8$c$^$:[email protected]$m$&$H!#e(B
e$B$"$H!"e(Bencoding e$B$N>l9g$O$=$Ne(B encoding
e$B$,2?$r0U?^$7$F$$$k$N$+Fq$7$$$N$G!#e(B

|e$B$^$D$b$H$5$s$N6D$k;[email protected]$,$"$k$N$G$h$$$H;W$&$N$G$9$,!"e(B
|e$B8=9T$N;EMM$G$Oe(B compatible e$B$J;~$Ke(B enc e$B$rJV$90J>e!"e(B
|false e$B$He(B nil e$B$G6hJL$H$$$&J}K!$,;H$$$E$i$$$N$,%M%C%/$G$7$g$&$+!#e(B
|enc / false / nil e$B$G$b$$$$$N$+$J$!!&!&!&!#e(B

e$B$d$C$Q$je(B enc / false / nil e$B$O$*$+$7$$5$$,$7$^$9$M!#$&!<$s!#e(B
true / false / nil e$B$K$7$F!":G>/8xG?t$J%(%s%3!<%G%#%s%0$r5ae(B
e$B$a$k%a%=%C%I$OJL$K;}$D$H$+e(B…e$B!#e(B

Encoding.compatible? e$B$Oe(B enc / nil e$B$K$7$F!"e(B

C e$B%l%Y%[email protected]$&e(B enc_capable
e$BE*$J$b$N$rMQ0U$9$k$N$b$"$j$+$b!"$H$+$O!#e(B
e$B$3$N>l9ge(B obj#encoding e$B$NM-L5$GH=CG$H$+$K$J$k$s$G$7$g$&$,!"e(B
e$B0lJ}$Ge(B IO#encoding e$B$O$J$+$C$?$j$9$k$o$1$G$9!#e(B

|r18920 e$B$N0U?^$Oe(B Encoding.compatible? e$B$,BP1~$7$F$$$k%%V%8%’%/%H$H!"e(B
|e$BBP1~$7$F$$$J$$%
%V%8%’%/%[email protected]$C$?$N$G!"e(B
|[email protected]$o$j$O$J$$$N$G$9$,!&!&!&!#e(B

Encoding.compatible?e$B$,[email protected]$K$9$kI,MW$,$"$k$H;We(B
e$B$$$^$9!#e(B

e$B$?$H$($P>-Mhe(BIOe$B$H$+e(BStringIOe$B$H$+!VJ8;zNs$N$h$&$K?6$kIq$&$J$K$+!We(B
e$B$r0z?t$K$H$k$h$&[email protected]$r9M$($k$H!":#$N$h$&$J%A%’%C%/e(B(e$BJ8;zNse(B
[email protected],I=8=$N$_e(B)e$B$O$"$^$jNI$/$J$$$h$&$J5$$,$7$^$9!#e(B

IO e$B7O$N$3$H$O9M$($?$s$G$9$,!":#$Ne(B Encoding.compatible? e$B$H$Oe(B
e$B$=$0$o$J$$$h$&$K46$8$^$7$?!#e(B

e$B$=$b$=$b!“e(BIO e$B$OF~NO$H=PNO$GOC$,0c$&$o$1$G!“e(B
e$B$?$H$($P!”!Ve(BUS-ASCII e$B$Ne(B IO e$B=PNO!W$H!Ve(BUTF-8
e$B$NJ8;zNs!W$O!_$G$9!#e(B
e$B$7$+$7!”!Ve(BUS-ASCII e$B$Ne(B IO e$BF~NO!W$H!Ve(BUTF-8
e$B$NJ8;zNs!W$O!{$G!"e(B
encoding e$B$rJV$9$J$i$Pe(B UTF-8 e$B$G$7$g$&!#e(B

e$B$^$?!"e(BEncoding.compatible? e$B$OCf?H$Ne(B ASCII ONLY
e$B$^$G8+$k$o$1$G$9$,!"e(B
e$B$3$l$re(B IO e$B$KE,MQ$9$k$3$H$O:$Fq$G$9!#e(B

e$B$D$^$j!"e(BIO e$B$r2>$K0z?t$H$9$k>l9g!"e(B
e$B$=$Ne(B encoding e$B$r;}$Ae(B CODERANGE_VALID e$B$Je(B string
e$B$H$_$J$9!"e(B
e$B$H$$$&$3$H$K$J$k$+$H;W$&$N$G$9$,!"2L$?$7$F$3$l$,!"e(B
Encoding.compatible?(io, str) e$B$H=q$$$?>l9g$N4|BTDL$j$+$H$$$&$H!“e(B
e$B$J$+$J$+$”$d$7$$=j$J$s$8$c$J$$$+$J$!$H!#e(B

encoding e$B$N>l9g$bF1MM$G!"$=$Ne(B encoding e$B$,$I$3$Ne(B encoding
e$B$+$K$h$C$F!"e(B
“compatible” e$B$N0UL#$,JQ$o$C$F$-$^$9!#e(B

e$B0lJ}$G!"e(Bregexp
e$B$K4X$7$F$OJ8;zNs$HMm$`ItJ,$,%^%C%A$N$$J$N$G!"e(B
e$B$b$&0lJ}$N$J$K$+$Ne(B encoding e$B$rJ8;zNs$Ne(B encoding
e$B$H$
$J$7!"e(B
e$BEv3:e(B regexp
e$B$N%^%C%A2DG=$+$GH=CG$9$k$H$$$&$3$H$G7h$a$i$l$^$7$?!#e(B

e$B$H$$$&6q9g$KOC$O$J$+$J$+Fq$7$$$o$1$G$9!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs