[macruby-changes] [3913] MacRuby/trunk/re.cpp

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 7 00:33:54 PDT 2010


Revision: 3913
          http://trac.macosforge.org/projects/ruby/changeset/3913
Author:   lsansonetti at apple.com
Date:     2010-04-07 00:33:50 -0700 (Wed, 07 Apr 2010)
Log Message:
-----------
added #names and #names_captures (atm returning empty collections)

Modified Paths:
--------------
    MacRuby/trunk/re.cpp

Modified: MacRuby/trunk/re.cpp
===================================================================
--- MacRuby/trunk/re.cpp	2010-04-07 00:47:27 UTC (rev 3912)
+++ MacRuby/trunk/re.cpp	2010-04-07 07:33:50 UTC (rev 3913)
@@ -1082,7 +1082,59 @@
     return RREGEXP(rcv)->fixed_encoding ? Qtrue : Qfalse;
 }
 
+/*
+ * call-seq:
+ *    rxp.names   => [name1, name2, ...]
+ *
+ * Returns a list of names of captures as an array of strings.
+ *
+ *     /(?<foo>.)(?<bar>.)(?<baz>.)/.names
+ *     #=> ["foo", "bar", "baz"]
+ *
+ *     /(?<foo>.)(?<foo>.)/.names
+ *     #=> ["foo"]
+ *
+ *     /(.)(.)/.names
+ *     #=> []
+ */
+
 static VALUE
+regexp_names(VALUE rcv, SEL sel)
+{
+    // TODO
+    return rb_ary_new();
+}
+
+/*
+ * call-seq:
+ *    rxp.named_captures  => hash
+ *
+ * Returns a hash representing information about named captures of <i>rxp</i>.
+ *
+ * A key of the hash is a name of the named captures.
+ * A value of the hash is an array which is list of indexes of corresponding
+ * named captures.
+ *
+ *    /(?<foo>.)(?<bar>.)/.named_captures
+ *    #=> {"foo"=>[1], "bar"=>[2]}
+ *
+ *    /(?<foo>.)(?<foo>.)/.named_captures
+ *    #=> {"foo"=>[1, 2]}
+ *
+ * If there are no named captures, an empty hash is returned.
+ *
+ *    /(.)(.)/.named_captures
+ *    #=> {}
+ */
+
+static VALUE
+regexp_named_captures(VALUE rcv, SEL sel)
+{
+    // TODO
+    return rb_hash_new();
+}
+
+static VALUE
 match_getter(void)
 {
     VALUE match = rb_backref_get();
@@ -1218,10 +1270,10 @@
 	    (void *)regexp_fixed_encoding, 0);
 #if 0
     rb_objc_define_method(rb_cRegexp, "encoding", rb_reg_encoding, 0);
-    rb_objc_define_method(rb_cRegexp, "names", rb_reg_names, 0);
+#endif
+    rb_objc_define_method(rb_cRegexp, "names", (void *)regexp_names, 0);
     rb_objc_define_method(rb_cRegexp, "named_captures",
-	    rb_reg_named_captures, 0);
-#endif
+	    (void *)regexp_named_captures, 0);
     rb_objc_define_method(rb_cRegexp, "to_s", (void *)regexp_to_s, 0);
     rb_objc_define_method(rb_cRegexp, "inspect", (void *)regexp_inspect, 0);
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100407/bf19e480/attachment.html>


More information about the macruby-changes mailing list