]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/myString.cpp
Implemented the myString class in the player and monster classes. This should make...
[irc/gameservirc.git] / gameserv / myString.cpp
index 62637ab708a99e9a1e04270c506f3652df5a4e71..deb3cf3fc7f088435ec74cd7bda41b652dcb477a 100644 (file)
@@ -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;
+}