* re.c (rb_reg_preprocess_dregexp): use non-preprocessed regexp source
for result. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8435c6bb8c
commit
ec4756f633
@ -1,3 +1,8 @@
|
|||||||
|
Thu Feb 14 12:30:02 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* re.c (rb_reg_preprocess_dregexp): use non-preprocessed regexp source
|
||||||
|
for result.
|
||||||
|
|
||||||
Thu Feb 14 01:43:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Feb 14 01:43:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/timeout.rb (Timeout::timeout): made sensitive to location on the
|
* lib/timeout.rb (Timeout::timeout): made sensitive to location on the
|
||||||
|
25
re.c
25
re.c
@ -1953,6 +1953,7 @@ static VALUE
|
|||||||
rb_reg_preprocess_dregexp(VALUE ary)
|
rb_reg_preprocess_dregexp(VALUE ary)
|
||||||
{
|
{
|
||||||
rb_encoding *fixed_enc = 0;
|
rb_encoding *fixed_enc = 0;
|
||||||
|
rb_encoding *regexp_enc = 0;
|
||||||
onig_errmsg_buffer err = "";
|
onig_errmsg_buffer err = "";
|
||||||
int i;
|
int i;
|
||||||
VALUE result = 0;
|
VALUE result = 0;
|
||||||
@ -1967,31 +1968,33 @@ rb_reg_preprocess_dregexp(VALUE ary)
|
|||||||
VALUE str = argv[i];
|
VALUE str = argv[i];
|
||||||
VALUE buf;
|
VALUE buf;
|
||||||
char *p, *end;
|
char *p, *end;
|
||||||
rb_encoding *enc;
|
rb_encoding *src_enc;
|
||||||
|
|
||||||
StringValue(str);
|
StringValue(str);
|
||||||
p = RSTRING_PTR(str);
|
p = RSTRING_PTR(str);
|
||||||
end = p + RSTRING_LEN(str);
|
end = p + RSTRING_LEN(str);
|
||||||
enc = rb_enc_get(str);
|
src_enc = rb_enc_get(str);
|
||||||
|
|
||||||
buf = rb_reg_preprocess(p, end, enc, &fixed_enc, err);
|
buf = rb_reg_preprocess(p, end, src_enc, &fixed_enc, err);
|
||||||
RB_GC_GUARD(str);
|
|
||||||
|
|
||||||
if (buf == Qnil)
|
if (buf == Qnil)
|
||||||
rb_raise(rb_eArgError, "%s", err);
|
rb_raise(rb_eArgError, "%s", err);
|
||||||
|
|
||||||
if (i == 0) {
|
if (fixed_enc != 0) {
|
||||||
/* The encoding of the first fragment is the encoding
|
if (regexp_enc != 0 && regexp_enc != fixed_enc) {
|
||||||
* given by the regexp option or script encoding. */
|
rb_raise(rb_eArgError, "encoding mismatch in dynamic regexp : %s and %s",
|
||||||
if (fixed_enc == 0) {
|
rb_enc_name(regexp_enc), rb_enc_name(fixed_enc));
|
||||||
rb_enc_copy(buf, str);
|
|
||||||
}
|
}
|
||||||
|
regexp_enc = fixed_enc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
result = buf;
|
result = rb_str_new3(str);
|
||||||
else
|
else
|
||||||
rb_str_buf_append(result, buf);
|
rb_str_buf_append(result, str);
|
||||||
|
}
|
||||||
|
if (regexp_enc) {
|
||||||
|
rb_enc_associate(result, regexp_enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -452,6 +452,12 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
assert_raise(ArgumentError) { /\xc2\xa1#{r}/s }
|
assert_raise(ArgumentError) { /\xc2\xa1#{r}/s }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_regexp_embed_preprocess
|
||||||
|
r1 = /\xa4\xa2/e
|
||||||
|
r2 = /#{r1}/
|
||||||
|
assert(r2.source.include?(r1.source))
|
||||||
|
end
|
||||||
|
|
||||||
def test_begin_end_offset
|
def test_begin_end_offset
|
||||||
str = e("\244\242\244\244\244\246\244\250\244\252a")
|
str = e("\244\242\244\244\244\246\244\250\244\252a")
|
||||||
assert(/(a)/ =~ str)
|
assert(/(a)/ =~ str)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user