e$B@.@%$G$9!#e(B
e$B35MW$O@hF|$^$D$b$H$5$s$KOC$7$^$7$?$,!"e(BRegexp e$B$K$*$1$kFC<l$Je(B
ENCODING_FIXED e$B$He(B ENCODING_NONE e$B$N07$$$O0lItITMW$K46$8$^$9!#e(B
Ruby 1.9.1 e$B$K$Oe(B 1.8 e$BF1MM!"e(B
e$B@55,I=8=%j%F%i%k$Ke(B //s e$B$de(B //n
e$B$H$$$C$?%*%W%7%g%s$r;XDj$G$-$^$9!#e(B
e$B$H$3$m$,!"$3$N8z2L$O!"e(B//s e$B$de(B //ee$B!“e(B//u e$B$N>l9g$O!“e(B
e$B@55,I=8=$N%(%s%3!<%G%#%s%0$r;XDj$9$k$@$1$G$J$/!“e(B
e$B%^%C%ABP>]$NJ8;zNs$r;XDj$7$?%(%s%3!<%G%#%s%0$K!V8GDj!W$7$^$9!#e(B
e$B6qBNE*$K$Oe(B /aa/u =~ “aa”.force_encoding(“euc-jp”)
e$B$,%^%C%A$7$J$/$J$j$^$9!#e(B
e$B$7$+$7!”$3$N;EMM$O:.Mp$r>7$/$@$1$GITMW$G$O$J$$$G$7$g$&$+!#e(B
e$BHse(B ASCII e$BJ8;z$N%A%’%C%/MQ$H$7$F!”@55,I=8=FbIt$Ne(B KCODE_FIXED
e$B$Oe(B
e$B;D$9I,MW$,$”$k$H;W$$$^$9$,!"e(B//s
e$BEy$+$i;XDj$G$-$k;EMM$N:o=|$rDs0F$7$^$9!#e(B
e$B$^$?!"e(B//n e$B$O!"e(B
- e$B%(%s%3!<%G%#%s%0$Ke(B ASCII-8BIT e$B$r;XDje(B
- e$B@55,I=8=%j%F%i%k$KHse(B ASCII e$BJ8;z$r4^$`$H%(%i!<e(B
- /./n =~ "e$B$“e(B” e$BEy$G7Y9p$rI=<(e(B
e$B$r9T$$$^$9$,!"e(B3. e$B$OITMW$G$O$J$$$G$7$g$&$+!#e(B
Index: re.c
— re.c (revision 22332)
+++ re.c (working copy)
@@ -238,7 +238,6 @@ rb_memsearch(const void *x0, long m, const void *y
}
#define REG_LITERAL FL_USER5
-#define REG_ENCODING_NONE FL_USER6
#define KCODE_FIXED FL_USER4
@@ -302,7 +301,6 @@ rb_char_to_option_kcode(int c, int *option, int *k
*kcode = -1;
return (*option = char_to_option©);
}
- *option = ARG_ENCODING_FIXED;
return 1;
}
@@ -1201,12 +1199,6 @@ rb_reg_prepare_enc(VALUE re, VALUE str, int warn)
}
enc = RREGEXP(re)->ptr->enc;
}
- if (warn && (RBASIC(re)->flags & REG_ENCODING_NONE) &&
- enc != rb_ascii8bit_encoding() &&
- rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
- rb_warn(“regexp match /…/n against to %s string”,
- rb_enc_name(enc));
- }
return enc;
}
@@ -2329,8 +2321,7 @@ rb_reg_initialize(VALUE obj, const char *s, int le
return -1;
if (fixed_enc) {
- if ((fixed_enc != enc && (options & ARG_ENCODING_FIXED)) ||
-
(fixed_enc != a_enc && (options & ARG_ENCODING_NONE))) {
- if (fixed_enc != enc && (options & ARG_ENCODING_FIXED)) {
errcpy(err, “incompatible character encoding”);
return -1;
}
@@ -2347,9 +2338,6 @@ rb_reg_initialize(VALUE obj, const char *s, int le
if ((options & ARG_ENCODING_FIXED) || fixed_enc) {
re->basic.flags |= KCODE_FIXED;
}
-
if (options & ARG_ENCODING_NONE) {
-
re->basic.flags |= REG_ENCODING_NONE;
-
}
re->ptr = make_regexp(RSTRING_PTR(unescaped),
RSTRING_LEN(unescaped), enc,
options & ARG_REG_OPTION_MASK, err);
@@ -2946,7 +2934,6 @@ rb_reg_options(VALUE re)
rb_reg_check(re);
options = RREGEXP(re)->ptr->options & ARG_REG_OPTION_MASK;
if (RBASIC(re)->flags & KCODE_FIXED) options |= ARG_ENCODING_FIXED; -
if (RBASIC(re)->flags & REG_ENCODING_NONE) options |=
ARG_ENCODING_NONE;
return options;
}
Index: test/ruby/test_m17n.rb
— test/ruby/test_m17n.rb (revision 22332)
+++ test/ruby/test_m17n.rb (working copy)
@@ -349,24 +349,14 @@ class TestM17N < Test::Unit::TestCase
def test_regexp_ascii_none
r = /a/n
- assert_warning(%r{regexp match /…/n against to}) {
-
assert_regexp_generic_ascii(r)
- }
- assert_equal(0, r =~ a(“a”))
assert_equal(0, r =~ e(“a”))
assert_equal(0, r =~ s(“a”))
assert_equal(0, r =~ u(“a”))
assert_equal(nil, r =~ a("\xc2\xa1")) - assert_warning(%r{regexp match /…/n against to EUC-JP string}) {
-
assert_equal(nil, r =~ e("\xc2\xa1"))
- }
- assert_warning(%r{regexp match /…/n against to Windows-31J
string}) { -
assert_equal(nil, r =~ s("\xc2\xa1"))
- }
- assert_warning(%r{regexp match /…/n against to UTF-8 string}) {
-
assert_equal(nil, r =~ u("\xc2\xa1"))
- }
-
assert_equal(nil, r =~ e("\xc2\xa1"))
-
assert_equal(nil, r =~ s("\xc2\xa1"))
-
assert_equal(nil, r =~ u("\xc2\xa1"))
assert_nothing_raised { eval(e("/\x80/n")) }
end
@@ -392,7 +382,7 @@ class TestM17N < Test::Unit::TestCase
end
def test_regexp_euc
- assert_regexp_fixed_eucjp(/a/e)
- assert_regexp_generic_ascii(/a/e)
assert_regexp_fixed_eucjp(/\xc2\xa1/e)
assert_regexp_fixed_eucjp(eval(e(%{/\xc2\xa1/})))
assert_regexp_fixed_eucjp(eval(e(%q{/\xc2\xa1/})))
@@ -402,10 +392,10 @@ class TestM17N < Test::Unit::TestCase
assert_equal(0, r =~ e(“a”))
assert_equal(0, r =~ s(“a”))
assert_equal(0, r =~ u(“a”))
-
assert_raise(Encoding::CompatibilityError) { r =~ a("\xc2\xa1") }
-
assert_nothing_raised{ r =~ a("\xc2\xa1") } assert_equal(nil, r =~ e("\xc2\xa1"))
-
assert_raise(Encoding::CompatibilityError) { r =~ s("\xc2\xa1") }
-
assert_raise(Encoding::CompatibilityError) { r =~ u("\xc2\xa1") }
-
assert_nothing_raised{ r =~ s("\xc2\xa1") }
-
assert_nothing_raised{ r =~ u("\xc2\xa1") }
}
[/\xc2\xa1/e, eval(e(%{/\xc2\xa1/})), eval(e(%q{/\xc2\xa1/}))].each
{|r|
@@ -421,7 +411,7 @@ class TestM17N < Test::Unit::TestCase
enddef test_regexp_sjis
- assert_regexp_fixed_sjis(/a/s)
- assert_regexp_generic_ascii(/a/s)
assert_regexp_fixed_sjis(/\xc2\xa1/s)
assert_regexp_fixed_sjis(eval(s(%{/\xc2\xa1/})))
assert_regexp_fixed_sjis(eval(s(%q{/\xc2\xa1/})))
@@ -598,12 +588,10 @@ class TestM17N < Test::Unit::TestCase
def test_union_1_regexp
assert_regexp_generic_ascii(Regexp.union(//))
- assert_warning(%r{regexp match /…/n against to}) {
-
assert_regexp_generic_ascii(Regexp.union(//n))
- }
- assert_regexp_fixed_eucjp(Regexp.union(//e))
- assert_regexp_fixed_sjis(Regexp.union(//s))
- assert_regexp_fixed_utf8(Regexp.union(//u))
- assert_regexp_generic_ascii(Regexp.union(//n))
- assert_regexp_generic_ascii(Regexp.union(//e))
- assert_regexp_generic_ascii(Regexp.union(//s))
- assert_regexp_generic_ascii(Regexp.union(//u))
end
def test_union_2
@@ -641,16 +629,14 @@ class TestM17N < Test::Unit::TestCase
end
def test_dynamic_ascii_regexp
- assert_warning(%r{regexp match /…/n against to}) {
-
assert_regexp_generic_ascii(/#{}/n)
- }
- assert_regexp_generic_ascii(/#{}/n)
assert_regexp_fixed_ascii8bit(/#{}\xc2\xa1/n)
assert_regexp_fixed_ascii8bit(/\xc2\xa1#{}/n)
assert_nothing_raised { s1, s2 = a(’\xc2’), a(’\xa1’); /#{s1}#{s2}/
}
end
def test_dynamic_eucjp_regexp
- assert_regexp_fixed_eucjp(/#{}/e)
- assert_regexp_generic_ascii(/#{}/e)
assert_regexp_fixed_eucjp(/#{}\xc2\xa1/e)
assert_regexp_fixed_eucjp(/\xc2\xa1#{}/e)
assert_raise(SyntaxError) { eval(’/\xc2#{}/e’) }
@@ -660,7 +646,7 @@ class TestM17N < Test::Unit::TestCase
end
def test_dynamic_sjis_regexp
- assert_regexp_fixed_sjis(/#{}/s)
- assert_regexp_generic_ascii(/#{}/s)
assert_regexp_fixed_sjis(/#{}\xc2\xa1/s)
assert_regexp_fixed_sjis(/\xc2\xa1#{}/s)
assert_raise(SyntaxError) { eval(’/\x81#{}/s’) }
@@ -670,7 +656,7 @@ class TestM17N < Test::Unit::TestCase
end
def test_dynamic_utf8_regexp
- assert_regexp_fixed_utf8(/#{}/u)
- assert_regexp_generic_ascii(/#{}/u)
assert_regexp_fixed_utf8(/#{}\xc2\xa1/u)
assert_regexp_fixed_utf8(/\xc2\xa1#{}/u)
assert_raise(SyntaxError) { eval(’/\xc2#{}/u’) }