[macruby-changes] [3841] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sat Mar 20 17:31:44 PDT 2010
Revision: 3841
http://trac.macosforge.org/projects/ruby/changeset/3841
Author: lsansonetti at apple.com
Date: 2010-03-20 17:31:41 -0700 (Sat, 20 Mar 2010)
Log Message:
-----------
added MatchData#==
Modified Paths:
--------------
MacRuby/trunk/object.c
MacRuby/trunk/re.cpp
Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c 2010-03-21 00:08:50 UTC (rev 3840)
+++ MacRuby/trunk/object.c 2010-03-21 00:31:41 UTC (rev 3841)
@@ -2833,7 +2833,6 @@
return rb_convert_type(val, T_STRING, "String", "to_s");
}
-
/*
* call-seq:
* String(arg) => string
Modified: MacRuby/trunk/re.cpp
===================================================================
--- MacRuby/trunk/re.cpp 2010-03-21 00:08:50 UTC (rev 3840)
+++ MacRuby/trunk/re.cpp 2010-03-21 00:31:41 UTC (rev 3841)
@@ -1704,6 +1704,43 @@
}
/*
+ * call-seq:
+ * mtch == mtch2 => true or false
+ *
+ * Equality---Two matchdata are equal if their target strings,
+ * patterns, and matched positions are identical.
+ */
+
+static VALUE
+match_equal(VALUE rcv, SEL sel, VALUE other)
+{
+ if (rcv == other) {
+ return Qtrue;
+ }
+ if (TYPE(other) != T_MATCH) {
+ return Qfalse;
+ }
+ if (regexp_equal((VALUE)RMATCH(rcv)->regexp, 0,
+ (VALUE)RMATCH(other)->regexp) != Qtrue) {
+ return Qfalse;
+ }
+ if (rb_str_equal(RMATCH(rcv)->str, RMATCH(other)->str) != Qtrue) {
+ return Qfalse;
+ }
+ if (RMATCH(rcv)->results_count != RMATCH(other)->results_count) {
+ return Qfalse;
+ }
+ for (int i = 0; i < RMATCH(rcv)->results_count; i++) {
+ rb_match_result_t *res1 = RMATCH(rcv)->results;
+ rb_match_result_t *res2 = RMATCH(other)->results;
+ if (res1[i].beg != res2[i].beg || res1[i].end != res2[i].end) {
+ return Qfalse;
+ }
+ }
+ return Qtrue;
+}
+
+/*
* Document-class: MatchData
*
* <code>MatchData</code> is the type of the special variable <code>$~</code>,
@@ -1740,6 +1777,8 @@
rb_objc_define_method(rb_cMatch, "to_s", (void *)match_to_s, 0);
rb_objc_define_method(rb_cMatch, "string", (void *)match_string, 0);
rb_objc_define_method(rb_cMatch, "inspect", (void *)match_inspect, 0);
+ rb_objc_define_method(rb_cMatch, "eql?", (void *)match_equal, 1);
+ rb_objc_define_method(rb_cMatch, "==", (void *)match_equal, 1);
}
// Compiler primitives.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100320/26355bdf/attachment-0001.html>
More information about the macruby-changes
mailing list