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

* parse.y (reg_fragment_setenc_gen): associate ASCII-8BIT only if

str has only ASCII characters.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-01-24 13:11:00 +00:00
parent e27f4ef689
commit 14b9d47ae0
2 changed files with 18 additions and 4 deletions

View file

@ -1,3 +1,8 @@
Thu Jan 24 21:46:24 2008 Tanaka Akira <akr@fsij.org>
* parse.y (reg_fragment_setenc_gen): associate ASCII-8BIT only if
str has only ASCII characters.
Thu Jan 24 20:46:17 2008 NAKAMURA Usaku <usa@ruby-lang.org> Thu Jan 24 20:46:17 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* test/ruby/test_m17n.rb: follow to the following changes. * test/ruby/test_m17n.rb: follow to the following changes.

17
parse.y
View file

@ -8475,17 +8475,26 @@ reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options)
if (c) { if (c) {
int opt, idx; int opt, idx;
rb_char_to_option_kcode(c, &opt, &idx); rb_char_to_option_kcode(c, &opt, &idx);
if (idx != ENCODING_GET(str) && !ENCODING_IS_ASCII8BIT(str) && if (idx != ENCODING_GET(str) &&
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) { rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
compile_error(PARSER_ARG goto error;
"regexp encoding option '%c' differs from source encoding '%s'",
c, rb_enc_name(rb_enc_get(str)));
} }
ENCODING_SET(str, idx); ENCODING_SET(str, idx);
} }
else if (RE_OPTION_ENCODING_NONE(options)) { else if (RE_OPTION_ENCODING_NONE(options)) {
if (!ENCODING_IS_ASCII8BIT(str) &&
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
c = 'n';
goto error;
}
rb_enc_associate(str, rb_ascii8bit_encoding()); rb_enc_associate(str, rb_ascii8bit_encoding());
} }
return;
error:
compile_error(PARSER_ARG
"regexp encoding option '%c' differs from source encoding '%s'",
c, rb_enc_name(rb_enc_get(str)));
} }
static void static void