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

ruby-changes:27854

From: naruse <ko1@a...>
Date: Sun, 24 Mar 2013 22:19:05 +0900 (JST)
Subject: [ruby-changes:27854] naruse:r39906 (trunk): * string.c (rb_str_rpartition): revert r39903, and convert byte offset

naruse	2013-03-24 22:18:54 +0900 (Sun, 24 Mar 2013)

  New Revision: 39906

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

  Log:
    * string.c (rb_str_rpartition): revert r39903, and convert byte offset
      to char offset; the return value of rb_reg_search is byte offset,
      but other than it of rb_str_rpartition expects char offset.
      [Bug #8138] [ruby-dev:47183]

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39905)
+++ ChangeLog	(revision 39906)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Mar 24 22:13:51 2013  NARUSE, Yui  <naruse@r...>
+
+	* string.c (rb_str_rpartition): revert r39903, and convert byte offset
+	  to char offset; the return value of rb_reg_search is byte offset,
+	  but other than it of rb_str_rpartition expects char offset.
+	  [Bug #8138] [ruby-dev:47183]
+
 Sun Mar 24 18:29:46 2013  Akinori MUSHA  <knu@i...>
 
 	* string.c (rb_str_rpartition): Fix String#rpartition(/re/)
Index: re.c
===================================================================
--- re.c	(revision 39905)
+++ re.c	(revision 39906)
@@ -1348,6 +1348,7 @@ rb_reg_adjust_startpos(VALUE re, VALUE s https://github.com/ruby/ruby/blob/trunk/re.c#L1348
     return pos;
 }
 
+/* returns byte offset */
 long
 rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
 {
Index: string.c
===================================================================
--- string.c	(revision 39905)
+++ string.c	(revision 39906)
@@ -7522,6 +7522,7 @@ rb_str_rpartition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L7522
 
     if (RB_TYPE_P(sep, T_REGEXP)) {
 	pos = rb_reg_search(sep, str, pos, 1);
+	pos = rb_str_sublen(str, pos);
 	regex = TRUE;
     }
     else {
@@ -7542,10 +7543,9 @@ rb_str_rpartition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L7543
     if (regex) {
 	sep = rb_reg_nth_match(0, rb_backref_get());
     }
-    return rb_ary_new3(3, rb_str_subseq(str, 0, pos),
+    return rb_ary_new3(3, rb_str_substr(str, 0, pos),
 		          sep,
-		          rb_str_subseq(str, pos+RSTRING_LEN(sep),
-					     RSTRING_LEN(str)-pos-RSTRING_LEN(sep)));
+			  rb_str_substr(str,pos+str_strlen(sep,STR_ENC_GET(sep)),RSTRING_LEN(str)));
 }
 
 /*

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

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