[#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:33400] /#{}/e.encoding

From: Tanaka Akira <akr@...>
Date: 2008-01-26 03:14:00 UTC
List: ruby-dev #33400
以下のように /#{}/e の encoding が US-ASCII になります。

  % ./ruby -ve 'p(/#{}/e.encoding)'
  ruby 1.9.0 (2008-01-26 revision 15237) [i686-linux]
  #<Encoding:US-ASCII>

正規表現のソースを構成する文字列の連結時に EUC-JP な
encoding が消えてしまうのが理由なようです。

もともとこの連結に単なる文字列連結を使うのは、エスケープされ
た中途半端な非 ASCII 文字が連結されて中途半端でないものにな
るのを検出できないという問題があります。なので、
Regexp.preprocess というメソッドを新設して、そこで連結を行い、
エンコーディングの伝播も以前同様ににされるようにしてみました。

Index: re.c
===================================================================
--- re.c	(revision 15249)
+++ re.c	(working copy)
@@ -1942,36 +1942,51 @@ rb_reg_check_preprocess(VALUE str)
     return Qnil;
 }
 
-#if 0
 static VALUE
-rb_reg_preprocess_obj(VALUE str,
-        rb_encoding **fixed_enc, onig_errmsg_buffer err)
+rb_reg_preprocess_m(int argc, VALUE *argv, VALUE klass)
 {
-    VALUE buf;
-    char *p, *end;
-    rb_encoding *enc;
+    rb_encoding *fixed_enc = 0;
+    onig_errmsg_buffer err = "";
+    int i;
+    VALUE result = 0;
 
-    StringValue(str);
-    p = RSTRING_PTR(str);
-    end = p + RSTRING_LEN(str);
-    enc = rb_enc_get(str);
+    if (argc == 0) {
+        rb_raise(rb_eArgError, "no arguments given");
+    }
 
-    buf = rb_reg_preprocess(p, end, enc, fixed_enc, err);
-    RB_GC_GUARD(str);
-    return buf;
-}
+    for (i = 0; i < argc; i++) {
+        VALUE str = argv[i];
+        VALUE buf;
+        char *p, *end;
+        rb_encoding *enc;
+
+        StringValue(str);
+        p = RSTRING_PTR(str);
+        end = p + RSTRING_LEN(str);
+        enc = rb_enc_get(str);
+
+        buf = rb_reg_preprocess(p, end, enc, &fixed_enc, err);
+        RB_GC_GUARD(str);
+
+        if (buf == Qnil)
+            rb_raise(rb_eArgError, "%s", err);
+
+        if (i == 0) {
+            /* The encoding of the first fragment is the encoding 
+             * given by the regexp option or script encoding. */
+            if (fixed_enc == 0) {
+                rb_enc_copy(buf, str);
+            }
+        }
 
-static VALUE
-rb_reg_preprocess_m(VALUE klass, VALUE obj)
-{
-    rb_encoding *fixed_enc = 0;
-    onig_errmsg_buffer err = "";
-    VALUE str = rb_reg_preprocess_obj(obj, &fixed_enc, err);
-    if (str == Qnil)
-        rb_raise(rb_eArgError, "%s", err);
-    return rb_assoc_new(str, fixed_enc ? Qtrue : Qfalse);
+        if (!result)
+            result = buf;
+        else
+            rb_str_buf_append(result, buf);
+    }
+
+    return result;
 }
-#endif
 
 static int
 rb_reg_initialize(VALUE obj, const char *s, int len, rb_encoding *enc,
@@ -3035,9 +3050,7 @@ Init_Regexp(void)
     rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
     rb_define_singleton_method(rb_cRegexp, "try_convert", rb_reg_s_try_convert, 1);
 
-#if 0
-    rb_define_singleton_method(rb_cRegexp, "preprocess", rb_reg_preprocess_m, 1);
-#endif
+    rb_define_singleton_method(rb_cRegexp, "preprocess", rb_reg_preprocess_m, -1);
 
     rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
     rb_define_method(rb_cRegexp, "initialize_copy", rb_reg_init_copy, 1);
Index: compile.c
===================================================================
--- compile.c	(revision 15249)
+++ compile.c	(working copy)
@@ -1848,7 +1848,7 @@ iseq_set_sequence_stackcaching(rb_iseq_t
 
 
 static int
-compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node)
+compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int *cntp)
 {
     NODE *list = node->nd_next;
     VALUE lit = node->nd_lit;
@@ -1862,12 +1862,31 @@ compile_dstr(rb_iseq_t *iseq, LINK_ANCHO
 	cnt++;
 	list = list->nd_next;
     }
+    *cntp = cnt;
+
+    return COMPILE_OK;
+}
 
+static int
+compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node)
+{
+    int cnt;
+    compile_dstr_fragments(iseq, ret, node, &cnt);
     ADD_INSN1(ret, nd_line(node), concatstrings, INT2FIX(cnt));
     return COMPILE_OK;
 }
 
 static int
+compile_dregx(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node)
+{
+    int cnt;
+    ADD_INSN1(ret, nd_line(node), putobject, rb_cRegexp);
+    compile_dstr_fragments(iseq, ret, node, &cnt);
+    ADD_SEND(ret, nd_line(node), ID2SYM(rb_intern("preprocess")), INT2FIX(cnt));
+    return COMPILE_OK;
+}
+
+static int
 compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond,
 			 LABEL *then_label, LABEL *else_label)
 {
@@ -4077,7 +4096,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_
 	break;
       }
       case NODE_DREGX:{
-	compile_dstr(iseq, ret, node);
+	compile_dregx(iseq, ret, node);
 	ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag));
 
 	if (poped) {
@@ -4094,7 +4113,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_
 	ADD_INSN2(ret, nd_line(node), onceinlinecache, 0, lend);
 	ADD_INSN(ret, nd_line(node), pop);
 
-	compile_dstr(iseq, ret, node);
+	compile_dregx(iseq, ret, node);
 	ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag));
 
 	ADD_INSN1(ret, nd_line(node), setinlinecache, lstart);
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 15249)
+++ test/ruby/test_m17n.rb	(working copy)
@@ -428,14 +428,14 @@ class TestM17N < Test::Unit::TestCase
     assert_raise(ArgumentError) { eval(s("/\#{r}\xc2\xa1/s")) }
 
     r = /\xc2\xa1/e
-    #assert_raise(ArgumentError) { eval(s("/\xc2\xa1\#{r}/s")) }
-    #assert_raise(ArgumentError) { eval(s("/\#{r}\xc2\xa1/s")) }
+    assert_raise(ArgumentError) { eval(s("/\xc2\xa1\#{r}/s")) }
+    assert_raise(ArgumentError) { eval(s("/\#{r}\xc2\xa1/s")) }
 
     r = eval(e("/\xc2\xa1/"))
-    #assert_raise(ArgumentError) { /\xc2\xa1#{r}/s }
+    assert_raise(ArgumentError) { /\xc2\xa1#{r}/s }
 
     r = /\xc2\xa1/e
-    #assert_raise(ArgumentError) { /\xc2\xa1#{r}/s }
+    assert_raise(ArgumentError) { /\xc2\xa1#{r}/s }
   end
 
   def test_begin_end_offset
@@ -560,7 +560,7 @@ class TestM17N < Test::Unit::TestCase
     }
     assert_regexp_fixed_ascii8bit(/#{}\xc2\xa1/n)
     assert_regexp_fixed_ascii8bit(/\xc2\xa1#{}/n)
-    #assert_raise(SyntaxError) { s1, s2 = s('\xc2'), s('\xa1'); /#{s1}#{s2}/ }
+    assert_nothing_raised { s1, s2 = a('\xc2'), a('\xa1'); /#{s1}#{s2}/ }
   end
 
   def test_dynamic_eucjp_regexp
@@ -570,7 +570,7 @@ class TestM17N < Test::Unit::TestCase
     assert_raise(SyntaxError) { eval('/\xc2#{}/e') }
     assert_raise(SyntaxError) { eval('/#{}\xc2/e') }
     assert_raise(SyntaxError) { eval('/\xc2#{}\xa1/e') }
-    #assert_raise(SyntaxError) { s1, s2 = e('\xc2'), e('\xa1'); /#{s1}#{s2}/ }
+    assert_raise(ArgumentError) { s1, s2 = e('\xc2'), e('\xa1'); /#{s1}#{s2}/ }
   end
 
   def test_dynamic_sjis_regexp
@@ -580,7 +580,7 @@ class TestM17N < Test::Unit::TestCase
     assert_raise(SyntaxError) { eval('/\x81#{}/s') }
     assert_raise(SyntaxError) { eval('/#{}\x81/s') }
     assert_raise(SyntaxError) { eval('/\x81#{}\xa1/s') }
-    #assert_raise(SyntaxError) { s1, s2 = s('\x81'), s('\xa1'); /#{s1}#{s2}/ }
+    assert_raise(ArgumentError) { s1, s2 = s('\x81'), s('\xa1'); /#{s1}#{s2}/ }
   end
 
   def test_dynamic_utf8_regexp
@@ -590,7 +590,7 @@ class TestM17N < Test::Unit::TestCase
     assert_raise(SyntaxError) { eval('/\xc2#{}/u') }
     assert_raise(SyntaxError) { eval('/#{}\xc2/u') }
     assert_raise(SyntaxError) { eval('/\xc2#{}\xa1/u') }
-    #assert_raise(SyntaxError) { s1, s2 = u('\xc2'), u('\xa1'); /#{s1}#{s2}/ }
+    assert_raise(ArgumentError) { s1, s2 = u('\xc2'), u('\xa1'); /#{s1}#{s2}/ }
   end
 
   def test_regexp_unicode
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread

Prev Next