2 EasyUnit : Simple C++ Unit testing framework
3 Copyright (C) 2004 Barthelemy Dagenais
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 barthelemy@prologique.com
23 #include "simplestring.h"
29 static const int DEFAULT_SIZE
= 20;
31 SimpleString::SimpleString ()
32 : buffer(new char [1])
38 SimpleString::SimpleString (const char *otherBuffer
)
39 : buffer (new char [strlen (otherBuffer
) + 1])
41 strcpy (buffer
, otherBuffer
);
44 SimpleString::SimpleString (const SimpleString
& other
)
46 buffer
= new char [other
.size() + 1];
47 strcpy(buffer
, other
.buffer
);
51 SimpleString
SimpleString::operator= (const SimpleString
& other
)
54 buffer
= new char [other
.size() + 1];
55 strcpy(buffer
, other
.buffer
);
59 SimpleString
SimpleString::operator+ (const SimpleString
& other
)
62 delete [] newS
.buffer
;
63 newS
.buffer
= new char[this->size()+other
.size()+1];
64 strcpy(newS
.buffer
,this->asCharString());
65 newS
.buffer
= strcat(newS
.buffer
,other
.asCharString());
69 char *SimpleString::asCharString () const
74 int SimpleString::size() const
76 return strlen (buffer
);
79 SimpleString::~SimpleString ()
84 bool operator== (const SimpleString
& left
, const SimpleString
& right
)
86 return !strcmp (left
.asCharString (), right
.asCharString ());
89 bool operator!= (const SimpleString
& left
, const SimpleString
& right
)
91 return !(left
== right
);
94 SimpleString
StringFrom (bool value
)
96 char buffer
[sizeof ("false") + 1];
97 sprintf (buffer
, "%s", value
? "true" : "false");
98 return SimpleString(buffer
);
101 SimpleString
StringFrom (const char *value
)
103 return SimpleString(value
);
106 SimpleString
StringFrom (long value
)
108 char buffer
[DEFAULT_SIZE
];
109 sprintf (buffer
, "%ld", value
);
111 return SimpleString(buffer
);
114 SimpleString
StringFrom (int value
)
116 char buffer
[DEFAULT_SIZE
];
117 sprintf (buffer
, "%d", value
);
119 return SimpleString(buffer
);
122 SimpleString
StringFrom (unsigned int value
)
124 char buffer
[DEFAULT_SIZE
];
125 sprintf (buffer
, "%u", value
);
127 return SimpleString(buffer
);
130 SimpleString
StringFrom (double value
)
132 char buffer
[DEFAULT_SIZE
];
133 sprintf (buffer
, "%lf", value
);
135 return SimpleString(buffer
);
138 SimpleString
StringFrom (float value
)
140 char buffer
[DEFAULT_SIZE
];
141 sprintf (buffer
, "%f", value
);
143 return SimpleString(buffer
);
146 SimpleString
StringFrom (const SimpleString
& value
)
148 return SimpleString(value
);