1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/strscan/strscan.c (strscan_do_scan): should set kcode option before match. [ruby-dev:29914]

* test/strscan/test_stringscanner.rb: test it.
* re.c: export kcode_set_option and kcode_reset_option (with "rb_" prefix).
* intern.h: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11524 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2007-01-10 09:59:11 +00:00
parent d158c31683
commit 2785c7c05f
5 changed files with 46 additions and 17 deletions

View file

@ -1,3 +1,15 @@
Wed Jan 10 18:57:57 2007 Minero Aoki <aamine@loveruby.net>
* ext/strscan/strscan.c (strscan_do_scan): should set kcode option
before match. [ruby-dev:29914]
* test/strscan/test_stringscanner.rb: test it.
* re.c: export kcode_set_option and kcode_reset_option (with "rb_"
prefix).
* intern.h: ditto.
Tue Jan 9 17:45:17 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (rb_find_file): should not call fpath_check() with NULL.

View file

@ -403,6 +403,7 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
if (S_RESTLEN(p) < 0) {
return Qnil;
}
rb_kcode_set_option(regex);
if (headonly) {
ret = re_match(RREGEXP(regex)->ptr,
CURPTR(p), S_RESTLEN(p),
@ -416,6 +417,7 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
S_RESTLEN(p),
&(p->regs));
}
rb_kcode_reset_option();
if (ret == -2) rb_raise(ScanError, "regexp buffer overflow");
if (ret < 0) {

View file

@ -370,6 +370,8 @@ VALUE rb_reg_match2 _((VALUE));
int rb_reg_options _((VALUE));
void rb_set_kcode _((const char*));
const char* rb_get_kcode _((void));
void rb_kcode_set_option _((VALUE));
void rb_kcode_reset_option _((void));
/* ruby.c */
RUBY_EXTERN VALUE rb_argv;
RUBY_EXTERN VALUE rb_argv0;

34
re.c
View file

@ -200,8 +200,8 @@ kcode_none(re)
static int curr_kcode;
static void
kcode_set_option(re)
void
rb_kcode_set_option(re)
VALUE re;
{
if (!FL_TEST(re, KCODE_FIXED)) return;
@ -224,8 +224,8 @@ kcode_set_option(re)
}
}
static void
kcode_reset_option()
void
rb_kcode_reset_option()
{
if (reg_kcode == curr_kcode) return;
switch (reg_kcode) {
@ -253,9 +253,9 @@ rb_reg_mbclen2(c, re)
if (!FL_TEST(re, KCODE_FIXED))
return mbclen(c);
kcode_set_option(re);
rb_kcode_set_option(re);
len = mbclen(c);
kcode_reset_option();
rb_kcode_reset_option();
return len;
}
@ -486,11 +486,11 @@ rb_reg_to_s(re)
}
if (*ptr == ':' && ptr[len-1] == ')') {
Regexp *rp;
kcode_set_option(re);
rb_kcode_set_option(re);
rp = ALLOC(Regexp);
MEMZERO((char *)rp, Regexp, 1);
err = re_compile_pattern(++ptr, len -= 2, rp) != 0;
kcode_reset_option();
rb_kcode_reset_option();
re_free_pattern(rp);
}
if (err) {
@ -849,7 +849,7 @@ rb_reg_prepare_re(re)
char *err;
if (FL_TEST(re, KCODE_FIXED))
kcode_set_option(re);
rb_kcode_set_option(re);
rb_reg_check(re);
RREGEXP(re)->ptr->fastmap_accurate = 0;
err = re_compile_pattern(RREGEXP(re)->str, RREGEXP(re)->len, RREGEXP(re)->ptr);
@ -870,9 +870,9 @@ rb_reg_adjust_startpos(re, str, pos, reverse)
if (may_need_recompile) rb_reg_prepare_re(re);
if (FL_TEST(re, KCODE_FIXED))
kcode_set_option(re);
rb_kcode_set_option(re);
else if (reg_kcode != curr_kcode)
kcode_reset_option();
rb_kcode_reset_option();
if (reverse) {
range = -pos;
@ -904,9 +904,9 @@ rb_reg_search(re, str, pos, reverse)
if (may_need_recompile) rb_reg_prepare_re(re);
if (FL_TEST(re, KCODE_FIXED))
kcode_set_option(re);
rb_kcode_set_option(re);
else if (reg_kcode != curr_kcode)
kcode_reset_option();
rb_kcode_reset_option();
if (reverse) {
range = -pos;
@ -918,7 +918,7 @@ rb_reg_search(re, str, pos, reverse)
pos, range, &regs);
if (FL_TEST(re, KCODE_FIXED))
kcode_reset_option();
rb_kcode_reset_option();
if (result == -2) {
rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len,
@ -1364,7 +1364,7 @@ rb_reg_initialize(obj, s, len, options)
}
if (options & ~0xf) {
kcode_set_option((VALUE)re);
rb_kcode_set_option((VALUE)re);
}
if (ruby_ignorecase) {
options |= RE_OPTION_IGNORECASE;
@ -1376,7 +1376,7 @@ rb_reg_initialize(obj, s, len, options)
re->str[len] = '\0';
re->len = len;
if (options & ~0xf) {
kcode_reset_option();
rb_kcode_reset_option();
}
if (ruby_in_compile) FL_SET(obj, REG_LITERAL);
}
@ -1839,7 +1839,7 @@ rb_reg_s_quote(argc, argv)
}
StringValue(str);
str = rb_reg_quote(str);
kcode_reset_option();
rb_kcode_reset_option();
return str;
}

View file

@ -247,6 +247,19 @@ class TestStringScanner < Test::Unit::TestCase
s = StringScanner.new("")
assert_equal "", s.scan(//)
assert_equal "", s.scan(//)
# [ruby-dev:29914]
%w( NONE EUC SJIS UTF8 ).each do |kcode|
begin
$KCODE = kcode
assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/n)
assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/e)
assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/s)
assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/u)
ensure
$KCODE = 'NONE'
end
end
end
def test_skip