From d73f08d56d92de1ad41abb877c2f9ed6c8c15d76 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 23 Nov 2007 02:10:44 +0000 Subject: * re.c (match_begin): should return offset by character. [ruby-dev:32331] * re.c (match_end): ditto. * re.c (rb_reg_search): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ include/ruby/re.h | 4 ++-- re.c | 34 ++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b2e841352..e36ef903fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Nov 23 11:01:54 2007 Yukihiro Matsumoto + + * 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 * compile.c (defined_expr): defined(method(x)) dumped core. a diff --git a/include/ruby/re.h b/include/ruby/re.h index 6fd0609e7a..3b8c6c5d74 100644 --- a/include/ruby/re.h +++ b/include/ruby/re.h @@ -37,9 +37,9 @@ struct RMatch { #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); diff --git a/re.c b/re.c index 573fb2ee3b..4e915f6f78 100644 --- a/re.c +++ b/re.c @@ -608,6 +608,15 @@ match_size(VALUE match) 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: @@ -632,8 +641,8 @@ match_offset(VALUE match, VALUE n) 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 @@ match_begin(VALUE match, VALUE n) 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 @@ match_end(VALUE match, VALUE n) 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 @@ rb_reg_prepare_re(VALUE re, VALUE str) } } -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 @@ rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, long reverse) 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 @@ rb_reg_search(VALUE re, VALUE str, long pos, long reverse) OBJ_INFECT(match, re); OBJ_INFECT(match, str); - return result; + + return rb_str_sublen(RMATCH(match)->str, result); } VALUE -- cgit v1.2.3