mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* parse.y: strings which contain only US-ASCII don't force to have
US-ASCII encoding. [ruby-dev:36400] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
00cdba732f
commit
cfadd72532
3 changed files with 13 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Sep 20 08:07:34 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* parse.y: strings which contain only US-ASCII don't force to have
|
||||
US-ASCII encoding. [ruby-dev:36400]
|
||||
|
||||
Sat Sep 20 07:59:31 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* re.c (rb_reg_desc): Regexps of ASCII Compatible encoding may
|
||||
|
|
6
parse.y
6
parse.y
|
@ -264,12 +264,11 @@ struct parser_params {
|
|||
#define UTF8_ENC() (parser->utf8 ? parser->utf8 : \
|
||||
(parser->utf8 = rb_utf8_encoding()))
|
||||
#define STR_NEW(p,n) rb_enc_str_new((p),(n),parser->enc)
|
||||
#define STR_NEW0() rb_usascii_str_new(0,0)
|
||||
#define STR_NEW0() rb_enc_str_new(0,0,parser->enc)
|
||||
#define STR_NEW2(p) rb_enc_str_new((p),strlen(p),parser->enc)
|
||||
#define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),parser->enc)
|
||||
#define STR_ENC(m) ((m)?parser->enc:rb_usascii_encoding())
|
||||
#define ENC_SINGLE(cr) ((cr)==ENC_CODERANGE_7BIT)
|
||||
#define TOK_INTERN(mb) rb_intern3(tok(), toklen(), STR_ENC(mb))
|
||||
#define TOK_INTERN(mb) rb_intern3(tok(), toklen(), parser->enc)
|
||||
|
||||
#ifdef YYMALLOC
|
||||
void *rb_parser_malloc(struct parser_params *, size_t);
|
||||
|
@ -5150,7 +5149,6 @@ parser_str_new(const char *p, long n, rb_encoding *enc, int func, rb_encoding *e
|
|||
str = rb_enc_str_new(p, n, enc);
|
||||
if (!(func & STR_FUNC_REGEXP) && rb_enc_asciicompat(enc)) {
|
||||
if (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) {
|
||||
rb_enc_associate(str, rb_usascii_encoding());
|
||||
}
|
||||
else if (enc0 == rb_usascii_encoding() && enc != rb_utf8_encoding()) {
|
||||
rb_enc_associate(str, rb_ascii8bit_encoding());
|
||||
|
|
|
@ -146,17 +146,17 @@ class TestM17N < Test::Unit::TestCase
|
|||
# tests start
|
||||
|
||||
def test_string_ascii_literal
|
||||
assert_encoding("US-ASCII", eval(a(%{""})).encoding)
|
||||
assert_encoding("US-ASCII", eval(a(%{"a"})).encoding)
|
||||
assert_encoding("ASCII-8BIT", eval(a(%{""})).encoding)
|
||||
assert_encoding("ASCII-8BIT", eval(a(%{"a"})).encoding)
|
||||
end
|
||||
|
||||
def test_string_eucjp_literal
|
||||
assert_encoding("US-ASCII", eval(e(%{""})).encoding)
|
||||
assert_encoding("US-ASCII", eval(e(%{"a"})).encoding)
|
||||
assert_encoding("EUC-JP", eval(e(%{""})).encoding)
|
||||
assert_encoding("EUC-JP", eval(e(%{"a"})).encoding)
|
||||
assert_encoding("EUC-JP", eval(e(%{"\xa1\xa1"})).encoding)
|
||||
assert_encoding("EUC-JP", eval(e(%{"\\xa1\\xa1"})).encoding)
|
||||
assert_encoding("US-ASCII", eval(e(%{"\\x20"})).encoding)
|
||||
assert_encoding("US-ASCII", eval(e(%{"\\n"})).encoding)
|
||||
assert_encoding("EUC-JP", eval(e(%{"\\x20"})).encoding)
|
||||
assert_encoding("EUC-JP", eval(e(%{"\\n"})).encoding)
|
||||
assert_encoding("EUC-JP", eval(e(%{"\\x80"})).encoding)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue