[#32945] Shift_JIS variants and UTF-16 support — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/07
[#32953] Re: Shift_JIS variants and UTF-16 support — Martin Duerst <duerst@...> 2008/01/07

中村さん、こんにちは。

[#32955] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32959] Re: Shift_JIS variants and UTF-16 support — "NARUSE, Yui" <naruse@...> 2008/01/07

成瀬です。

[#32960] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32992] ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...>

成瀬です。

18 messages 2008/01/08
[#32994] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/09

まつもと ゆきひろです

[#32995] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Martin Duerst <duerst@...> 2008/01/09

At 18:13 08/01/09, Yukihiro Matsumoto wrote:

[#33011] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33012] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33014] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33015] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33239] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Tanaka Akira <akr@...>

In article <200801210259.m0L2x3CW017171@ci.ruby-lang.org>,

11 messages 2008/01/21
[#33240] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Nobuyoshi Nakada <nobu@...> 2008/01/21

なかだです。

[#33303] Time#strftimeのエンコーディング — rubikitch@...

るびきちです。

13 messages 2008/01/23
[#33305] Re: Time#strftimeのエンコーディング — Yukihiro Matsumoto <matz@...> 2008/01/23

まつもと ゆきひろです

[#33368] summary of script encoding — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/25
[#33375] Re: summary of script encoding — Yukihiro Matsumoto <matz@...> 2008/01/25

まつもと ゆきひろです

[#33376] Re: summary of script encoding — "U.Nakamura" <usa@...> 2008/01/25

こんにちは、なかむら(う)です。

[#33387] HashからStructを作る — rubikitch@...

るびきちです。

19 messages 2008/01/25
[#33455] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/28

まつもと ゆきひろです

[#33505] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33507] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33508] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33433] Win32OLE: set encoding to OLE string — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

16 messages 2008/01/28

[#33461] Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...>

=1B$B?9ED$H?=3D$7$^$9!#=1B(B

19 messages 2008/01/28
[#33473] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/28

なかだです。

[#33503] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/29

森田です。

[#33514] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/29

なかだです。

[#33518] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/30

森田です。

[#33545] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野竜太郎と申します。

[#33546] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33547] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野です。

[#33551] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33488] 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

20 messages 2008/01/29
[#33491] Re: 現在の script encoding の値を得る方法は? — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33500] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/29

永井@知能.九工大です.

[#33501] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/29

成瀬です。

[#33515] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33516] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[#33519] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33522] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[ruby-dev:33271] Re: default encoding for Marshal.load

From: Nobuyoshi Nakada <nobu@...>
Date: 2008-01-22 00:05:26 UTC
List: ruby-dev #33271
なかだです。

At Tue, 22 Jan 2008 04:59:27 +0900,
NARUSE, Yui wrote in [ruby-dev:33268]:
> Marlshal.recursive_force_encoding とかいう「データ中の文字列をたどって
> force_encoding する」メソッドがあったら楽だろうと思ったんですが、すごい
> 面倒そうだったので [ruby-dev:33205] の「dumpの入力データのエンコーディン
> グにする」を書いてみました。

> @@ -968,7 +969,7 @@ r_bytes0(long len, struct load_arg *arg)
>      if (len == 0) return rb_str_new(0, 0);
>      if (TYPE(arg->src) == T_STRING) {
>         if (RSTRING_LEN(arg->src) - arg->offset >= len) {
> -           str = rb_str_new(RSTRING_PTR(arg->src)+arg->offset, len);
> +           str = rb_enc_str_new(RSTRING_PTR(arg->src)+arg->offset, len, arg->enc);

String限定なら、ここでrb_str_subseq()を使うだけでもできます。

それ以外のときが問題で、IO#read(length)は常にASCII-8BITを返すの
で入力から調べることもできません。IOにもrb_enc_get()で取れるよう
にエンコーディングをセットしておけば簡単なんですけど。

> この arg.enc に encoding をつっこむ方法が何かあれば明示的に指定できるの
> ですが、まぁ、これで事実上問題ないのではないでしょうか。

引数なしのMarshal.loadがMarshal::Loaderオブジェクトを返す、とか
でしょうか。


Index: marshal.c
===================================================================
--- marshal.c	(revision 15163)
+++ marshal.c	(working copy)
@@ -81,5 +81,5 @@ shortlen(long len, BDIGIT *ds)
 static ID s_dump, s_load, s_mdump, s_mload;
 static ID s_dump_data, s_load_data, s_alloc;
-static ID s_getc, s_read, s_write, s_binmode;
+static ID s_getc, s_read, s_write, s_binmode, s_external_encoding;
 
 ID rb_id_encoding(void);
@@ -883,4 +883,5 @@ struct load_arg {
     st_table *compat_tbl;
     VALUE compat_tbl_wrapper;
+    rb_encoding *enc;
 };
 
@@ -966,5 +967,5 @@ r_bytes0(long len, struct load_arg *arg)
     VALUE str;
 
-    if (len == 0) return rb_str_new(0, 0);
+    if (len == 0) return rb_enc_str_new(0, 0, arg->enc);
     if (TYPE(arg->src) == T_STRING) {
 	if (RSTRING_LEN(arg->src) - arg->offset >= len) {
@@ -986,4 +987,5 @@ r_bytes0(long len, struct load_arg *arg)
 	if (OBJ_TAINTED(str)) arg->taint = Qtrue;
     }
+    rb_enc_associate(str, arg->enc);
     return str;
 }
@@ -1553,7 +1555,9 @@ marshal_load(int argc, VALUE *argv)
 
     rb_scan_args(argc, argv, "11", &port, &proc);
+    arg.enc = 0;
     if (rb_respond_to(port, rb_intern("to_str"))) {
 	arg.taint = OBJ_TAINTED(port); /* original taintedness */
 	StringValue(port);	       /* possible conversion */
+	arg.enc = rb_enc_get(port);
     }
     else if (rb_respond_to(port, s_getc) && rb_respond_to(port, s_read)) {
@@ -1561,4 +1565,9 @@ marshal_load(int argc, VALUE *argv)
 	    rb_funcall2(port, s_binmode, 0, 0);
 	}
+	if (rb_respond_to(port, s_external_encoding)) {
+	    VALUE enc = rb_funcall2(port, s_external_encoding, 0, 0);
+	    rb_p(enc);
+	    arg.enc = rb_to_encoding(enc);
+	}
 	arg.taint = Qtrue;
     }
@@ -1642,4 +1651,5 @@ Init_marshal(void)
     s_write = rb_intern("write");
     s_binmode = rb_intern("binmode");
+    s_external_encoding = rb_intern("external_encoding");
 
     rb_define_module_function(rb_mMarshal, "dump", marshal_dump, -1);


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread