1.9, C extension vs encoding

  • Thread starter Victor 'Zverok' Shepelev
  • Start date
V

Victor 'Zverok' Shepelev

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.
 
K

KUBO Takehiro

Hi,

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().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top