[macruby-changes] [1804] MacRuby/branches/experimental/encoding.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 8 14:53:05 PDT 2009
Revision: 1804
http://trac.macosforge.org/projects/ruby/changeset/1804
Author: lsansonetti at apple.com
Date: 2009-06-08 14:53:05 -0700 (Mon, 08 Jun 2009)
Log Message:
-----------
better logic to rubyfy encoding names (was failing on 10.6)
Modified Paths:
--------------
MacRuby/branches/experimental/encoding.c
Modified: MacRuby/branches/experimental/encoding.c
===================================================================
--- MacRuby/branches/experimental/encoding.c 2009-06-08 09:25:18 UTC (rev 1803)
+++ MacRuby/branches/experimental/encoding.c 2009-06-08 21:53:05 UTC (rev 1804)
@@ -48,28 +48,34 @@
iana = (VALUE)CFStringConvertEncodingToIANACharSetName(*e);
if (iana != 0) {
const char *name;
- char *p;
name = RSTRING_PTR(iana);
- p = strchr(name, '-');
- if ((p = strchr(name, '-')) != NULL
- || islower(*name)) {
- char *tmp = alloca(strlen(name));
- strcpy(tmp, name);
- if (p != NULL) {
- p = tmp + (p - name);
- do {
- *p = '_';
- p++;
- p = strchr(p, '-');
- }
- while (p != NULL);
+
+ // new_name = name.gsub(/-/, '_').upcase
+ char *new_name = alloca(strlen(name));
+ strcpy(new_name, name);
+ char *p = strchr(name, '-');
+ if (p != NULL) {
+ p = new_name + (p - name);
+ do {
+ *p = '_';
+ p++;
+ p = strchr(p, '-');
}
- if (islower(*tmp))
- *tmp = toupper(*tmp);
- name = tmp;
+ while (p != NULL);
}
- rb_define_const(rb_cEncoding, name, encoding);
+ p = new_name;
+ while (*p != '\0') {
+ if (islower(*p)) {
+ *p = toupper(*p);
+ }
+ p++;
+ }
+
+ ID encoding_id = rb_intern(new_name);
+ if (!rb_const_defined(rb_cEncoding, encoding_id)) {
+ rb_const_set(rb_cEncoding, encoding_id, encoding);
+ }
}
CFDictionarySetValue(__encodings, (const void *)iana,
(const void *)encoding);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090608/2f77c29d/attachment.html>
More information about the macruby-changes
mailing list