e$B@.@%$G$9!#e(B
-- coding: UTF-8 --
str = “e$B$”$$$&$($*e(B"
m = str[/./]
p m.encoding #=> Encoding:ASCII-8BIT
e$B$H$J$k$N$G$9$,!"$3$3$Oe(B UTF-8
e$BJ8;zNs$rJV$9$Y$-$G$O$J$$$G$7$g$&$+!#$?$V$se(B
e$BC1$Ke(B rb_str_new4() e$B$J$@$1$C$]$$$G$9$,!#e(B
Index: string.c
— string.c (e$B%j%S%8%g%se(B 13711)
+++ string.c (e$B:n6H%3%T!<e(B)
@@ -307,6 +307,7 @@
}
else if (STR_ASSOC_P(orig) || STR_EMBED_P(orig)) {
str = str_new(klass, RSTRING_PTR(orig), RSTRING_LEN(orig));
-
}rb_enc_copy(str, orig);
else {
str = str_new4(klass, orig);
e$B$^$?!“e(B
ru = Regexp.new(”\xE3\x81\x82".force_encoding(‘UTF-8’))
ru.encoding #=> Encoding:UTF-8
p ru.to_s.encoding # => Encoding:ASCII-8BIT
re = Regexp.new("\x82\xA0".force_encoding(‘EUC-JP’))
re.encoding #=> Encoding:EUC-JP
rr = Regexp.union(ru,re) #=> /(?-mix:\343\201\202)|(?-mix:\202\240)/
rr.encoding #=> Encoding:ASCII-8BIT
e$B$H$J$k$N$G$9$,!"$3$l$O0U?^$7$?F0:n$G$7$g$&$+e(B