X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/089cdf5d5881c3249575744a94c8fdc0e92cda10..ddef84f1065598678384195233eeb24e835b4acc:/gameserv/myString.cpp diff --git a/gameserv/myString.cpp b/gameserv/myString.cpp index 62637ab..deb3cf3 100644 --- a/gameserv/myString.cpp +++ b/gameserv/myString.cpp @@ -3,6 +3,11 @@ using std::cout; using std::endl; +myString::myString() +{ + string = NULL; +} + myString::myString(char *s) { setString(s); @@ -32,6 +37,24 @@ void myString::setString(char *s) } else { + delete []string; + string = new char[strlen(s) + 1]; + memset(string, 0, (strlen(s) + 1)); + strcpy(string, s); + } +} +void myString::setString(const char *s) +{ + if (!s) + { + if (string) + delete [] string; + + string = NULL; + } + else + { + delete []string; string = new char[strlen(s) + 1]; memset(string, 0, (strlen(s) + 1)); strcpy(string, s); @@ -42,3 +65,21 @@ void myString::setString(const myString *right) { setString(right->string); } + +myString &myString::operator=(myString &right) +{ + setString(right.string); + return *this; +} + +myString &myString::operator=(char *right) +{ + setString(right); + return *this; +} + +myString &myString::operator=(const char *right) +{ + setString(right); + return *this; +}