diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-28 19:27:10 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-28 19:27:10 +0000 |
commit | c351afc37276bb3d82eabe142a20be10127fed27 (patch) | |
tree | 1439d697c7f32c7e8322bfd62d40ce9c2ed7e628 /string.c | |
parent | 534d057e58e68c5a65509e718366f2dab5e69e84 (diff) |
* encoding.c (rb_enc_alias): allow encodings multiple aliases.
* encoding.c (rb_enc_find_index): search the encoding which has the
given name and return its index if found, or -1.
* st.c (type_strcasehash): case-insensitive string hash type.
* string.c (rb_str_force_encoding): force encoding of self. this name
comes from [ruby-dev:31894] by Martin Duerst. [ruby-dev:31744]
* include/ruby/encoding.h (rb_enc_find_index, rb_enc_associate_index):
prototyped.
* include/ruby/encoding.h (rb_enc_isctype): direct interface to ctype.
* include/ruby/st.h (st_init_strcasetable): prototyped.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -228,7 +228,7 @@ rb_tainted_str_new2(const char *ptr) } static VALUE -str_new3(VALUE klass, VALUE str) +str_new_shared(VALUE klass, VALUE str) { VALUE str2 = str_alloc(klass); @@ -244,11 +244,19 @@ str_new3(VALUE klass, VALUE str) RSTRING(str2)->as.heap.aux.shared = str; FL_SET(str2, ELTS_SHARED); } - rb_enc_copy((VALUE)str2, str); return str2; } +static VALUE +str_new3(VALUE klass, VALUE str) +{ + VALUE str2 = str_new_shared(klass, str); + + rb_enc_copy(str2, str); + return str2; +} + VALUE rb_str_new3(VALUE str) { @@ -5108,6 +5116,21 @@ str_encoding(VALUE str) } +/* + * call-seq: + * str.force_encoding(encoding) => str + * + * Changes the encoding to +encoding+ and returns self. + */ + +static VALUE +rb_str_force_encoding(VALUE str, VALUE encname) +{ + str_modifiable(str); + rb_enc_associate(str, rb_enc_find(StringValueCStr(encname))); + return str; +} + /********************************************************************** * Document-class: Symbol * @@ -5519,6 +5542,7 @@ Init_String(void) rb_define_method(rb_cString, "rpartition", rb_str_rpartition, 1); rb_define_method(rb_cString, "encoding", str_encoding, 0); + rb_define_method(rb_cString, "force_encoding", rb_str_force_encoding, 1); id_to_s = rb_intern("to_s"); |