Revision: 3675 http://trac.macosforge.org/projects/ruby/changeset/3675 Author: lsansonetti@apple.com Date: 2010-03-02 18:55:45 -0800 (Tue, 02 Mar 2010) Log Message: ----------- misc bug fixes Modified Paths: -------------- MacRuby/branches/icu/string.c Modified: MacRuby/branches/icu/string.c =================================================================== --- MacRuby/branches/icu/string.c 2010-03-03 02:45:54 UTC (rev 3674) +++ MacRuby/branches/icu/string.c 2010-03-03 02:55:45 UTC (rev 3675) @@ -1215,37 +1215,42 @@ /* * call-seq: - * String.new(str="") => new_str + * str.replace(other_str) => str * - * Returns a new string object containing a copy of <i>str</i>. + * Replaces the contents and taintedness of <i>str</i> with the corresponding + * values in <i>other_str</i>. + * + * s = "hello" #=> "hello" + * s.replace "world" #=> "world" */ static VALUE -rstr_initialize(VALUE self, SEL sel, int argc, VALUE *argv) +rstr_replace(VALUE self, SEL sel, VALUE arg) { - if (argc > 0) { - assert(argc == 1); - str_replace(RSTR(self), argv[0]); + rstr_modify(self); + str_replace(RSTR(self), arg); + if (OBJ_TAINTED(arg)) { + OBJ_TAINT(self); } return self; } /* * call-seq: - * str.replace(other_str) => str + * String.new(str="") => new_str * - * Replaces the contents and taintedness of <i>str</i> with the corresponding - * values in <i>other_str</i>. - * - * s = "hello" #=> "hello" - * s.replace "world" #=> "world" + * Returns a new string object containing a copy of <i>str</i>. */ static VALUE -rstr_replace(VALUE self, SEL sel, VALUE arg) +rstr_initialize(VALUE self, SEL sel, int argc, VALUE *argv) { - rstr_modify(self); - str_replace(RSTR(self), arg); + VALUE orig; + if (argc > 0 && rb_scan_args(argc, argv, "01", &orig) == 1) { + if (self != orig) { + rstr_replace(self, 0, orig); + } + } return self; } @@ -1776,6 +1781,9 @@ { rb_str_t *newstr = str_dup(RSTR(self)); str_concat_string(newstr, str_need_string(other)); + if (OBJ_TAINTED(self) || OBJ_TAINTED(other)) { + OBJ_TAINT(newstr); + } return (VALUE)newstr; }
participants (1)
-
source_changes@macosforge.org