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

io.c: use built-in encoding indexes

* internal.h: add UTF-{16,32}{BE,LE}.
* io.c (io_strip_bom): use built-in encoding indexes in internal.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-07-02 08:22:34 +00:00
parent ea2b115efd
commit 42a2f89b39
4 changed files with 17 additions and 5 deletions

View file

@ -1,4 +1,8 @@
Tue Jul 2 17:22:25 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
Tue Jul 2 17:22:31 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* internal.h: add UTF-{16,32}{BE,LE}.
* io.c (io_strip_bom): use built-in encoding indexes in internal.h.
* internal.h (rb_{ascii8bit,utf8,usascii}_encindex): use built-in
encoding indexes for optimization.

View file

@ -559,6 +559,10 @@ rb_enc_init(void)
#undef ENC_REGISTER
#ifndef NO_PRESERVED_ENCODING
#define ENCDB_REGISTER(name, enc) enc_register_at(ENCINDEX_##enc, name, NULL)
ENCDB_REGISTER("UTF-16BE", UTF_16BE);
ENCDB_REGISTER("UTF-16LE", UTF_16LE);
ENCDB_REGISTER("UTF-32BE", UTF_32BE);
ENCDB_REGISTER("UTF-32LE", UTF_32LE);
#undef ENCDB_REGISTER
#endif
enc_table.count = ENCINDEX_BUILTIN_MAX;

View file

@ -204,6 +204,10 @@ enum ruby_preserved_encindex {
#ifndef NO_PRESERVED_ENCODING
/* preserved indexes */
ENCINDEX_UTF_16BE,
ENCINDEX_UTF_16LE,
ENCINDEX_UTF_32BE,
ENCINDEX_UTF_32LE,
#endif
ENCINDEX_BUILTIN_MAX

8
io.c
View file

@ -5319,7 +5319,7 @@ io_strip_bom(VALUE io)
case INT2FIX(0xFE):
if (NIL_P(b2 = rb_io_getbyte(io))) break;
if (b2 == INT2FIX(0xFF)) {
return rb_enc_find_index("UTF-16BE");
return ENCINDEX_UTF_16BE;
}
rb_io_ungetbyte(io, b2);
break;
@ -5330,14 +5330,14 @@ io_strip_bom(VALUE io)
b3 = rb_io_getbyte(io);
if (b3 == INT2FIX(0) && !NIL_P(b4 = rb_io_getbyte(io))) {
if (b4 == INT2FIX(0)) {
return rb_enc_find_index("UTF-32LE");
return ENCINDEX_UTF_32LE;
}
rb_io_ungetbyte(io, b4);
rb_io_ungetbyte(io, b3);
}
else {
rb_io_ungetbyte(io, b3);
return rb_enc_find_index("UTF-16LE");
return ENCINDEX_UTF_16LE;
}
}
rb_io_ungetbyte(io, b2);
@ -5348,7 +5348,7 @@ io_strip_bom(VALUE io)
if (b2 == INT2FIX(0) && !NIL_P(b3 = rb_io_getbyte(io))) {
if (b3 == INT2FIX(0xFE) && !NIL_P(b4 = rb_io_getbyte(io))) {
if (b4 == INT2FIX(0xFF)) {
return rb_enc_find_index("UTF-32BE");
return ENCINDEX_UTF_32BE;
}
rb_io_ungetbyte(io, b4);
}