VALUE rb_enc_associate_index(VALUE obj, int idx) { rb_encoding *enc; int oldidx, oldtermlen, termlen; /* enc_check_capable(obj);*/ rb_check_frozen(obj); oldidx = rb_enc_get_index(obj); if (oldidx == idx) return obj; if (SPECIAL_CONST_P(obj)) { rb_raise(rb_eArgError, "cannot set encoding"); } enc = must_encindex(idx); if (!ENC_CODERANGE_ASCIIONLY(obj) || !rb_enc_asciicompat(enc)) { ENC_CODERANGE_CLEAR(obj); } termlen = rb_enc_mbminlen(enc); oldtermlen = rb_enc_mbminlen(rb_enc_from_index(oldidx)); if (oldtermlen < termlen && RB_TYPE_P(obj, T_STRING)) { rb_str_fill_terminator(obj, termlen); } enc_set_index(obj, idx); return obj; }
void rb_enc_set_index(VALUE obj, int idx) { rb_check_frozen(obj); must_encindex(idx); enc_set_index(obj, idx); }
VALUE rb_enc_associate_index(VALUE obj, int idx) { /* enc_check_capable(obj);*/ rb_check_frozen(obj); if (rb_enc_get_index(obj) == idx) return obj; if (SPECIAL_CONST_P(obj)) { rb_raise(rb_eArgError, "cannot set encoding"); } if (!ENC_CODERANGE_ASCIIONLY(obj) || !rb_enc_asciicompat(rb_enc_from_index(idx))) { ENC_CODERANGE_CLEAR(obj); } enc_set_index(obj, idx); return obj; }