summaryrefslogtreecommitdiff
path: root/ext/strscan/strscan.c
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-05 11:20:12 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-05 11:20:12 +0000
commit492dfc7c0839f406008e52b2b09db349791e2895 (patch)
treef4214efbdd1b9c1e13c140138e92241905dab943 /ext/strscan/strscan.c
parent87275504ab0690e243401db6985f6253ccc17b65 (diff)
* ext/strscan/strscan.c: new method StringScanner#initialize_copy to allow #dup and #clone.
* test/strscan/test_strscan.rb: test StringScanner#dup. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/strscan/strscan.c')
-rw-r--r--ext/strscan/strscan.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index 227ed92..68471ed 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -73,10 +73,12 @@ static VALUE infect _((VALUE str, struct strscanner *p));
static VALUE extract_range _((struct strscanner *p, long beg_i, long end_i));
static VALUE extract_beg_len _((struct strscanner *p, long beg_i, long len));
+void check_strscan _((VALUE obj));
static void strscan_mark _((struct strscanner *p));
static void strscan_free _((struct strscanner *p));
static VALUE strscan_s_allocate _((VALUE klass));
static VALUE strscan_initialize _((int argc, VALUE *argv, VALUE self));
+static VALUE strscan_init_copy _((VALUE vself, VALUE vorig));
static VALUE strscan_s_mustc _((VALUE self));
static VALUE strscan_terminate _((VALUE self));
@@ -217,6 +219,38 @@ strscan_initialize(argc, argv, self)
return self;
}
+void
+check_strscan(obj)
+ VALUE obj;
+{
+ if (TYPE(obj) != T_DATA || RDATA(obj)->dmark != (RUBY_DATA_FUNC)strscan_mark) {
+ rb_raise(rb_eTypeError,
+ "wrong argument type %s (expected StringScanner)",
+ rb_obj_classname(obj));
+ }
+}
+
+/*
+ * call-seq:
+ * dup
+ * clone
+ *
+ * Duplicates a StringScanner object.
+ */
+static VALUE
+strscan_init_copy(vself, vorig)
+ VALUE vself, vorig;
+{
+ struct strscanner *self, *orig;
+
+ Data_Get_Struct(vself, struct strscanner, self);
+ check_strscan(vorig);
+ Data_Get_Struct(vorig, struct strscanner, orig);
+ memmove(self, orig, sizeof(struct strscanner));
+
+ return vself;
+}
+
/* =======================================================================
Instance Methods
@@ -1291,6 +1325,7 @@ Init_strscan()
rb_define_alloc_func(StringScanner, strscan_s_allocate);
rb_define_private_method(StringScanner, "initialize", strscan_initialize, -1);
+ rb_define_private_method(StringScanner, "initialize_copy", strscan_init_copy, 1);
rb_define_singleton_method(StringScanner, "must_C_version", strscan_s_mustc, 0);
rb_define_method(StringScanner, "reset", strscan_reset, 0);
rb_define_method(StringScanner, "terminate", strscan_terminate, 0);