diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-23 02:10:44 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-23 02:10:44 +0000 |
commit | d73f08d56d92de1ad41abb877c2f9ed6c8c15d76 (patch) | |
tree | 9961f41da837a9d8339d5f60293aa520d6ce0028 | |
parent | 050a10c607e471bb2f387eb9644db5ee9e43c46b (diff) | |
download | ruby-d73f08d56d92de1ad41abb877c2f9ed6c8c15d76.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | include/ruby/re.h | 4 | ||||
-rw-r--r-- | re.c | 34 |
3 files changed, 33 insertions, 14 deletions
@@ -1,3 +1,12 @@ +Fri Nov 23 11:01:54 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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@ruby-lang.org> * 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); @@ -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 |