- Timestamp:
- Sep 8, 2021, 4:40:08 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 5a40e4e
- Parents:
- f26923e
- Location:
- libcfa/src/containers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/string_res.cfa
rf26923e rd8d512e 223 223 } 224 224 225 void ?=?(string_res &s, const char* other) { 226 string_res sother = other; 227 const string_res & sother_ref = sother; 228 s = sother_ref; // `s = sother` calls autogen ?=? 229 } 230 231 void ?=?(string_res &s, char other) { 232 char otherCstr[2] = {other, 0}; 233 s = otherCstr; 234 } 235 236 // Copy assignment operator 237 void ?=?(string_res & this, const string_res & rhs) with( this ) { 225 void assign(string_res &this, const char* buffer, size_t bsize) { 238 226 239 227 char * afterBegin = this.Handle.s + this.Handle.lnth; … … 251 239 252 240 string_res pasting = { beforeBegin, beforeLen }; 253 pasting += rhs;241 append(pasting, buffer, bsize); 254 242 string_res after = { afterBegin, afterLen }; // juxtaposed with in-progress pasting 255 243 pasting += after; // optimized case … … 258 246 259 247 this.Handle.s = pasting.Handle.s + beforeLen; 260 this.Handle.lnth = rhs.Handle.lnth;248 this.Handle.lnth = bsize; 261 249 MoveThisAfter( this.Handle, pasting.Handle ); 262 250 … … 314 302 } 315 303 304 void ?=?(string_res &s, const char* other) { 305 assign(s, other, strlen(other)); 306 } 307 308 void ?=?(string_res &s, char other) { 309 assign(s, &other, 1); 310 } 311 312 // Copy assignment operator 313 void ?=?(string_res & this, const string_res & rhs) with( this ) { 314 assign(this, rhs.Handle.s, rhs.Handle.lnth); 315 } 316 316 317 void ?=?(string_res & this, string_res & rhs) with( this ) { 317 318 const string_res & rhs2 = rhs; … … 340 341 } 341 342 343 342 344 /////////////////////////////////////////////////////////////////// 343 // Slice-Concatenate helper 344 345 void append(string_res &str1, const string_res & str_src, size_t start, size_t end) { 346 size_t clnth = size(str1) + end - start; 347 if ( str1.Handle.s + size(str1) == str_src.Handle.s && start == 0) { // already juxtapose ? 345 // Concatenation 346 347 void append(string_res &str1, const char * buffer, size_t bsize) { 348 size_t clnth = size(str1) + bsize; 349 if ( str1.Handle.s + size(str1) == buffer ) { // already juxtapose ? 350 // no-op 348 351 } else { // must copy some text 349 352 if ( str1.Handle.s + size(str1) == VbyteAlloc(HeapArea, 0) ) { // str1 at end of string area ? 350 VbyteAlloc(HeapArea, end - start); // create room for 2nd part at the end of string area353 VbyteAlloc(HeapArea, bsize); // create room for 2nd part at the end of string area 351 354 } else { // copy the two parts 352 355 char * str1oldBuf = str1.Handle.s; … … 354 357 ByteCopy( HeapArea, str1.Handle.s, 0, str1.Handle.lnth, str1oldBuf, 0, str1.Handle.lnth); 355 358 } // if 356 ByteCopy( HeapArea, str1.Handle.s, str1.Handle.lnth, str_src.Handle.lnth, str_src.Handle.s, start, end);359 ByteCopy( HeapArea, str1.Handle.s, str1.Handle.lnth, bsize, (char*)buffer, 0, (int)bsize); 357 360 // VbyteHeap & this, char *Dst, int DstStart, int DstLnth, char *Src, int SrcStart, int SrcLnth 358 361 } // if … … 360 363 } 361 364 362 363 364 ///////////////////////////////////////////////////////////////////365 // Concatenation366 367 365 void ?+=?(string_res &str1, const string_res &str2) { 368 append( str1, str2 , 0, size(str2));366 append( str1, str2.Handle.s, str2.Handle.lnth ); 369 367 } 370 368 371 369 void ?+=?(string_res &s, char other) { 372 string_res other_s = { &other, 1 }; 373 s += other_s; 370 append( s, &other, 1 ); 374 371 } 375 372 376 373 void ?+=?(string_res &s, const char* other) { 377 string_res other_s = other; 378 s += other_s; 374 append( s, other, strlen(other) ); 379 375 } 380 376 -
libcfa/src/containers/string_res.hfa
rf26923e rd8d512e 82 82 } 83 83 84 void ?=?(string_res &s, const char* other); // copy assignment from literal 84 void assign(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer 85 void ?=?(string_res &s, const char* other); // copy from string literal (NULL-terminated) 85 86 void ?=?(string_res &s, const string_res &other); 86 87 void ?=?(string_res &s, string_res &other); 87 void ?=?(string_res &s, char other); // Str tolerates memcpys; still saw calls to autogen88 void ?=?(string_res &s, char other); 88 89 89 90 void ^?{}(string_res &s); … … 96 97 void ?+=?(string_res &s, char other); // append a character 97 98 void ?+=?(string_res &s, const string_res &s2); // append-concatenate to first string 98 void ?+=?(string_res &s, const char* other); // append-concatenate to first string 99 void ?+=?(string_res &s, const char* other); 100 void append(string_res &s, const char* buffer, size_t bsize); 99 101 100 102 // Character access
Note: See TracChangeset
for help on using the changeset viewer.