Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

also define the encoding constants in upper case

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4134 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 325c03252d15c116dc4ac70b87ab1b38866a094c 1 parent a4d9d90
@vincentisambart vincentisambart authored
Showing with 20 additions and 0 deletions.
  1. +20 −0 encoding.c
View
20 encoding.c
@@ -155,19 +155,39 @@ define_encoding_constant(const char *name, rb_encoding_t *encoding)
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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.