]> jfr.im git - irc/gameservirc.git/blame - gameserv/myString.cpp
Implemented the myString class in the player and monster classes. This should make...
[irc/gameservirc.git] / gameserv / myString.cpp
CommitLineData
138b009f 1#include "myString.h"
c260a8d7 2#include <iostream>
3using std::cout;
4using std::endl;
138b009f 5
ddef84f1 6myString::myString()
7{
8 string = NULL;
9}
10
138b009f 11myString::myString(char *s)
12{
13 setString(s);
14}
15
c260a8d7 16myString::myString(const myString &right)
17{
18 setString(&right);
19}
20
138b009f 21myString::~myString()
22{
23 if (string)
24 delete [] string;
25
26 string = NULL;
27}
28
29void myString::setString(char *s)
30{
31 if (!s)
32 {
87137def 33 if (string)
34 delete [] string;
35
36 string = NULL;
138b009f 37 }
38 else
39 {
ddef84f1 40 delete []string;
41 string = new char[strlen(s) + 1];
42 memset(string, 0, (strlen(s) + 1));
43 strcpy(string, s);
44 }
45}
46void myString::setString(const char *s)
47{
48 if (!s)
49 {
50 if (string)
51 delete [] string;
52
53 string = NULL;
54 }
55 else
56 {
57 delete []string;
138b009f 58 string = new char[strlen(s) + 1];
59 memset(string, 0, (strlen(s) + 1));
60 strcpy(string, s);
61 }
62}
c260a8d7 63
64void myString::setString(const myString *right)
65{
66 setString(right->string);
67}
ddef84f1 68
69myString &myString::operator=(myString &right)
70{
71 setString(right.string);
72 return *this;
73}
74
75myString &myString::operator=(char *right)
76{
77 setString(right);
78 return *this;
79}
80
81myString &myString::operator=(const char *right)
82{
83 setString(right);
84 return *this;
85}