From 1ed88df67f94e52007176cb8a5cb85a66658d69b Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 16 Oct 2007 21:18:09 +0000 Subject: * 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: http://svn.ruby-lang.org/repos/ruby/trunk@13731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- encoding.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 11 deletions(-) (limited to 'encoding.c') diff --git a/encoding.c b/encoding.c index a327d42d1..e2d3cdd8d 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