Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement ENCODING_SET() CRuby API

  • Loading branch information...
commit 3fce966385774a70e1d114db7e0e3a4c5621bc2f 1 parent bd12795
Laurent Sansonetti authored
Showing with 4 additions and 3 deletions.
  1. +3 −3 encoding.c
  2. +1 −0  include/ruby/encoding.h
View
6 encoding.c
@@ -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
1  include/ruby/encoding.h
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.