00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Basics.H"
00027 #include "Text.H"
00028
00029 #include "TextCommon.C"
00030
00031 bool Text::GCImpl() throw () { return false; }
00032
00033 static const char *StrConcat(const char *str1, const char *str2) throw ()
00034
00035
00036 {
00037
00038 int len1 = strlen(str1), len2 = strlen(str2) + 1;
00039 char *res = NEW_ARRAY(char, len1 + len2);
00040 if (len1 == 0) {
00041 memcpy(res, str2, len2);
00042 } else {
00043 memcpy(res, str1, len1);
00044 memcpy(res + len1, str2, len2);
00045 }
00046 return res;
00047 }
00048
00049
00050 Text::Text(const Text& t) throw ()
00051 {
00052 this->s = StrCopy(t.s);
00053 }
00054
00055 Text::Text(const char c) throw ()
00056 {
00057 char *temp = NEW_ARRAY(char, 2);
00058 temp[0] = c; temp[1] = '\0';
00059 this->s = temp;
00060 }
00061
00062
00063 Text::~Text() throw ()
00064 {
00065 if (this->s != EmptyStr) {
00066 delete[] (char *)(this->s);
00067 this->s = (char *)NULL;
00068 }
00069 }
00070
00071
00072 Text& Text::operator = (const char* str) throw ()
00073 {
00074 if (this->s != EmptyStr) delete[] (char *)(this->s);
00075 this->s = StrCopy(str);
00076 return *this;
00077 }
00078
00079 Text& Text::operator = (const Text& t) throw ()
00080 {
00081 if (this->s != EmptyStr) delete[] (char *)(this->s);
00082 this->s = StrCopy(t.s);
00083 return *this;
00084 }
00085
00086
00087 bool operator == (const Text& t1, const Text& t2) throw ()
00088 {
00089 return ((t1.s == t2.s) || (strcmp(t1.s, t2.s) == 0));
00090 }
00091
00092 bool operator != (const Text& t1, const Text& t2) throw ()
00093 {
00094 return ((t1.s != t2.s) && (strcmp(t1.s, t2.s) != 0));
00095 }
00096
00097
00098 Text operator + (const Text& t1, const Text& t2) throw ()
00099 {
00100 return Text(StrConcat(t1.s, t2.s), (void*)1);
00101 }
00102
00103 Text operator + (const char* str, const Text& t) throw ()
00104 {
00105 return Text(StrConcat(str, t.s), (void*)1);
00106 }
00107
00108 Text operator + (const Text& t, const char* str) throw ()
00109 {
00110 return Text(StrConcat(t.s, str), (void*)1);
00111 }
00112
00113
00114 Text& Text::operator += (const char* str) throw ()
00115 {
00116 const char *oldS = this->s;
00117 this->s = StrConcat(oldS, str);
00118 if (oldS != EmptyStr) delete[] (char *)oldS;
00119 return *this;
00120 }
00121
00122 Text& Text::operator += (const Text& t) throw ()
00123 {
00124 const char *oldS = this->s;
00125 this->s = StrConcat(oldS, t.s);
00126 if (oldS != EmptyStr) delete[] (char *)oldS;
00127 return *this;
00128 }