[前][次][番号順一覧][スレッド一覧]

ruby-changes:6368

From: akr <ko1@a...>
Date: Sat, 5 Jul 2008 08:50:51 +0900 (JST)
Subject: [ruby-changes:6368] Ruby:r17884 (trunk): * re.c (unescape_nonascii): add has_property argument not to

akr	2008-07-05 08:50:33 +0900 (Sat, 05 Jul 2008)

  New Revision: 17884

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_m17n.rb

  Log:
    * re.c (unescape_nonascii): add has_property argument not to
      raise error by /\p{Hiragana}\u{3042}/ in EUC-JP script.
      (rb_reg_preprocess): use has_property argument to make regexp
      encoding fixed.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17884

Index: re.c
===================================================================
--- re.c	(revision 17883)
+++ re.c	(revision 17884)
@@ -2085,7 +2085,8 @@
 
 static int
 unescape_nonascii(const char *p, const char *end, rb_encoding *enc,
-        VALUE buf, rb_encoding **encp, onig_errmsg_buffer err)
+        VALUE buf, rb_encoding **encp, int *has_property,
+        onig_errmsg_buffer err)
 {
     char c;
     char smallbuf[2];
@@ -2165,7 +2166,7 @@
 
               case 'p': /* \p{Hiragana} */
                 if (!*encp) {
-                    *encp = enc;
+                    *has_property = 1;
                 }
                 goto escape_asis;
 
@@ -2192,6 +2193,7 @@
         rb_encoding **fixed_enc, onig_errmsg_buffer err)
 {
     VALUE buf;
+    int has_property = 0;
 
     buf = rb_str_buf_new(0);
 
@@ -2202,9 +2204,13 @@
         rb_enc_associate(buf, enc);
     }
 
-    if (unescape_nonascii(p, end, enc, buf, fixed_enc, err) != 0)
+    if (unescape_nonascii(p, end, enc, buf, fixed_enc, &has_property, err) != 0)
         return Qnil;
 
+    if (has_property && !*fixed_enc) {
+        *fixed_enc = enc;
+    }
+
     if (*fixed_enc) {
         rb_enc_associate(buf, *fixed_enc);
     }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17883)
+++ ChangeLog	(revision 17884)
@@ -1,3 +1,10 @@
+Sat Jul  5 08:48:05 2008  Tanaka Akira  <akr@f...>
+
+	* re.c (unescape_nonascii): add has_property argument not to
+	  raise error by /\p{Hiragana}\u{3042}/ in EUC-JP script.
+	  (rb_reg_preprocess): use has_property argument to make regexp
+	  encoding fixed.
+
 Sat Jul  5 08:29:47 2008  Tanaka Akira  <akr@f...>
 
 	* re.c (unescape_nonascii): make regexp fixed_encoding if \p is used.
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 17883)
+++ test/ruby/test_m17n.rb	(revision 17884)
@@ -510,6 +510,14 @@
     r = /\p{Hiragana}/e
     assert(r.fixed_encoding?)
     assert_match(r, "\xa4\xa2".force_encoding("euc-jp"))
+
+    r = eval('/\u{3042}\p{Hiragana}/'.force_encoding("euc-jp"))
+    assert(r.fixed_encoding?)
+    assert_equal(Encoding::UTF_8, r.encoding)
+
+    r = eval('/\p{Hiragana}\u{3042}/'.force_encoding("euc-jp"))
+    assert(r.fixed_encoding?)
+    assert_equal(Encoding::UTF_8, r.encoding)
   end
 
   def test_regexp_embed_preprocess

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]