home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1991
/
10
/
string
/
strirem.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-30
|
652b
|
30 lines
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <string.hpp>
String &String::remove(int pos, int count)
{
if (count <= 0 || pos >= length())
return *this;
if (count > length()-pos) count = length()-pos;
int nl = length()-count;
srep *p = 0;
if (nl) {
p = new(nl) srep(nl);
if (!p) {
errno = ENOMEM;
return *this;
}
memmove(p->body,body(),pos);
memmove(p->body+pos,body()+pos+count,nl-pos);
}
if (rp) {
if (--rp->refs < 1)
delete rp;
}
rp = p;
rp->refs++;
return *this;
}