On Tue, Feb 9, 2010 at 9:15 PM, Praveen <praveendevarao / gmail.com> wrote:
> Hi,
>
> I am working on enhancing the IBM_DB Ruby driver (database driver for
> DB2 and Informix) by providing unicode support.
>
> I tried googling with no luck to find any documents or links which
> talk about the Ruby C extension API's that can be used to unleash the
> unicode support of Ruby-1.9 to

Look at ruby-1.9.1-pxxx/include/ruby/encoding.h and ruby-1.9.1-pxxx/string.c.

> 1) Convert Ruby string (unicode) object received in the extension API
> into wchar (like rb_str2cstr, in ruby-1.8)

No generic way because wchar's encoding is platform-dependent.
As far as I know, it is UCS-2 in Windows, UCS-4 in Linux, locale-dependent
value in Solaris.

If it is UCS-2,
  rb_encoding *ucs2_enc = rb_enc_find("UCS-2");
  VALUE ucs2_string = rb_str_export_to_enc(string, ucs2_enc);
  const char *ucs2_cstr = StringValueCStr(ucs2_string);

> 2) Convert wchar* to a Ruby Object (like rb_str_new2, in ruby-1.8).

If the wchar's encoding is UCS-2,
  rb_encoding *ucs2_enc = rb_enc_find("UCS-2");
  VALUE ucs2_string = rb_external_str_new_with_enc(cstr, len, usc2_enc);

> 3) Convert string objects between different formats (UCS-2, UCS-4).

  rb_encoding *ucs2_enc = rb_enc_find("UCS-2");
  rb_encoding *ucs4_enc = rb_enc_find("UCS-4");
  VALUE ucs4_string = rb_str_conv_enc(ucs2_string, ucs2_enc, ucs4_enc);