00001
00020 #include "mfcpch.h"
00021 #include "tprintf.h"
00022 #include "strngs.h"
00023
00024
00028 STRING & STRING::operator= (
00029 const char *string
00030 ) {
00031 if (string != NULL) {
00032 INT32
00033 length = strlen (string) + 1;
00034
00035 if (ptr == NULL)
00036
00037 ptr = alloc_string (length);
00038
00039 else if (strlen (ptr) != (UINT32) length - 1) {
00040 free_string(ptr);
00041
00042 ptr = alloc_string (length);
00043 }
00044 if (ptr == NULL) {
00045 tprintf ("No memory to allocate string");
00046 return *this;
00047 }
00048 strcpy(ptr, string);
00049 }
00050 else {
00051 if (ptr == NULL)
00052 ptr = alloc_string (1);
00053
00054 else if (strlen (ptr) != 0) {
00055 free_string(ptr);
00056 ptr = alloc_string (1);
00057 }
00058 if (ptr == NULL) {
00059 tprintf ("No memory to allocate string");
00060 return *this;
00061 }
00062 *ptr = '\0';
00063 }
00064
00065 return *this;
00066 }
00067
00068
00069
00073 STRING
00074 STRING::operator+ (
00075 const STRING & string
00076 ) const
00077 {
00078 INT32 length;
00079 STRING result;
00080
00081 if (ptr == NULL)
00082 length = 0;
00083 else
00084 length = strlen (ptr);
00085 result.ptr = alloc_string (length + strlen (string.ptr) + 1);
00086
00087 if (result.ptr == NULL) {
00088 tprintf ("No memory to allocate string");
00089 return result;
00090 }
00091 result.ptr[0] = '\0';
00092 if (ptr != NULL)
00093 strcpy (result.ptr, ptr);
00094 if (string.ptr != NULL)
00095
00096 strcpy (result.ptr + length, string.ptr);
00097 return result;
00098 }
00099
00100
00101
00105 STRING
00106 STRING::operator+ (
00107 const char ch
00108 ) const
00109 {
00110 INT32 length;
00111 STRING result;
00112
00113 if (ptr == NULL)
00114 length = 0;
00115 else
00116 length = strlen (ptr);
00117
00118 result.ptr = alloc_string (length + 2);
00119 if (result.ptr == NULL) {
00120 tprintf ("No memory to allocate string");
00121 return result;
00122 }
00123 if (ptr != NULL)
00124 strcpy (result.ptr, ptr);
00125 result.ptr[length] = ch;
00126 result.ptr[length + 1] = '\0';
00127 return result;
00128 }
00129
00130
00131
00137 STRING & STRING::operator+= (
00138 const char *string
00139 ) {
00140 INT32
00141 length;
00142 char *
00143 src;
00144
00145 if (string == NULL || string[0] == '\0')
00146 return *this;
00147 if (ptr == NULL)
00148 length = 0;
00149 else
00150 length = strlen (ptr);
00151 src = ptr;
00152
00153 ptr = alloc_string (length + strlen (string) + 1);
00154 if (ptr == NULL) {
00155 tprintf ("No memory to allocate string");
00156 ptr = src;
00157 return *this;
00158 }
00159 if (src != NULL) {
00160 strcpy(ptr, src);
00161 free_string(src);
00162 }
00163 strcpy (ptr + length, string);
00164 return *this;
00165 }
00166
00167
00168
00172 STRING & STRING::operator+= (
00173 const char ch
00174 ) {
00175 INT32
00176 length;
00177 char *
00178 src;
00179
00180 if (ch == '\0')
00181 return *this;
00182 if (ptr == NULL)
00183 length = 0;
00184 else
00185 length = strlen (ptr);
00186 src = ptr;
00187
00188 ptr = alloc_string (length + 2);
00189 if (ptr == NULL) {
00190 tprintf ("No memory to allocate string");
00191 ptr = src;
00192 return *this;
00193 }
00194 if (src != NULL) {
00195 strcpy(ptr, src);
00196 free_string(src);
00197 }
00198 ptr[length] = ch;
00199 ptr[length + 1] = '\0';
00200 return *this;
00201 }