1.9, C extension vs encoding

Hello all.

Ruby 1.9.
When I create some strings with Russian letters in C extensions, they have

str.encoding #=> #<Encoding:ASCII-8BIT>

while being created in Ruby, they have proper UTF-8. Where is I'm idiot?

Thanks.

V.

Hi,

ยทยทยท

On Thu, Aug 21, 2008 at 12:18 AM, Victor 'Zverok' Shepelev <vshepelev@imho.com.ua> wrote:

Hello all.

Ruby 1.9.
When I create some strings with Russian letters in C extensions, they have

str.encoding #=> #<Encoding:ASCII-8BIT>

while being created in Ruby, they have proper UTF-8. Where is I'm idiot?

rb_str_new() creates a ASCII-8BIT string in Ruby 1.9.
You need to use rb_enc_str_new() with proper rb_encoding.
If your extensions always make UTF8 strings, use rb_utf8_encoding().
If the encoding depends on locale, use rb_locale_encoding().