1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

2000-03-23

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-03-23 08:37:35 +00:00
parent 5c13dd59db
commit 688169fd83
17 changed files with 995 additions and 314 deletions

View file

@ -886,12 +886,16 @@ rb_str_replace(str, beg, len, val)
long beg;
long len;
{
if (RSTRING(str)->len < beg + len) {
len = RSTRING(str)->len - beg;
}
if (len < RSTRING(val)->len) {
/* expand string */
REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len+RSTRING(val)->len-len+1);
}
if (len != RSTRING(val)->len) {
if (RSTRING(val)->len != len) {
memmove(RSTRING(str)->ptr + beg + RSTRING(val)->len,
RSTRING(str)->ptr + beg + len,
RSTRING(str)->len - (beg + len));
@ -899,7 +903,9 @@ rb_str_replace(str, beg, len, val)
if (RSTRING(str)->len < beg && len < 0) {
MEMZERO(RSTRING(str)->ptr + RSTRING(str)->len, char, -len);
}
memmove(RSTRING(str)->ptr+beg, RSTRING(val)->ptr, RSTRING(val)->len);
if (RSTRING(val)->len > 0) {
memmove(RSTRING(str)->ptr+beg, RSTRING(val)->ptr, RSTRING(val)->len);
}
RSTRING(str)->len += RSTRING(val)->len - len;
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
}
@ -1017,6 +1023,9 @@ rb_str_slice_bang(argc, argv, str)
if (pos < 0) {
pos = RSTRING(str)->len + pos;
}
if (pos < 0 || RSTRING(str)->len <= pos) {
rb_raise(rb_eIndexError, "index %d out of string", pos);
}
arg2 = rb_str_substr(str, pos, len);
rb_str_replace(str, pos, len, rb_str_new(0,0));
return arg2;