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

ruby-changes:17326

From: naruse <ko1@a...>
Date: Fri, 24 Sep 2010 15:28:41 +0900 (JST)
Subject: [ruby-changes:17326] Ruby:r29331 (trunk): * string.c (rb_str_rindex): use rb_enc_prev_char instead of repeated str_nth.

naruse	2010-09-24 15:28:35 +0900 (Fri, 24 Sep 2010)

  New Revision: 29331

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

  Log:
    * string.c (rb_str_rindex): use rb_enc_prev_char instead of repeated str_nth.
      patched by Michael Selig [ruby-core:32498]

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29330)
+++ ChangeLog	(revision 29331)
@@ -1,3 +1,8 @@
+2010-09-24  NARUSE, Yui  <naruse@r...>
+
+	* string.c (rb_str_rindex): use rb_enc_prev_char instead of repeated str_nth.
+	  patched by Michael Selig [ruby-core:32498]
+
 Fri Sep 24 14:19:12 2010  URABE Shyouhei  <shyouhei@r...>
 
 	* test/test_pty.rb: Same as 229281; existence of PTY class do not
Index: string.c
===================================================================
--- string.c	(revision 29330)
+++ string.c	(revision 29331)
@@ -2488,14 +2488,14 @@
     e = RSTRING_END(str);
     t = RSTRING_PTR(sub);
     slen = RSTRING_LEN(sub);
-    for (;;) {
-	s = str_nth(sbeg, e, pos, enc, singlebyte);
-	if (!s) return -1;
+    s = str_nth(sbeg, e, pos, enc, singlebyte);
+    while (s) {
 	if (memcmp(s, t, slen) == 0) {
 	    return pos;
 	}
 	if (pos == 0) break;
 	pos--;
+	s = rb_enc_prev_char(sbeg, s, e, enc);
     }
     return -1;
 }

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

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