diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-10-06 05:56:09 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-10-06 05:56:09 +0000 |
| commit | f6c2ad67829ce5419990d7c3c2be6a62fea0a7a7 (patch) | |
| tree | 52160ca24830b1bbb1973eabdfb6acc819b56e44 /string.c | |
| parent | 1569854787ca2b6551e0bbcc1eca2e5f81f75264 (diff) | |
| download | ruby-f6c2ad67829ce5419990d7c3c2be6a62fea0a7a7.tar.gz ruby-f6c2ad67829ce5419990d7c3c2be6a62fea0a7a7.tar.xz ruby-f6c2ad67829ce5419990d7c3c2be6a62fea0a7a7.zip | |
* encoding.c (rb_enc_register): returns new index or -1 if failed.
* encoding.c (rb_enc_alias): check if original name is registered.
* encoding.c (rb_enc_init): register in same order as kcode options in
re.c. added new aliases.
* string.c (rb_str_force_encoding): check if valid encoding name.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -5114,8 +5114,17 @@ rb_str_setter(VALUE val, ID id, VALUE *var) static VALUE rb_str_force_encoding(VALUE str, VALUE encname) { + const char *name; + int idx; + + if (NIL_P(encname)) { + idx = 0; + } + else if ((idx = rb_enc_find_index(name = StringValueCStr(encname))) < 0) { + rb_raise(rb_eArgError, "invalid encoding name - %s", name); + } str_modifiable(str); - rb_enc_associate(str, rb_enc_find(StringValueCStr(encname))); + rb_enc_associate_index(str, idx); return str; } |
