Dne 14.2.2012 05:25, Shawn Starr napsal(a):
On Monday, February 13, 2012 12:10:34 PM Vít Ondruch wrote:
If you do it right in rubygem-idn, then you could remove the
#force_encoding in rubygem-addressabe, i.e. rubygem-addressable should
stay untouched IMO. Moreover, it is dangerous to force encoding just
like that. In rubygem-idn, there has to be clear in what encoding is the
string returned by the library and you have to use the #force_encoding
for that. Later, Ruby knows encoding of the string and it should handle
it correctly, at least correctly fail if there is some unexpected
conversion needed.
for rubygem-idn:
ext/idna.c:
How would i return UTF-8 within C language, do we assume always UTF-8?
if so then something like this? I'm not familar with Ruby C APIs.
static VALUE toUnicode(int argc, VALUE argv[], VALUE self) {
....
....
....
- retv = rb_str_new2(buf);
+retv = rb_funcall(buf, rb_intern("force_encoding"), 1,
rb_str_new2("utf-8"));
xfree(buf);
return retv;
}
If that is right I wil adjust fir toUnicode and toASCII in rubygem-idn.
Nether I am expert on Ruby C APIs, however this looks good to me.
I've found some example:
http://callsign.rubyforge.org/git?p=nokogiri.git;a=commitdiff_plain;h=a47cbad917e75e653cdb97a8d99f4bb5bbab4d50
+#include<ruby/encoding.h>
+
+#define ENCODED_STR_NEW2(str, encoding) \
+ ({ \
+ VALUE _string = rb_str_new2((const char *)str); \
+ int _enc = rb_enc_find_index(encoding); \
+ rb_enc_associate_index(_string, _enc); \
+ _string; \
+ })
+
+#define ENCODED_STR_NEW(str, len, encoding) \
+ ({ \
+ VALUE _string = rb_str_new((const char *)str, (long)len); \
+ int _enc = rb_enc_find_index(encoding); \
+ rb_enc_associate_index(_string, _enc); \
+ _string; \
+ })
+
We just adapt accordingly, passes tests now without extra patch.. fixing
rubygem-addressable also to not use any patch (it shouldn't need it now)
Good work Shawn!
Vit
_______________________________________________
ruby-sig mailing list
[email protected]
https://admin.fedoraproject.org/mailman/listinfo/ruby-sig