[macruby-changes] [863] MacRuby/tags/0.4/encoding.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 9 14:39:05 PDT 2009
Revision: 863
http://trac.macosforge.org/projects/ruby/changeset/863
Author: lsansonetti at apple.com
Date: 2009-03-09 14:39:05 -0700 (Mon, 09 Mar 2009)
Log Message:
-----------
backported fix from trunk
Modified Paths:
--------------
MacRuby/tags/0.4/encoding.c
Modified: MacRuby/tags/0.4/encoding.c
===================================================================
--- MacRuby/tags/0.4/encoding.c 2009-03-09 21:27:45 UTC (rev 862)
+++ MacRuby/tags/0.4/encoding.c 2009-03-09 21:39:05 UTC (rev 863)
@@ -33,7 +33,8 @@
{
const CFStringEncoding *e;
- __encodings = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
+ __encodings = CFDictionaryCreateMutable(NULL, 0, NULL,
+ &kCFTypeDictionaryValueCallBacks);
/* XXX CFStringGetListOfAvailableEncodings() is a costly call and should
* be called on demand and not by default when the interpreter starts.
@@ -41,10 +42,7 @@
e = CFStringGetListOfAvailableEncodings();
while (e != NULL && *e != kCFStringEncodingInvalidId) {
VALUE iana;
- VALUE encoding;
- encoding = enc_new(e);
-
iana = (VALUE)CFStringConvertEncodingToIANACharSetName(*e);
if (iana != 0) {
const char *name;
@@ -65,14 +63,23 @@
}
while (p != NULL);
}
- if (islower(*tmp))
+ if (islower(*tmp)) {
*tmp = toupper(*tmp);
+ }
name = tmp;
}
+ VALUE encoding = enc_new(e);
rb_define_const(rb_cEncoding, name, encoding);
+ if (strcmp(name, "US_ASCII") == 0) {
+ // TODO in 1.9, ASCII_8BIT means binary
+ // In the meantime we finish the bytestring support let's
+ // alias this to US_ASCII
+ rb_define_const(rb_cEncoding, "ASCII_8BIT", encoding);
+ }
+
+ CFDictionarySetValue(__encodings, (const void *)iana,
+ (const void *)encoding);
}
- CFDictionarySetValue(__encodings, (const void *)iana,
- (const void *)encoding);
e++;
}
@@ -86,6 +93,9 @@
assert(enc != NULL);
iana = (VALUE)CFStringConvertEncodingToIANACharSetName(*enc);
+ if (iana == 0) {
+ return Qnil;
+ }
v = (VALUE)CFDictionaryGetValue((CFDictionaryRef)__encodings,
(const void *)iana);
assert(v != 0);
@@ -244,7 +254,10 @@
ary = rb_ary_new();
e = CFStringGetListOfAvailableEncodings();
while (e != NULL && *e != kCFStringEncodingInvalidId) {
- rb_ary_push(ary, enc_make(e));
+ VALUE enc = enc_make(e);
+ if (enc != Qnil) {
+ rb_ary_push(ary, enc);
+ }
e++;
}
return ary;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090309/19e51d15/attachment.html>
More information about the macruby-changes
mailing list