From 5daecbc0e14f840059db48f34f6b000df54c40cc Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 16 Oct 2007 21:18:09 +0000 Subject: [PATCH] * encoding.c (rb_enc_alias, rb_enc_find_index): changed enc_table_alias to a name-to-index hash. * encoding.c (rb_enc_init): use upper case names for aliases to use as constant names. * encoding.c (enc_find): allow symbols. * encoding.c (Init_Encoding): define encoding constants. * st.c (strcasehash): fix wrong code range condition. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 ++++++++++ encoding.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++-------- st.c | 2 +- 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index a3c0530f75..e72f23e62e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Wed Oct 17 06:18:06 2007 Nobuyoshi Nakada + + * encoding.c (rb_enc_alias, rb_enc_find_index): changed + enc_table_alias to a name-to-index hash. + + * encoding.c (rb_enc_init): use upper case names for aliases to use as + constant names. + + * encoding.c (enc_find): allow symbols. + + * encoding.c (Init_Encoding): define encoding constants. + + * st.c (strcasehash): fix wrong code range condition. + Wed Oct 17 05:07:18 2007 Nobuyoshi Nakada * encoding.c (rb_primary_encoding): added Encoding.primary_encoding. diff --git a/encoding.c b/encoding.c index a327d42d1a..e2d3cdd8da 100644 --- a/encoding.c +++ b/encoding.c @@ -13,6 +13,7 @@ #include "ruby/ruby.h" #include "ruby/encoding.h" #include "regenc.h" +#include static ID id_encoding; static VALUE rb_cEncoding; @@ -152,12 +153,12 @@ rb_enc_alias(const char *alias, const char *orig) if (!enc_table_alias) { enc_table_alias = st_init_strcasetable(); } - while ((idx = rb_enc_find_index(orig)) < 0) { + if ((idx = rb_enc_find_index(orig)) < 0) { if (!st_lookup(enc_table_alias, (st_data_t)orig, &data)) return -1; - orig = (const char *)data; + idx = (int)data; } - st_insert(enc_table_alias, (st_data_t)alias, (st_data_t)orig); + st_insert(enc_table_alias, (st_data_t)alias, (st_data_t)idx); return idx; } @@ -170,10 +171,10 @@ rb_enc_init(void) ENC_REGISTER(ONIG_ENCODING_SJIS); ENC_REGISTER(ONIG_ENCODING_UTF8); #undef ENC_REGISTER - rb_enc_alias("ascii", rb_enc_name(ONIG_ENCODING_ASCII)); - rb_enc_alias("binary", rb_enc_name(ONIG_ENCODING_ASCII)); - rb_enc_alias("us-ascii", rb_enc_name(ONIG_ENCODING_ASCII)); /* will be defined separately in future. */ - rb_enc_alias("sjis", rb_enc_name(ONIG_ENCODING_SJIS)); + rb_enc_alias("ASCII", rb_enc_name(ONIG_ENCODING_ASCII)); + rb_enc_alias("BINARY", rb_enc_name(ONIG_ENCODING_ASCII)); + rb_enc_alias("US-ASCII", rb_enc_name(ONIG_ENCODING_ASCII)); /* will be defined separately in future. */ + rb_enc_alias("SJIS", rb_enc_name(ONIG_ENCODING_SJIS)); } rb_encoding * @@ -198,7 +199,6 @@ rb_enc_find_index(const char *name) if (!enc_table) { rb_enc_init(); } - find: for (i=0; i