summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-27 08:31:08 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-27 08:31:08 +0000
commitc45908e41f47c88674b73a754ecd0535449b667a (patch)
treea27bb0f2ca80fa80b9582ddcb8312eee673b0bd5 /string.c
parentcd3d4a01f248fad1a73ff0b66b7a8d1653f64c19 (diff)
* file.c (rb_find_file): $LOAD_PATH must not be empty.
* file.c (rb_find_file_ext): ditto. * range.c (range_eq): class check should be based on range.class, instead of Range to work with Range.dup. * range.c (range_eql): ditto. * class.c (rb_mod_dup): need to preserve metaclass and flags. * object.c (rb_cstr_to_dbl): had a buffer overrun. * marshal.c (w_class): integrate singleton check into a funciton to follow DRY principle. * marshal.c (w_uclass): should check singleton method. * object.c (rb_obj_dup): dmark and dfree functions must be match for T_DATA type. * object.c (rb_obj_dup): class of the duped object must be match to the class of the original. * re.c (rb_reg_quote): do not escape \t, \f, \r, \n, for they are not regular expression metacharacters. * time.c (time_s_alloc): use time_free instead of free (null check, also serves for type mark). * time.c (time_s_at): check dfree function too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c52
1 files changed, 6 insertions, 46 deletions
diff --git a/string.c b/string.c
index 7488940275..a4f597f2a4 100644
--- a/string.c
+++ b/string.c
@@ -292,56 +292,17 @@ rb_obj_as_string(obj)
return str;
}
-static VALUE
-str_copy(str, clone)
- VALUE str;
- int clone;
-{
- VALUE str2;
- int flags;
-
- StringValue(str);
-
- if (FL_TEST(str, ELTS_SHARED)) {
- str2 = rb_str_new3(RSTRING(str)->aux.shared);
- }
- else if (FL_TEST(str, STR_ASSOC)) {
- str2 = str_new(RSTRING(str)->ptr, RSTRING(str)->len);
- RSTRING(str2)->aux.shared = RSTRING(str)->aux.shared;
- }
- else if (OBJ_FROZEN(str)) {
- str2 = rb_str_new3(str);
- }
- else {
- str2 = rb_str_new3(rb_str_new4(str));
- }
- flags = FL_TEST(str2, ELTS_SHARED|STR_ASSOC);
- if (clone) {
- CLONESETUP(str2, str);
- }
- else {
- DUPSETUP(str2, str);
- }
- if (flags) FL_SET(str2, flags);
- return str2;
-}
+static VALUE rb_str_replace _((VALUE, VALUE));
VALUE
rb_str_dup(str)
VALUE str;
{
- return str_copy(str, Qfalse);
-}
-
-static VALUE
-rb_str_clone(str)
- VALUE str;
-{
- return str_copy(str, Qtrue);
+ VALUE dup = rb_str_s_alloc(rb_cString);
+ rb_str_replace(dup, str);
+ return dup;
}
-static VALUE rb_str_replace _((VALUE, VALUE));
-
static VALUE
rb_str_init(argc, argv, str)
int argc;
@@ -1425,7 +1386,7 @@ get_pat(pat)
}
val = rb_reg_quote(pat);
#if RUBY_VERSION_CODE < 180
- if (val != pat) {
+ if (val != pat && rb_str_cmp(val, pat) != 0) {
rb_warn("string pattern instead of regexp; metacharacters no longer effective");
}
#endif
@@ -3154,8 +3115,7 @@ Init_String()
rb_include_module(rb_cString, rb_mEnumerable);
rb_define_singleton_method(rb_cString, "allocate", rb_str_s_alloc, 0);
rb_define_method(rb_cString, "initialize", rb_str_init, -1);
- rb_define_method(rb_cString, "clone", rb_str_clone, 0);
- rb_define_method(rb_cString, "dup", rb_str_dup, 0);
+ rb_define_method(rb_cString, "become", rb_str_replace, 1);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
rb_define_method(rb_cString, "==", rb_str_equal, 1);
rb_define_method(rb_cString, "===", rb_str_equal, 1);