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

ruby-changes:2508

From: ko1@a...
Date: 23 Nov 2007 11:10:56 +0900
Subject: [ruby-changes:2508] matz - Ruby:r13999 (trunk): * re.c (match_begin): should return offset by character.

matz	2007-11-23 11:10:44 +0900 (Fri, 23 Nov 2007)

  New Revision: 13999

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/re.h
    trunk/re.c

  Log:
    * re.c (match_begin): should return offset by character.
      [ruby-dev:32331]
    
    * re.c (match_end): ditto.
    
    * re.c (rb_reg_search): ditto.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13999&r2=13998
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/re.h?r1=13999&r2=13998
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=13999&r2=13998

Index: include/ruby/re.h
===================================================================
--- include/ruby/re.h	(revision 13998)
+++ include/ruby/re.h	(revision 13999)
@@ -37,9 +37,9 @@
 #define RMATCH(obj)  (R_CAST(RMatch)(obj))
 
 VALUE rb_reg_regcomp(VALUE);
-long rb_reg_search(VALUE, VALUE, long, long);
+int rb_reg_search(VALUE, VALUE, int, int);
 VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE);
-long rb_reg_adjust_startpos(VALUE, VALUE, long, long);
+int rb_reg_adjust_startpos(VALUE, VALUE, int, int);
 void rb_match_busy(VALUE);
 VALUE rb_reg_quote(VALUE);
 
Index: re.c
===================================================================
--- re.c	(revision 13998)
+++ re.c	(revision 13999)
@@ -608,7 +608,16 @@
     return INT2FIX(RMATCH(match)->regs->num_regs);
 }
 
+static VALUE
+match_sublen(VALUE str, int offset)
+{
+    int i;
 
+    i = rb_str_sublen(str, offset);
+    return INT2FIX(i);
+}
+
+
 /*
  *  call-seq:
  *     mtch.offset(n)   => array
@@ -632,8 +641,8 @@
     if (RMATCH(match)->regs->beg[i] < 0)
 	return rb_assoc_new(Qnil, Qnil);
 
-    return rb_assoc_new(INT2FIX(RMATCH(match)->regs->beg[i]),
-			INT2FIX(RMATCH(match)->regs->end[i]));
+    return rb_assoc_new(match_sublen(RMATCH(match)->str, RMATCH(match)->regs->beg[i]),
+			match_sublen(RMATCH(match)->str, RMATCH(match)->regs->end[i]));
 }
 
 
@@ -660,7 +669,7 @@
     if (RMATCH(match)->regs->beg[i] < 0)
 	return Qnil;
 
-    return INT2FIX(RMATCH(match)->regs->beg[i]);
+    return match_sublen(RMATCH(match)->str, RMATCH(match)->regs->beg[i]);
 }
 
 
@@ -687,7 +696,7 @@
     if (RMATCH(match)->regs->beg[i] < 0)
 	return Qnil;
 
-    return INT2FIX(RMATCH(match)->regs->end[i]);
+    return match_sublen(RMATCH(match)->str, RMATCH(match)->regs->end[i]);
 }
 
 #define MATCH_BUSY FL_USER2
@@ -739,10 +748,10 @@
     }
 }
 
-long
-rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, long reverse)
+int
+rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, int reverse)
 {
-    long range;
+    int range;
     OnigEncoding enc;
     UChar *p, *string;
 
@@ -773,13 +782,13 @@
     return pos;
 }
 
-long
-rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
+int
+rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
 {
-    long result;
+    int result;
     VALUE match;
     static struct re_registers regs;
-    long range;
+    int range;
 
     if (pos > RSTRING_LEN(str) || pos < 0) {
 	rb_backref_set(Qnil);
@@ -833,7 +842,8 @@
 
     OBJ_INFECT(match, re);
     OBJ_INFECT(match, str);
-    return result;
+
+    return rb_str_sublen(RMATCH(match)->str, result);
 }
 
 VALUE
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13998)
+++ ChangeLog	(revision 13999)
@@ -1,3 +1,12 @@
+Fri Nov 23 11:01:54 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* re.c (match_begin): should return offset by character.
+	  [ruby-dev:32331]
+
+	* re.c (match_end): ditto.
+
+	* re.c (rb_reg_search): ditto.
+
 Fri Nov 23 10:44:24 2007  Yukihiro Matsumoto  <matz@r...>
 
 	* compile.c (defined_expr): defined(method(x)) dumped core.  a

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

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