Permalink
Browse files

added NSString primitives to Symbol

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/icu@3655 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 2194947 commit b3f59324ae04849862a97ce279f8e30b81636b03 @lrz lrz committed Feb 28, 2010
Showing with 19 additions and 0 deletions.
  1. +19 −0 symbol.c
View
19 symbol.c
@@ -14,6 +14,7 @@
#include "symbol.h"
#include "ruby/node.h"
#include "vm.h"
+#include "objc.h"
VALUE rb_cSymbol;
@@ -344,6 +345,18 @@ rsym_to_sym(VALUE sym, SEL sel)
return sym;
}
+static CFIndex
+rsym_imp_length(void *rcv, SEL sel)
+{
+ return CFStringGetLength((CFStringRef)RSYM(rcv)->str);
+}
+
+static UniChar
+rsym_imp_characterAtIndex(void *rcv, SEL sel, CFIndex idx)
+{
+ return CFStringGetCharacterAtIndex((CFStringRef)RSYM(rcv)->str, idx);
+}
+
void
Init_Symbol(void)
{
@@ -366,4 +379,10 @@ Init_Symbol(void)
rb_objc_define_method(rb_cSymbol, "description", rsym_to_s, 0);
rb_objc_define_method(rb_cSymbol, "intern", rsym_to_sym, 0);
rb_objc_define_method(rb_cSymbol, "to_sym", rsym_to_sym, 0);
+
+ // Cocoa primitives.
+ rb_objc_install_method2((Class)rb_cSymbol, "length",
+ (IMP)rsym_imp_length);
+ rb_objc_install_method2((Class)rb_cSymbol, "characterAtIndex:",
+ (IMP)rsym_imp_characterAtIndex);
}

0 comments on commit b3f5932

Please sign in to comment.