[macruby-changes] [4134] MacRuby/trunk/encoding.c

source_changes at macosforge.org source_changes at macosforge.org
Fri May 21 15:00:21 PDT 2010


Revision: 4134
          http://trac.macosforge.org/projects/ruby/changeset/4134
Author:   vincent.isambart at gmail.com
Date:     2010-05-21 15:00:18 -0700 (Fri, 21 May 2010)
Log Message:
-----------
also define the encoding constants in upper case

Modified Paths:
--------------
    MacRuby/trunk/encoding.c

Modified: MacRuby/trunk/encoding.c
===================================================================
--- MacRuby/trunk/encoding.c	2010-05-21 21:04:40 UTC (rev 4133)
+++ MacRuby/trunk/encoding.c	2010-05-21 22:00:18 UTC (rev 4134)
@@ -155,19 +155,39 @@
 	return;
     }
 
+    if (strcmp(name, "locale") == 0) {
+	// there is no constant for locale
+	return;
+    }
+
     char *name_copy = strdup(name);
     if ((c >= 'a') && (c <= 'z')) {
 	// the first character must be upper case
 	name_copy[0] = c - ('a' - 'A');
     }
 
+    bool has_lower_case = false;
     // '.' and '-' must be transformed into '_'
     for (int i = 0; name_copy[i]; ++i) {
 	if ((name_copy[i] == '.') || (name_copy[i] == '-')) {
 	    name_copy[i] = '_';
 	}
+	else if ((name_copy[i] >= 'a') && (name_copy[i] <= 'z')) {
+	    has_lower_case = true;
+	}
     }
     rb_define_const(rb_cEncoding, name_copy, (VALUE)encoding);
+    // if the encoding name has lower case characters,
+    // also define it in upper case
+    if (has_lower_case) {
+	for (int i = 0; name_copy[i]; ++i) {
+	    if ((name_copy[i] >= 'a') && (name_copy[i] <= 'z')) {
+		name_copy[i] = name_copy[i] - 'a' + 'A';
+	    }
+	}
+	rb_define_const(rb_cEncoding, name_copy, (VALUE)encoding);
+    }
+
     free(name_copy);
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100521/96b7cc70/attachment-0001.html>


More information about the macruby-changes mailing list