D:/Programming/GUI Editor (Source)/tinystr.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "stdafx.h"
00025 #include "tinyxml.h"
00026
00027 #ifndef TIXML_USE_STL
00028
00029
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <ctype.h>
00033
00034 #include "tinystr.h"
00035
00036
00037 TiXmlString::TiXmlString (const char* instring)
00038 {
00039 unsigned newlen;
00040 char * newstring;
00041
00042 if (!instring)
00043 {
00044 allocated = 0;
00045 cstring = NULL;
00046 current_length = 0;
00047 return;
00048 }
00049 newlen = strlen (instring) + 1;
00050 newstring = new char [newlen];
00051 memcpy (newstring, instring, newlen);
00052
00053 allocated = newlen;
00054 cstring = newstring;
00055 current_length = newlen - 1;
00056 }
00057
00058
00059 TiXmlString::TiXmlString (const TiXmlString& copy)
00060 {
00061 unsigned newlen;
00062 char * newstring;
00063
00064
00065 if ( © == this )
00066 return;
00067
00068 if (! copy . allocated)
00069 {
00070 allocated = 0;
00071 cstring = NULL;
00072 current_length = 0;
00073 return;
00074 }
00075 newlen = copy . length () + 1;
00076 newstring = new char [newlen];
00077
00078 memcpy (newstring, copy . cstring, newlen);
00079 allocated = newlen;
00080 cstring = newstring;
00081 current_length = newlen - 1;
00082 }
00083
00084
00085 void TiXmlString ::operator = (const char * content)
00086 {
00087 unsigned newlen;
00088 char * newstring;
00089
00090 if (! content)
00091 {
00092 empty_it ();
00093 return;
00094 }
00095 newlen = strlen (content) + 1;
00096 newstring = new char [newlen];
00097
00098 memcpy (newstring, content, newlen);
00099 empty_it ();
00100 allocated = newlen;
00101 cstring = newstring;
00102 current_length = newlen - 1;
00103 }
00104
00105
00106 void TiXmlString ::operator = (const TiXmlString & copy)
00107 {
00108 unsigned newlen;
00109 char * newstring;
00110
00111 if (! copy . length ())
00112 {
00113 empty_it ();
00114 return;
00115 }
00116 newlen = copy . length () + 1;
00117 newstring = new char [newlen];
00118
00119 memcpy (newstring, copy . c_str (), newlen);
00120 empty_it ();
00121 allocated = newlen;
00122 cstring = newstring;
00123 current_length = newlen - 1;
00124 }
00125
00126
00127
00128 void TiXmlString::Append( const char* str, int len )
00129 {
00130 char * new_string;
00131 unsigned new_alloc, new_size, size_suffix;
00132
00133
00134 const char* p = str;
00135 size_suffix = 0;
00136
00137 while ( *p && size_suffix < (unsigned)len )
00138 {
00139 ++p;
00140 ++size_suffix;
00141 }
00142 if ( !size_suffix)
00143 return;
00144
00145 new_size = length () + size_suffix + 1;
00146
00147 if (new_size > allocated)
00148 {
00149
00150 new_alloc = assign_new_size (new_size);
00151
00152
00153 new_string = new char [new_alloc];
00154 new_string [0] = 0;
00155
00156
00157 if (allocated && cstring)
00158
00159 memcpy (new_string, cstring, length ());
00160
00161
00162
00163 memcpy (new_string + length (),
00164 str,
00165 size_suffix);
00166
00167
00168 if (allocated && cstring)
00169 delete [] cstring;
00170
00171
00172 cstring = new_string;
00173 allocated = new_alloc;
00174 }
00175 else
00176 {
00177
00178
00179 memcpy (cstring + length (),
00180 str,
00181 size_suffix);
00182 }
00183 current_length = new_size - 1;
00184 cstring [current_length] = 0;
00185 }
00186
00187
00188
00189 void TiXmlString::Append( const char * suffix )
00190 {
00191 char * new_string;
00192 unsigned new_alloc, new_size;
00193
00194 new_size = length () + strlen (suffix) + 1;
00195
00196 if (new_size > allocated)
00197 {
00198
00199 new_alloc = assign_new_size (new_size);
00200
00201
00202 new_string = new char [new_alloc];
00203 new_string [0] = 0;
00204
00205
00206 if (allocated && cstring)
00207 memcpy (new_string, cstring, 1 + length ());
00208
00209
00210
00211
00212 memcpy (new_string + length (),
00213 suffix,
00214 strlen (suffix) + 1);
00215
00216
00217 if (allocated && cstring)
00218 delete [] cstring;
00219
00220
00221 cstring = new_string;
00222 allocated = new_alloc;
00223 }
00224 else
00225 {
00226
00227
00228 memcpy (cstring + length (),
00229 suffix,
00230 strlen (suffix) + 1);
00231 }
00232 current_length = new_size - 1;
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 unsigned TiXmlString::find (char tofind, unsigned offset) const
00251 {
00252 char * lookup;
00253
00254 if (offset >= length ())
00255 return (unsigned) notfound;
00256 for (lookup = cstring + offset; * lookup; lookup++)
00257 if (* lookup == tofind)
00258 return lookup - cstring;
00259 return (unsigned) notfound;
00260 }
00261
00262
00263 bool TiXmlString::operator == (const TiXmlString & compare) const
00264 {
00265 if ( allocated && compare.allocated )
00266 {
00267 assert( cstring );
00268 assert( compare.cstring );
00269 return ( strcmp( cstring, compare.cstring ) == 0 );
00270 }
00271 return false;
00272 }
00273
00274
00275 bool TiXmlString::operator < (const TiXmlString & compare) const
00276 {
00277 if ( allocated && compare.allocated )
00278 {
00279 assert( cstring );
00280 assert( compare.cstring );
00281 return ( strcmp( cstring, compare.cstring ) > 0 );
00282 }
00283 return false;
00284 }
00285
00286
00287 bool TiXmlString::operator > (const TiXmlString & compare) const
00288 {
00289 if ( allocated && compare.allocated )
00290 {
00291 assert( cstring );
00292 assert( compare.cstring );
00293 return ( strcmp( cstring, compare.cstring ) < 0 );
00294 }
00295 return false;
00296 }
00297
00298
00299 #endif // TIXML_USE_STL
Generated on Sun Jul 17 21:34:28 2005 for OpenGL GUI by
1.3.8