[macruby-changes] [3834] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 19 17:17:30 PDT 2010
Revision: 3834
http://trac.macosforge.org/projects/ruby/changeset/3834
Author: lsansonetti at apple.com
Date: 2010-03-19 17:17:30 -0700 (Fri, 19 Mar 2010)
Log Message:
-----------
added Symbol #upcase, #downcase, #swapcase, #capitalize
Modified Paths:
--------------
MacRuby/trunk/string.c
MacRuby/trunk/symbol.c
Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c 2010-03-20 00:00:58 UTC (rev 3833)
+++ MacRuby/trunk/string.c 2010-03-20 00:17:30 UTC (rev 3834)
@@ -3762,7 +3762,7 @@
* "hEllO".downcase #=> "hello"
*/
-static VALUE
+VALUE
rstr_downcase(VALUE str, SEL sel)
{
str = rb_str_new3(str);
@@ -3806,7 +3806,7 @@
* "hEllO".upcase #=> "HELLO"
*/
-static VALUE
+VALUE
rstr_upcase(VALUE str, SEL sel)
{
str = rb_str_new3(str);
@@ -3854,7 +3854,7 @@
* "cYbEr_PuNk11".swapcase #=> "CyBeR_pUnK11"
*/
-static VALUE
+VALUE
rstr_swapcase(VALUE str, SEL sel)
{
str = rb_str_new3(str);
@@ -3910,7 +3910,7 @@
* "123ABC".capitalize #=> "123abc"
*/
-static VALUE
+VALUE
rstr_capitalize(VALUE str, SEL sel)
{
str = rb_str_new3(str);
Modified: MacRuby/trunk/symbol.c
===================================================================
--- MacRuby/trunk/symbol.c 2010-03-20 00:00:58 UTC (rev 3833)
+++ MacRuby/trunk/symbol.c 2010-03-20 00:17:30 UTC (rev 3834)
@@ -621,6 +621,58 @@
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 @@
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",
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100319/de046485/attachment.html>
More information about the macruby-changes
mailing list