Permalink
Browse files

implement ENCODING_SET() CRuby API

  • Loading branch information...
1 parent bd12795 commit 3fce966385774a70e1d114db7e0e3a4c5621bc2f Laurent Sansonetti committed May 1, 2011
Showing with 4 additions and 3 deletions.
  1. +3 −3 encoding.c
  2. +1 −0 include/ruby/encoding.h
View
@@ -525,10 +525,10 @@ rb_enc_to_index(VALUE enc)
void
rb_enc_set_index(VALUE obj, int encindex)
{
- if (encindex < ENCODINGS_COUNT) {
- return ;
+ assert(encindex >= 0 && encindex < ENCODINGS_COUNT);
+ if (TYPE(obj) == T_STRING) {
+ rb_str_force_encoding(obj, rb_encodings[encindex]);
}
- rb_str_force_encoding(obj, rb_encodings[encindex]);
}
int
View
@@ -17,6 +17,7 @@ extern "C" {
typedef struct rb_encoding rb_encoding;
#define ENCODING_GET(obj) (rb_enc_get_index((VALUE)obj))
+#define ENCODING_SET(obj, idx) (rb_enc_set_index((VALUE)obj, idx))
int rb_enc_get_index(VALUE obj);
void rb_enc_set_index(VALUE obj, int encindex);

0 comments on commit 3fce966

Please sign in to comment.