Subject:
Re: [ruby-ffi] Re: FFI::StructLayout::CharArray and UTF-8 encoding
From:
"Navaneeth.K.N" <navaneethkn@gmail.com>
Date:
5/9/12 12:12 AM
To:
ruby-ffi@googlegroups.com

Hello,

On Wed, May 9, 2012 at 4:55 AM, Wayne Meissner <wmeissner@gmail.com> wrote:


On Tuesday, 8 May 2012 15:49:17 UTC+10, Navaneeth KN wrote:

It looks like str.force_encoding('UTF-8') works well. But I am still ineterested  to know if there are any FFI way of specifying the encoding.


There's no way currently.  Can you add a section to the wiki about forcing the string encoding like you did above?

Sure. Will do it.

Do you think adding this as an extension to FFI::StructLayout::CharArray makes sense? In such cases ptr.read_string can do the desired encoding. read_string can take the encoding as a parameter or read from a configuration like,

module Sample
extend FFI::Library
ffi_lib "sample.so"
string_encoding "UTF-8"
end

Let me know what you think.

Thanks
Navaneeth