diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 38e0fea90..77460ee1c 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -209,6 +209,27 @@ String *Swig_string_ucase(String *s) { return ns; } +/* ----------------------------------------------------------------------------- + * Swig_string_first_ucase() + * + * Make the first character in the string uppercase, leave all the + * rest the same. This is used by the Ruby module to provide backwards + * compatibility with the old way of naming classes and constants. For + * more info see the Ruby documentation. + * + * firstUpper -> FirstUpper + * ----------------------------------------------------------------------------- */ + +String *Swig_string_first_ucase(String *s) { + String *ns = NewStringEmpty(); + char *cs = Char(s); + if (cs) { + Putc(toupper(cs[0]),ns); + Append(ns, cs + 1); +} + return ns; +} + /* ----------------------------------------------------------------------------- * Swig_string_typecode() * @@ -736,6 +757,7 @@ Swig_init() { DohEncoding("lowercase", Swig_string_lower); DohEncoding("camelcase", Swig_string_ccase); DohEncoding("undercase", Swig_string_ucase); + DohEncoding("firstuppercase", Swig_string_first_ucase); /* Initialize the swig keys */ Swig_keys_init();