зеркало из https://github.com/github/ruby.git
* re.c (rb_reg_prepare_re): made non static with small refactoring.
* ext/strscan/strscan.c (strscan_do_scan): should adjust encoding before regex searching. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
b15fe02d19
Коммит
ab24f2b077
|
@ -1,3 +1,10 @@
|
|||
Mon May 12 15:04:58 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* re.c (rb_reg_prepare_re): made non static with small refactoring.
|
||||
|
||||
* ext/strscan/strscan.c (strscan_do_scan): should adjust encoding
|
||||
before regex searching.
|
||||
|
||||
Mon May 12 13:57:19 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (is_defined): add NODE_OP_ASGN_{OR,AND}. "defined?(a||=1)"
|
||||
|
|
|
@ -403,7 +403,9 @@ strscan_set_pos(VALUE self, VALUE v)
|
|||
static VALUE
|
||||
strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
|
||||
{
|
||||
regex_t *rb_reg_prepare_re(VALUE re, VALUE str);
|
||||
struct strscanner *p;
|
||||
regex_t *re;
|
||||
int ret;
|
||||
|
||||
Check_Type(regex, T_REGEXP);
|
||||
|
@ -413,13 +415,14 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
|
|||
if (S_RESTLEN(p) < 0) {
|
||||
return Qnil;
|
||||
}
|
||||
re = rb_reg_prepare_re(regex, p->str);
|
||||
if (headonly) {
|
||||
ret = onig_match(RREGEXP(regex)->ptr, (UChar* )CURPTR(p),
|
||||
ret = onig_match(re, (UChar* )CURPTR(p),
|
||||
(UChar* )(CURPTR(p) + S_RESTLEN(p)),
|
||||
(UChar* )CURPTR(p), &(p->regs), ONIG_OPTION_NONE);
|
||||
}
|
||||
else {
|
||||
ret = onig_search(RREGEXP(regex)->ptr,
|
||||
ret = onig_search(re,
|
||||
(UChar* )CURPTR(p), (UChar* )(CURPTR(p) + S_RESTLEN(p)),
|
||||
(UChar* )CURPTR(p), (UChar* )(CURPTR(p) + S_RESTLEN(p)),
|
||||
&(p->regs), ONIG_OPTION_NONE);
|
||||
|
|
7
re.c
7
re.c
|
@ -1181,8 +1181,8 @@ rb_reg_prepare_enc(VALUE re, VALUE str, int warn)
|
|||
return RREGEXP(re)->ptr->enc;
|
||||
}
|
||||
|
||||
static regex_t *
|
||||
rb_reg_prepare_re(VALUE re, rb_encoding *enc)
|
||||
regex_t *
|
||||
rb_reg_prepare_re(VALUE re, VALUE str)
|
||||
{
|
||||
regex_t *reg = RREGEXP(re)->ptr;
|
||||
onig_errmsg_buffer err = "";
|
||||
|
@ -1191,6 +1191,7 @@ rb_reg_prepare_re(VALUE re, rb_encoding *enc)
|
|||
const char *pattern;
|
||||
VALUE unescaped;
|
||||
rb_encoding *fixed_enc = 0;
|
||||
rb_encoding *enc = rb_reg_prepare_enc(re, str, 1);
|
||||
|
||||
if (reg->enc == enc) return reg;
|
||||
|
||||
|
@ -1265,7 +1266,7 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
|
|||
return -1;
|
||||
}
|
||||
|
||||
reg = rb_reg_prepare_re(re, rb_reg_prepare_enc(re, str, 1));
|
||||
reg = rb_reg_prepare_re(re, str);
|
||||
|
||||
FL_SET(re, REG_BUSY);
|
||||
if (!reverse) {
|
||||
|
|
|
@ -545,7 +545,7 @@ class TestStringScanner < Test::Unit::TestCase
|
|||
def test_generic_regexp
|
||||
ss = StringScanner.new("\xA1\xA2".force_encoding("euc-jp"))
|
||||
t = ss.scan(/./)
|
||||
assert_equal("\xa1\xa1".force_encoding("euc-jp"), t)
|
||||
assert_equal("\xa1\xa2".force_encoding("euc-jp"), t)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче