Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added Symbol #upcase, #downcase, #swapcase, #capitalize

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3834 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit af1c6516163501b718691bbcdf9b1c23d2e18e2a 1 parent 2c15444
Laurent Sansonetti authored
Showing with 60 additions and 4 deletions.
  1. +4 −4 string.c
  2. +56 −0 symbol.c
View
8 string.c
@@ -3762,7 +3762,7 @@ rstr_downcase_bang(VALUE str, SEL sel)
* "hEllO".downcase #=> "hello"
*/
-static VALUE
+VALUE
rstr_downcase(VALUE str, SEL sel)
{
str = rb_str_new3(str);
@@ -3806,7 +3806,7 @@ rstr_upcase_bang(VALUE str, SEL sel)
* "hEllO".upcase #=> "HELLO"
*/
-static VALUE
+VALUE
rstr_upcase(VALUE str, SEL sel)
{
str = rb_str_new3(str);
@@ -3854,7 +3854,7 @@ rstr_swapcase_bang(VALUE str, SEL sel)
* "cYbEr_PuNk11".swapcase #=> "CyBeR_pUnK11"
*/
-static VALUE
+VALUE
rstr_swapcase(VALUE str, SEL sel)
{
str = rb_str_new3(str);
@@ -3910,7 +3910,7 @@ rstr_capitalize_bang(VALUE str, SEL sel)
* "123ABC".capitalize #=> "123abc"
*/
-static VALUE
+VALUE
rstr_capitalize(VALUE str, SEL sel)
{
str = rb_str_new3(str);
View
56 symbol.c
@@ -621,6 +621,58 @@ rsym_aref(VALUE sym, SEL sel, int argc, VALUE *argv)
return rstr_aref(RSYM(sym)->str, sel, argc, argv);
}
+/*
+ * call-seq:
+ * sym.upcase => symbol
+ *
+ * Same as <code>sym.to_s.upcase.intern</code>.
+ */
+
+static VALUE
+rsym_upcase(VALUE sym, SEL sel)
+{
+ return ID2SYM(rb_intern_str(rstr_upcase(RSYM(sym)->str, sel)));
+}
+
+/*
+ * call-seq:
+ * sym.downcase => symbol
+ *
+ * Same as <code>sym.to_s.downcase.intern</code>.
+ */
+
+static VALUE
+rsym_downcase(VALUE sym, SEL sel)
+{
+ return ID2SYM(rb_intern_str(rstr_downcase(RSYM(sym)->str, sel)));
+}
+
+/*
+ * call-seq:
+ * sym.capitalize => symbol
+ *
+ * Same as <code>sym.to_s.capitalize.intern</code>.
+ */
+
+static VALUE
+rsym_capitalize(VALUE sym, SEL sel)
+{
+ return ID2SYM(rb_intern_str(rstr_capitalize(RSYM(sym)->str, sel)));
+}
+
+/*
+ * call-seq:
+ * sym.swapcase => symbol
+ *
+ * Same as <code>sym.to_s.swapcase.intern</code>.
+ */
+
+static VALUE
+rsym_swapcase(VALUE sym, SEL sel)
+{
+ return ID2SYM(rb_intern_str(rstr_swapcase(RSYM(sym)->str, sel)));
+}
+
static CFIndex
rsym_imp_length(void *rcv, SEL sel)
{
@@ -658,6 +710,10 @@ Init_Symbol(void)
rb_objc_define_method(rb_cSymbol, "to_sym", rsym_to_sym, 0);
rb_objc_define_method(rb_cSymbol, "empty?", rsym_empty, 0);
rb_objc_define_method(rb_cSymbol, "[]", rsym_aref, -1);
+ rb_objc_define_method(rb_cSymbol, "upcase", rsym_upcase, 0);
+ rb_objc_define_method(rb_cSymbol, "downcase", rsym_downcase, 0);
+ rb_objc_define_method(rb_cSymbol, "swapcase", rsym_swapcase, 0);
+ rb_objc_define_method(rb_cSymbol, "capitalize", rsym_capitalize, 0);
// Cocoa primitives.
rb_objc_install_method2((Class)rb_cSymbol, "length",
Please sign in to comment.
Something went wrong with that request. Please try again.