diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 04:40:13 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 04:40:13 +0000 |
commit | ef0706a5bf4dd888363f017c2408899009c24c4a (patch) | |
tree | 9c4741363c3f7162bd7fb73d5aeff1f32e37a349 /encoding.c | |
parent | ad47716266cc8048b6ec1c8d73490cfe06a05657 (diff) | |
download | ruby-ef0706a5bf4dd888363f017c2408899009c24c4a.tar.gz |
* encoding.c (rb_enc_register): set encoding constant.
* encoding.c (rb_enc_find_index): replace non-alphanumeric chars with
underscores, so that initialize function can be called.
* ruby.c (proc_options, process_options): finds encoding after
load_path is initialized.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/encoding.c b/encoding.c index 6ff8fb6aad..fdcceab5a2 100644 --- a/encoding.c +++ b/encoding.c @@ -158,6 +158,7 @@ enc_register(const char *name, rb_encoding *encoding) } static VALUE enc_based_encoding(VALUE); +static void set_encoding_const(const char *, rb_encoding *); int rb_enc_registered(const char *name); int @@ -170,16 +171,21 @@ rb_enc_register(const char *name, rb_encoding *encoding) if (strcasecmp(name, rb_enc_name(oldenc))) { st_data_t key = (st_data_t)name, alias; st_delete(enc_table_alias, &key, &alias); + index = enc_register(name, encoding); } else if (enc_initialized_p(oldenc) && - !NIL_P(enc_based_encoding(ENC_FROM_ENCODING(encoding)))) { - return enc_register_at(index, name, encoding); + !NIL_P(enc_based_encoding(ENC_FROM_ENCODING(oldenc)))) { + enc_register_at(index, name, encoding); } else { rb_raise(rb_eArgError, "encoding %s is already registered", name); } } - return enc_register(name, encoding); + else { + index = enc_register(name, encoding); + } + set_encoding_const(name, rb_enc_from_index(index)); + return index; } int @@ -293,6 +299,11 @@ rb_enc_find_index(const char *name) int i = rb_enc_registered(name); if (i < 0) { VALUE enclib = rb_sprintf("enc/%s", name); + char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib); + while (s < e) { + if (!ISALNUM(*s)) *s = '_'; + ++s; + } OBJ_FREEZE(enclib); if (RTEST(rb_protect(require_enc, enclib, 0))) i = rb_enc_registered(name); |