[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

1.9, C extension vs encoding

Victor 'Zverok' Shepelev

8/20/2008 3:19:00 PM

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.


1 Answer

KUBO Takehiro

8/22/2008 11:57:00 PM

0

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