/* * call-seq: * IDN::Idna.toUnicode(string, flags=nil) => string * * Converts a possibly ACE encoded domain name in UTF-8 format into an * UTF-8 string. The domain name may contain several labels, separated * by dots. * * Raises IDN::Idna::IdnaError on failure. */ static VALUE toUnicode(int argc, VALUE argv[], VALUE self) { int rc; char *buf; VALUE str, flags, retv; rb_scan_args(argc, argv, "11", &str, &flags); str = rb_check_convert_type(str, T_STRING, "String", "to_s"); if (flags != Qnil) { Check_Type(flags, T_FIXNUM); flags = FIX2INT(flags); } else { flags = 0x0000; } rc = idna_to_unicode_8z8z(RSTRING(str)->ptr, &buf, flags); if (rc != IDNA_SUCCESS) { xfree(buf); rb_raise(eIdnaError, "%s (%d)", idna_strerror(rc), rc); return Qnil; } retv = rb_str_new2(buf); xfree(buf); return retv; }