Windows-31J <-> UTF-8 roundtrip

e$B0J2<$N$h$&$Ke(B Windows-31J e$B$He(B UTF-8 e$B$,e(B roundtrip
e$B$9$k$+$I$&$+e(B
e$B$rD4$Y$k$H!"$7$J$$J8;z$,$$$/$D$+$"$j$^$9$,!"$=$&$$$&$b$N$G$7e(B
e$B$?$C$1e(B?

% ./ruby -ve ’
hi_bytes = (0x81…0x9f).to_a + (0xe0…0xfc).to_a
lo_bytes = (0x40…0x7e).to_a + (0x80…0xfc).to_a
hi_bytes.each {|hi|
lo_bytes.each {|lo|
w = [hi,lo].pack(“CC”).force_encoding(“Windows-31J”)
begin
u = w.encode(“UTF-8”)
rescue RuntimeError
next
end
w2 = u.encode(“Windows-31J”)
printf("%s %X %s\n", w.unpack(“H*”)[0], u.unpack(“U”)[0],
w2.unpack(“H*”)[0]) if w != w2
}
}’
ruby 1.9.0 (2008-08-01 revision 18310) [i686-linux]
81be 222A 879c
81bf 2229 879b
81da 2220 8797
81db 22A5 8796
81df 2261 8791
81e0 2252 8790
81e3 221A 8795
81e6 2235 879a
81e7 222B 8792

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

Tanaka A. wrote:

begin

81bf 2229 879b
81da 2220 8797
81db 22A5 8796
81df 2261 8791
81e0 2252 8790
81e3 221A 8795
81e6 2235 879a
81e7 222B 8792

Windows-31J e$B$He(B Unicode
e$B$N4V$G1}I|[email protected]$N$J$$J8;z$,B8:_$9$k$3$H<+BN$O!“e(B
e$B$=$&$$$&$b$N$J$N$G$9$,!”>/$J$9$.$k>e$K0c$$$^$9$M!#e(B

e$B$3$s$J46$8$K$J$k$O$:$G$9!#e(B
http://support.microsoft.com/default.aspx?scid=kb;ja;JP170559

In article [email protected],
“NARUSE, Yui” [email protected] writes:

Windows-31J e$B$He(B Unicode e$B$N4V$G1}I|[email protected]$N$J$$J8;z$,B8:_$9$k$3$H<+BN$O!“e(B
e$B$=$&$$$&$b$N$J$N$G$9$,!”>/$J$9$.$k>e$K0c$$$^$9$M!#e(B

e$B$J$k$[$I!#e(B

e$B$G$O!"e(BShift_JIS e$B$de(B EUC-JP e$B$Oe(B UTF-8 e$B$H$N4V$Ge(B
roundtrip e$B$9$k$se(B
e$B$G$7$?$C$1e(B?

e$B<BAu$O$7$J$$$h$&$G$9$,!#e(B

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

Tanaka A. wrote:

In article [email protected],
“NARUSE, Yui” [email protected] writes:

Windows-31J e$B$He(B Unicode e$B$N4V$G1}I|[email protected]$N$J$$J8;z$,B8:_$9$k$3$H<+BN$O!“e(B
e$B$=$&$$$&$b$N$J$N$G$9$,!”>/$J$9$.$k>e$K0c$$$^$9$M!#e(B

e$B$J$k$[$I!#e(B

e$B$G$O!"e(BShift_JIS e$B$de(B EUC-JP e$B$Oe(B UTF-8 e$B$H$N4V$Ge(B roundtrip e$B$9$k$se(B
e$B$G$7$?$C$1e(B?

JIS X 0208 e$B$de(B 0213 e$BE*$K$Oe(B roundtrip e$B$9$k$O$:$G$9!#e(B
e$B$h$&$O!"0l0U$JL>A0$r%Y!<%9$KBP1~$5$;$F$$$k$N$G!#e(B

e$B$b$C$H$b!"$H$j$"$($:<j6a$Je(B glibc iconv
e$B$N%^%C%T%s%0$r8+$k$H!“e(B
0x5C, 0x7E e$B$N$”$?$j$Ge(B roundtrip e$B$7$F$^$;$s$M$’!#e(B
http://www2d.biglobe.ne.jp/~msyk/cgi-bin/charcode/bbs.cgi?c=gr&n=372

e$B<BAu$O$7$J$$$h$&$G$9$,!#e(B

e$B$9$k$D$b$j$J$s$G$9$,!"%F!<%V%[email protected]@.%9%/%j%W%H$N8x3+$rBT$C$FAae(B9e$B%v7n!#e(B
e$B>/$J$/$H$be(B 1.9.5 e$B0JA0$K$Oe(B ICU e$B$Ne(B ucm
e$B%U%!%$%k$+$i%F!<%V%[email protected]@.$9$k%9%/%j%W%H$,!“e(B
ruby 1.9 e$B$N%j%]%8%H%jFb$K8=$l$k$h$&$K$9$k$D$b$j$G$O$”$j$^$9!#e(B

In article [email protected],
“NARUSE, Yui” [email protected] writes:

e$B$9$k$D$b$j$J$s$G$9$,!"%F!<%V%[email protected]@.%9%/%j%W%H$N8x3+$rBT$C$FAae(B9e$B%v7n!#e(B
e$B>/$J$/$H$be(B 1.9.5 e$B0JA0$K$Oe(B ICU e$B$Ne(B ucm e$B%U%!%$%k$+$i%F!<%V%[email protected]@.$9$k%9%/%j%W%H$,!“e(B
ruby 1.9 e$B$N%j%]%8%H%jFb$K8=$l$k$h$&$K$9$k$D$b$j$G$O$”$j$^$9!#e(B

e$B:rF|!"%F!<%V%[email protected]@.%9%/%j%W%H$r:n$C$F$_$?$s$G$9$,!"$I$&$G$9$+$M!#e(B

http://www.a-k-r.org/tmp/transcode-table-gen.patch

test_transcode.rb e$B$/$i$$$OF0$-$^$9!#e(B

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

Tanaka A. wrote:

In article [email protected],
“NARUSE, Yui” [email protected] writes:

e$B$9$k$D$b$j$J$s$G$9$,!"%F!<%V%[email protected]@.%9%/%j%W%H$N8x3+$rBT$C$FAae(B9e$B%v7n!#e(B
e$B>/$J$/$H$be(B 1.9.5 e$B0JA0$K$Oe(B ICU e$B$Ne(B ucm e$B%U%!%$%k$+$i%F!<%V%[email protected]@.$9$k%9%/%j%W%H$,!“e(B
ruby 1.9 e$B$N%j%]%8%H%jFb$K8=$l$k$h$&$K$9$k$D$b$j$G$O$”$j$^$9!#e(B

e$B:rF|!"%F!<%V%[email protected]@.%9%/%j%W%H$r:n$C$F$_$?$s$G$9$,!"$I$&$G$9$+$M!#e(B

e$B$"$!!"$J$k$[$I!"$=$l$Ge(B roundtrip e$B$NOC$J$N$G$9$M!#e(B

http://www.a-k-r.org/tmp/transcode-table-gen.patch

test_transcode.rb e$B$/$i$$$OF0$-$^$9!#e(B

e$B%F!<%V%[email protected]@.$H$$$&[email protected]$+$i$G$9$H!"BgItJ,$Oe(B roundtrip
e$B$J$N$G!"e(B
e$B4pK\E*$Ke(B roundtrip
e$B$N%F!<%V%k$r:n$C$F!"e(B1e$BJ}8~$OJL$K4IM}$9$k$N$,$h$$$H;W$$$^$9!#e(B
ucm
e$B7A<0$OBP1~$N%l%3!<%I$4$H$K%U%i%0$rIU$1$F!"e(B1e$BJ}8~JQ49$r$7$F$$$^$9$M!#e(B

e$B$5$F$*$-!"9|;R$H$7$F$O$h$$$+$H;W$$$^$9!#e(B

e$B$D$C$3$`$H$7$?$i!"e(B

  • transcode_compile “from_SHIFT_JIS”, “Shift_JIS”,
    e$B$Oe(B “Shift_JIS”, “UTF-8” e$B$K$9$k$H$+!"e(B

  • [

  • ["{00-7f}", :nomap],

  •                  ["A1", "EFBDA1"], ["A2", "EFBDA2"], ["A3", 
    

“EFBDA3”],


  • e$B$Oe(B

  • [

  • ["{00-7f}", :nomap],

  • [“JIS X 0208%UTF-8.txt”],
    e$B$J$j!"e(B
    e$B$b$C$HJL$Ke(B US-ASCII%UTF-8.tbl
    JIS_X_0208%UTF8.tble$B$J$j$N%U%!%$%k$r:n$C$F!"e(B
    transcode_define “Shift_JIS”, “UTF-8”
    [ US-ASCII, JIS_X_0208 ] e$B$J$j$GDj5A$9$k$H$+!#e(B

+static const rb_transcoder
+rb_to_SHIFT_JIS = {

  • “UTF-8”, “SHIFT_JIS”, &to_SHIFT_JIS, 2, 1,
  • NULL, NULL,
    +};
    e$B$Oe(B .erb e$B$K=q$+$:<[email protected]@.$K$9$k$H$+!"e(B

e$B$=$NJU$+$J$!$H!#e(B

In article [email protected],
“NARUSE, Yui” [email protected] writes:

e$B%F!<%V%[email protected]@.$H$$$&[email protected]$+$i$G$9$H!"BgItJ,$Oe(B roundtrip e$B$J$N$G!"e(B
e$B4pK\E*$Ke(B roundtrip e$B$N%F!<%V%k$r:n$C$F!"e(B1e$BJ}8~$OJL$K4IM}$9$k$N$,$h$$$H;W$$$^$9!#e(B

e$B$=$l$O$=$&$G$7$g$&$M!#e(B

ucm e$B7A<0$OBP1~$N%l%3!<%I$4$H$K%U%i%0$rIU$1$F!"e(B1e$BJ}8~JQ49$r$7$F$$$^$9$M!#e(B

e$B$U$`!#$=$s$J7A<0$,!#e(B

e$B$b$C$HJL$Ke(B US-ASCII%UTF-8.tbl JIS_X_0208%UTF8.tble$B$J$j$N%U%!%$%k$r:n$C$F!"e(B
transcode_define “Shift_JIS”, “UTF-8”
[ US-ASCII, JIS_X_0208 ] e$B$J$j$GDj5A$9$k$H$+!#e(B

e$BG[[email protected]$1Dj5A$9$k%U%!%$%k$K$o$1$F$_$^$7$?!#e(B

+static const rb_transcoder
+rb_to_SHIFT_JIS = {

  • “UTF-8”, “SHIFT_JIS”, &to_SHIFT_JIS, 2, 1,
  • NULL, NULL,
    +};
    e$B$Oe(B .erb e$B$K=q$+$:<[email protected]@.$K$9$k$H$+!"e(B

e$B$3$l$b$d$C$F!"$^$:$Oe(B
http://www.a-k-r.org/tmp/transcode-table-gen2.patch
e$B$/$i$$$G$9$+$M$’!#e(B

In article [email protected],
“NARUSE, Yui” [email protected] writes:

e$B$3$l$G%3%_%C%H$7$F$7$^$C$F$$$$$H;W$$$^$9!#e(B

e$B$$$l$^$7$?!#e(B

e$B$J$!"%F!<%V%k$NFbMF$OJQ$($F$J$$$N$G!"F|K\8l$NJQ49%F!<%V%k$Oe(B
e$B$$$^$^$G$I$
$j$h$/$o$+$i$J$$$b$N$N$^$^$G$9!#e(B

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

Tanaka A. wrote:

e$B$3$l$b$d$C$F!"$^$:$Oe(B
http://www.a-k-r.org/tmp/transcode-table-gen2.patch
e$B$/$i$$$G$9$+$M$’!#e(B

e$B$3$l$G%3%_%C%H$7$F$7$^$C$F$$$$$H;W$$$^$9!#e(B

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

Tanaka A. wrote:

In article [email protected],
“NARUSE, Yui” [email protected] writes:

e$B$3$l$G%3%_%C%H$7$F$7$^$C$F$$$$$H;W$$$^$9!#e(B

e$B$$$l$^$7$?!#e(B

e$B$J$!"%F!<%V%k$NFbMF$OJQ$($F$J$$$N$G!"F|K\8l$NJQ49%F!<%V%k$Oe(B
e$B$$$^$^$G$I$
$j$h$/$o$+$i$J$$$b$N$N$^$^$G$9!#e(B

e$B$"$j$,$H$&$4$6$$$^$9!#e(B
e$B%F!<%V%k$O;~4V$N$"$k;~$KJQ$($F$*$-$^$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