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

ruby-changes:11016

From: nobu <ko1@a...>
Date: Wed, 25 Feb 2009 02:17:46 +0900 (JST)
Subject: [ruby-changes:11016] Ruby:r22606 (trunk): * string.c (rb_str_delete_bang): should recalculate coderange.

nobu	2009-02-25 02:17:35 +0900 (Wed, 25 Feb 2009)

  New Revision: 22606

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

  Log:
    * string.c (rb_str_delete_bang): should recalculate coderange.
      [ruby-talk:329267]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 22605)
+++ ChangeLog	(revision 22606)
@@ -1,3 +1,8 @@
+Wed Feb 25 02:17:30 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_delete_bang): should recalculate coderange.
+	  [ruby-talk:329267]
+
 Wed Feb 25 00:41:21 2009  Akinori MUSHA  <knu@i...>
 
 	* class.c (rb_scan_args): Allow specifying the number of trailing
Index: string.c
===================================================================
--- string.c	(revision 22605)
+++ string.c	(revision 22606)
@@ -1255,7 +1255,12 @@
 {
     VALUE s = *ptr;
     if (TYPE(s) != T_STRING) {
-	s = rb_str_to_str(s);
+	if (SYMBOL_P(s)) {
+	    s = rb_sym_to_s(s);
+	}
+	else {
+	    s = rb_str_to_str(s);
+	}
 	*ptr = s;
     }
     return s;
@@ -5070,7 +5075,7 @@
     char *s, *send, *t;
     VALUE del = 0, nodel = 0;
     int modify = 0;
-    int i, ascompat;
+    int i, ascompat, cr;
 
     if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil;
     if (argc < 1) {
@@ -5088,6 +5093,7 @@
     ascompat = rb_enc_asciicompat(enc);
     s = t = RSTRING_PTR(str);
     send = RSTRING_END(str);
+    cr = ascompat ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
     while (s < send) {
 	unsigned int c;
 	int clen;
@@ -5112,12 +5118,14 @@
 	    else {
 		if (t != s) rb_enc_mbcput(c, t, enc);
 		t += clen;
+		if (cr == ENC_CODERANGE_7BIT) cr = ENC_CODERANGE_VALID;
 	    }
 	    s += clen;
 	}
     }
     *t = '\0';
     STR_SET_LEN(str, t - RSTRING_PTR(str));
+    ENC_CODERANGE_SET(str, cr);
 
     if (modify) return str;
     return Qnil;
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 22605)
+++ test/ruby/test_string.rb	(revision 22606)
@@ -474,6 +474,11 @@
     assert_equal(S("he"),   S("hello").delete(S("lo")))
     assert_equal(S("hell"), S("hello").delete(S("aeiou"), S("^e")))
     assert_equal(S("ho"),   S("hello").delete(S("ej-m")))
+
+    assert_equal("a".hash, "a\u0101".delete("\u0101").hash, '[ruby-talk:329267]')
+    assert_equal(true, "a\u0101".delete("\u0101").ascii_only?)
+    assert_equal(true, "a\u3041".delete("\u3041").ascii_only?)
+    assert_equal(false, "a\u3041\u3042".tr("\u3041", "a").ascii_only?)
   end
 
   def test_delete!

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

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