mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
050a10c607
commit
d73f08d56d
3 changed files with 33 additions and 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>
|
Fri Nov 23 10:44:24 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* compile.c (defined_expr): defined(method(x)) dumped core. a
|
* compile.c (defined_expr): defined(method(x)) dumped core. a
|
||||||
|
|
|
@ -37,9 +37,9 @@ struct RMatch {
|
||||||
#define RMATCH(obj) (R_CAST(RMatch)(obj))
|
#define RMATCH(obj) (R_CAST(RMatch)(obj))
|
||||||
|
|
||||||
VALUE rb_reg_regcomp(VALUE);
|
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);
|
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);
|
void rb_match_busy(VALUE);
|
||||||
VALUE rb_reg_quote(VALUE);
|
VALUE rb_reg_quote(VALUE);
|
||||||
|
|
||||||
|
|
34
re.c
34
re.c
|
@ -608,6 +608,15 @@ match_size(VALUE match)
|
||||||
return INT2FIX(RMATCH(match)->regs->num_regs);
|
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:
|
* call-seq:
|
||||||
|
@ -632,8 +641,8 @@ match_offset(VALUE match, VALUE n)
|
||||||
if (RMATCH(match)->regs->beg[i] < 0)
|
if (RMATCH(match)->regs->beg[i] < 0)
|
||||||
return rb_assoc_new(Qnil, Qnil);
|
return rb_assoc_new(Qnil, Qnil);
|
||||||
|
|
||||||
return rb_assoc_new(INT2FIX(RMATCH(match)->regs->beg[i]),
|
return rb_assoc_new(match_sublen(RMATCH(match)->str, RMATCH(match)->regs->beg[i]),
|
||||||
INT2FIX(RMATCH(match)->regs->end[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)
|
if (RMATCH(match)->regs->beg[i] < 0)
|
||||||
return Qnil;
|
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)
|
if (RMATCH(match)->regs->beg[i] < 0)
|
||||||
return Qnil;
|
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
|
#define MATCH_BUSY FL_USER2
|
||||||
|
@ -739,10 +748,10 @@ rb_reg_prepare_re(VALUE re, VALUE str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
int
|
||||||
rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, long reverse)
|
rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, int reverse)
|
||||||
{
|
{
|
||||||
long range;
|
int range;
|
||||||
OnigEncoding enc;
|
OnigEncoding enc;
|
||||||
UChar *p, *string;
|
UChar *p, *string;
|
||||||
|
|
||||||
|
@ -773,13 +782,13 @@ rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, long reverse)
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
int
|
||||||
rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
|
rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
|
||||||
{
|
{
|
||||||
long result;
|
int result;
|
||||||
VALUE match;
|
VALUE match;
|
||||||
static struct re_registers regs;
|
static struct re_registers regs;
|
||||||
long range;
|
int range;
|
||||||
|
|
||||||
if (pos > RSTRING_LEN(str) || pos < 0) {
|
if (pos > RSTRING_LEN(str) || pos < 0) {
|
||||||
rb_backref_set(Qnil);
|
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, re);
|
||||||
OBJ_INFECT(match, str);
|
OBJ_INFECT(match, str);
|
||||||
return result;
|
|
||||||
|
return rb_str_sublen(RMATCH(match)->str, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue