Changeset 7944 for trunk/mgpp
- Timestamp:
- 2004-08-14T07:30:16+12:00 (20 years ago)
- Location:
- trunk/mgpp/text
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mgpp/text/UCArray.cpp
r3365 r7944 30 30 text.push_back (*cStr); 31 31 cStr++; 32 } 33 } 34 35 void SetCStr (UCArray &text, const char *cStr, size_t nSizeHint) { 36 text.erase(text.begin(), text.end()); 37 38 // reserve the needed space in advance 39 if (text.capacity() < nSizeHint + 1) { 40 text.reserve(nSizeHint + 1); 41 } 42 while (*cStr != '\0') { 43 text.push_back (*cStr); 44 ++cStr; 32 45 } 33 46 } … … 53 66 while (here != end) { 54 67 s << *here; 55 here++;68 ++here; 56 69 } 57 70 … … 133 146 if (!ReadVarLenUL (f, arraySize)) return false; 134 147 148 // reserve the needed space in advance 149 if (a.capacity() < arraySize + 1) { 150 a.reserve(arraySize + 1); 151 } 152 135 153 // read in the array 136 154 unsigned char b = 0; … … 156 174 if (ferror (f) != 0) return false; 157 175 158 here++;176 ++here; 159 177 } 160 178 … … 219 237 pos = diff; 220 238 221 a1Here++;222 a2Here++;239 ++a1Here; 240 ++a2Here; 223 241 } 224 242 … … 234 252 235 253 while (i < l && *a1Here == *a2Here) { 236 i++; a1Here++; a2Here++;254 i++; ++a1Here; ++a2Here; 237 255 } 238 256 … … 255 273 char* tmp=GetCStr(a); 256 274 int ret=(fwrite (tmp+preLen, sizeof (char), sufLen, f) == sufLen); 257 delete (tmp);258 return (ret );275 delete []tmp; 276 return (ret != 0); 259 277 } 260 278 … … 267 285 sufLen = fgetc(f); 268 286 269 if (a.size () > preLen) a.erase (a.begin()+preLen, a.end()); 287 if (a.size() > preLen) a.erase (a.begin()+preLen, a.end()); 288 289 // reserve the needed space in advance 290 if (a.capacity() < a.size() + sufLen + 1) { 291 a.reserve(a.size() + sufLen + 1); 292 } 293 270 294 while (sufLen > 0) { 271 295 unsigned char c = fgetc (f); -
trunk/mgpp/text/UCArray.h
r3365 r7944 55 55 // functions to manipulate UCArrays 56 56 void SetCStr (UCArray &text, const char *cStr); 57 // same as SetCStr but first tries to allocate nSizeHint space (only if needed) 58 void SetCStr (UCArray &text, const char *cStr, size_t nSizeHint); 57 59 char * GetCStr(UCArray text); 58 60 inline void UCArrayClear (UCArray &a) {
Note:
See TracChangeset
for help on using the changeset viewer.