From: Brian Candler Date: 2009-12-03T02:59:17+09:00 Subject: Re: How to use rb_enc_str_new() to create a String with UTF-8 encoding? I単aki Baz Castillo wrote: > El Mi辿rcoles, 2 de Diciembre de 2009, Brian Candler escribi坦: >> > How should I fill the third 'enc' argument? >> return rb_enc_from_index(idx); >> } > > Humm, it involves allocating memory for the rb_encoding object Why? AFAICS, you can just pass a pointer to an existing encoding object. They are not mutated. There are other examples, e.g. from io.c #ifdef _WIN32 if (utf16 == (rb_encoding *)-1) { utf16 = rb_enc_find("UTF-16LE"); if (utf16 == rb_ascii8bit_encoding()) utf16 = NULL; } if (utf16) { VALUE wfname = rb_str_encode(fname, rb_enc_from_encoding(utf16), 0, Qnil); rb_enc_str_buf_cat(wfname, "", 1, utf16); /* workaround */ data.fname = RSTRING_PTR(wfname); data.wchar = 1; } else { data.wchar = 0; } #endif It looks like rb_enc_from_encoding() takes a pointer to the rb_encoding object returned from rb_enc_find, and turns it into a VALUE -- Posted via http://www.ruby-forum.com/.