Nathan Beyer wrote in post #1069253:
> I wasn't able to find anything in the README.EXT
> (http://svn.ruby-lang.org/repos/ruby/tags/v1_9_3_194/README.EXT).

Welcome to ruby 1.9.x, where everything to do with string encodings is 
completely undocumented.

> The implementation of String#force_encoding does a bit more than that:
>
> static VALUE
> rb_str_force_encoding(VALUE str, VALUE enc)
> {
>     str_modifiable(str);
>     rb_enc_associate(str, rb_to_encoding(enc));
>     ENC_CODERANGE_CLEAR(str);
>     return str;
> }
>
> This implementation adds an invocation of the ENC_CODERANGE_CLEAR
> macro and I'm not clear on what this does or when/why it would be
> needed.

I believe this is essentially the same as rb_str_modify(). It clears the 
cache of properties like 'ascii_only?' and 'valid_encoding?', so that 
next time someone queries them it has to scan the whole string.

> = String#encode
> I wasn't able to find any documentation about String transcoding
> within C extensions. Based on the implementation of String#encode,
> there seems to be a function 'rb_str_encode' in 'ruby/encoding.h' that
> might be appropriate, but there's no documentation for the method and
> I couldn't completely reverse engineer how the 'ecflags' and 'ecopts'
> arguments are used.

Maybe easier just to rb_funcall it?

Good luck,

Brian.

-- 
Posted via http://www.ruby-forum.com/.