From: "Iñaki Baz Castillo" Date: 2009-12-03T02:03:21+09:00 Subject: Re: How to use rb_enc_str_new() to create a String with UTF-8 encoding? El Miércoles, 2 de Diciembre de 2009, Brian Candler escribió: > Iñaki Baz Castillo wrote: > > VALUE > > rb_enc_str_new(const char *ptr, long len, rb_encoding *enc) > > { > > VALUE str = rb_str_new(ptr, len); > > rb_enc_associate(str, enc); > > return str; > > } > > > > But I have no idea on how to set 'enc' parameter to be "UTF-8". > > How should I fill the third 'enc' argument? > > I'd say give it a pointer to an rb_encoding object. > > Have a look in encoding.c, this particular function might be useful: > > rb_encoding * > rb_enc_find(const char *name) > { > int idx = rb_enc_find_index(name); > if (idx < 0) idx = 0; > return rb_enc_from_index(idx); > } Humm, it involves allocating memory for the rb_encoding object and so... not so trivial as I desired :) But that's the way. Thanks a lot. -- Iñaki Baz Castillo