Changeset 9018dcf for libcfa/src
- Timestamp:
- Apr 10, 2025, 7:33:31 AM (6 months ago)
- Branches:
- master
- Children:
- 7e4f226
- Parents:
- 931f1b4
- Location:
- libcfa/src/collections
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r931f1b4 r9018dcf 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 5 15:18:30 202513 // Update Count : 3 1812 // Last Modified On : Wed Apr 9 22:27:40 2025 13 // Update Count : 368 14 14 // 15 15 … … 295 295 bool ?<? ( const char * s1, const string & s2 ) { return s1 < *s2.inner; } 296 296 297 298 ////////////////////////////////////////////////////////299 // Getter300 301 size_t len( const string & s ) {302 return len( *s.inner );303 }304 305 297 //////////////////////////////////////////////////////// 306 298 // Concatenation … … 424 416 } 425 417 426 int find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen ) {418 size_t find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen ) { 427 419 if ( start < 0 ) { start += len( s ); } 428 420 if ( len < 0 ) { len = -len; start -= len; } … … 434 426 if ( kstart >= len( key ) ) return 0; 435 427 if ( kstart + klen > len( key ) ) klen = len( key ) - kstart; 436 428 437 429 return findFrom( *s.inner, start, *key.inner ); 438 430 } 439 431 440 int find( const string & s, char key ) {432 size_t find( const string & s, char key ) { 441 433 return find( *s.inner, key ); 442 434 } 443 435 444 int find( const string & s, const string & key ) {436 size_t find( const string & s, const string & key ) { 445 437 return find( *s.inner, *key.inner ); 446 438 } 447 439 448 int find( const string & s, const char * key ) {440 size_t find( const string & s, const char * key ) { 449 441 return find( *s.inner, key ); 450 442 } 451 443 452 int find( const string & s, const char * key, size_t keysize ) {444 size_t find( const string & s, const char * key, size_t keysize ) { 453 445 return find( *s.inner, key, keysize ); 454 446 } 455 447 456 int find( const string & s, size_t start, char key ) {448 size_t find( const string & s, size_t start, char key ) { 457 449 return findFrom( *s.inner, start, key ); 458 450 } 459 451 460 int find( const string & s, size_t start, const char * key ) {452 size_t find( const string & s, size_t start, const char * key ) { 461 453 return findFrom( *s.inner, start, key ); 462 454 } 463 455 464 int find( const string & s, size_t start, const char * key, size_t keysize ) {456 size_t find( const string & s, size_t start, const char * key, size_t keysize ) { 465 457 return findFrom( *s.inner, start, key, keysize ); 466 458 } … … 527 519 } 528 520 529 530 int exclude( const string & s, const charclass & mask ) { 521 size_t exclude( const string & s, const charclass & mask ) { 531 522 return exclude( *s.inner, *mask.inner ); 532 523 } 533 /* 534 StrSlice exclude( string & s, const charclass & mask ) { 535 } 536 */ 537 538 int include( const string & s, const charclass & mask ) { 524 525 size_t include( const string & s, const charclass & mask ) { 539 526 return include( *s.inner, *mask.inner ); 540 527 } 541 528 542 /* 543 StrSlice include( string & s, const charclass & mask ) { 544 } 545 */ 529 size_t test( const string & s, int (*f)( int ) ) { 530 size_t l = len( s ); 531 for ( i; l ) { 532 if ( ! f( s[i] ) ) return i; 533 } // for 534 return l; 535 } 536 537 string replace( string & s, const string & from, const string & to ) { 538 ssize_t pos; 539 string r; 540 541 pos = find( s, from ); 542 if ( pos < len( s ) ) { 543 r = s( 0, pos ) + to + replace( s( pos + (ssize_t)len( from ) ), from, to ); 544 string front = s( 0, pos ); 545 string back = s( pos + (ssize_t)len( from ) ); 546 r = front + to + replace( back, from, to ); 547 } else { 548 r = s; 549 } // if 550 return r; 551 } 552 553 string translate( const string & s, int (*f)( int ) ) { 554 string r = s; 555 size_t l = len( r ); 556 for ( i; l ) { 557 r[i] = (char)f( r[i] ); 558 } // for 559 return r; 560 } -
libcfa/src/collections/string.hfa
r931f1b4 r9018dcf 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 5 15:16:23202513 // Update Count : 18012 // Last Modified On : Wed Apr 9 22:27:41 2025 13 // Update Count : 259 14 14 // 15 15 … … 17 17 18 18 #include <fstream.hfa> 19 20 21 // in string_res.hfa 22 struct string_res; 23 struct charclass_res; 19 #include <string_res.hfa> 24 20 25 21 struct string { … … 28 24 29 25 // Getters 26 static inline size_t len( const string & s ) { return len( *s.inner ); } 30 27 static inline size_t len( const char * cs ) { return strlen( cs ); }; 31 size_t len( const string & s );32 28 static inline size_t strlen( const string & s ) { return len( s ); } 33 29 … … 215 211 bool contains( const string & s, char ch ); // single character 216 212 217 int find( const string & s, char key ); 218 static inline int ?^? ( const string & s, char key ) { return find( s, key ); } 219 int find( const string & s, const char * key ); 220 static inline int ?^? ( const string & s, const char * key ) { return find( s, key ); } 221 int find( const string & s, const string & key ); 222 static inline int ?^? ( const string & s, const string & key ) { return find( s, key ); } 223 int find( const string & s, const char * key, size_t keysize ); 224 225 int find( const string & s, size_t start, char key ); 226 int find( const string & s, size_t start, const string & key ); 227 int find( const string & s, size_t start, const char * key ); 228 int find( const string & s, size_t start, const char * key, size_t keysize ); 213 //int find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen ); 214 size_t find$( const string_res & s, size_t start, size_t len, const string & key_res, size_t kstart, size_t klen ); 215 216 size_t find( const string & s, char key ); 217 size_t find( const string & s, const char * key ); 218 size_t find( const string & s, const string & key ); 219 size_t find( const string & s, const char * key, size_t keysize ); 220 221 size_t find( const string & s, size_t start, char key ); 222 size_t find( const string & s, size_t start, const string & key ); 223 size_t find( const string & s, size_t start, const char * key ); 224 size_t find( const string & s, size_t start, const char * key, size_t keysize ); 225 static inline ?^?( const string & key, const string & s ) { return find( s, key ); } 226 static inline ?^?( const char * key, const string & s ) { return find( s, key ); } 229 227 230 228 bool includes( const string & s, const string & mask ); … … 241 239 242 240 // Slicing 243 string ?()( string & s, ssize_t start, ssize_t len ); // TODO const? 241 string ?()( string & s, ssize_t start, ssize_t len ); 242 static inline string ?()( const string & s, ssize_t start, ssize_t len ) { string & w = (string &)s; return w( start, len ); } // FIX ME 244 243 string ?()( string & s, ssize_t start ); 244 static inline string ?()( const string & s, ssize_t start ) { string & w = (string &)s; return w( start ); } // FIX ME 245 245 static inline string ?()( string & s, char m ) { return s( find( s, m ), 1 )`share; } 246 static inline string ?()( const string & s, char m ) { string & w = (string &)s; return w( find( s, m ), 1 )`share; } // FIX ME 246 247 static inline string ?()( string & s, const char * m ) { return s( find( s, m ), len( m ) )`share; } 248 static inline string ?()( const string & s, const char * m ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME 247 249 static inline string ?()( string & s, const string & m ) { return s( find( s, m ), len( m ) )`share; } 248 249 // Modifiers 250 void padStart( string & s, size_t n ); 251 void padStart( string & s, size_t n, char padding ); 252 void padEnd( string & s, size_t n ); 253 void padEnd( string & s, size_t n, char padding ); 254 250 static inline string ?()( const string & s, const string & m ) { string & w = (string &)s; return w( find( s, m ), len( m ) )`share; } // FIX ME 255 251 256 252 struct charclass { … … 267 263 void ^?{}( charclass & ); 268 264 269 int include( const string & s, const charclass & mask ); 270 271 int exclude( const string & s, const charclass & mask ); 272 273 /* 274 What to do with? 275 StrRet include( string & s, const charclass & mask ); 276 StrRet exclude( string & s, const charclass & mask ); 277 */ 265 size_t include( const string & s, const charclass & mask ); 266 static inline size_t include( const char * s, const charclass & mask ) { string temp = s; return include( temp, mask ); } 267 static inline string include( const string & s, const charclass & mask ) { ssize_t i = include( s, mask ); return s( 0, i )`share; } 268 static inline string include( const char * s, const charclass & mask ) { string temp = s; ssize_t i = include( temp, mask ); return temp( 0, i ); } 269 270 size_t exclude( const string & s, const charclass & mask ); 271 static inline size_t exclude( const char * s, const charclass & mask ) { string temp = s; return exclude( temp, mask ); } 272 static inline string exclude( const string & s, const charclass & mask ) { ssize_t i = exclude( s, mask ); return s( 0, i )`share; } 273 static inline string exclude( const char * s, const charclass & mask ) { string temp = s; ssize_t i = exclude( temp, mask ); return temp( 0, i ); } 274 275 size_t test( const string & s, int (*f)( int ) ); 276 static inline size_t test( const char * c, int (*f)( int ) ) { 277 const string S = c; 278 return test( S, f ); 279 } 280 281 string replace( string & s, const string & from, const string & to ); 282 static inline string replace( const char * s, const char * from, const char * to ) { 283 string S = s, From = from, To = to; 284 return replace( S, From, To ); 285 } 286 static inline string replace( string & s, const char * from, const char * to ) { 287 string From = from, To = to; 288 return replace( s, From, To ); 289 } 290 static inline string replace( string & s, const char * from, const string & to ) { 291 string From = from; 292 return replace( s, From, to ); 293 } 294 static inline string replace( string & s, string & from, const char * to ) { 295 string To = to; 296 return replace( s, from, To ); 297 } 298 299 string translate( const string & s, int (*f)( int ) ); 300 static inline string translate( const char * c, int (*f)( int ) ) { 301 const string S = c; 302 return translate( S, f ); 303 } -
libcfa/src/collections/string_res.cfa
r931f1b4 r9018dcf 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Apr 6 07:38:02202513 // Update Count : 1 1112 // Last Modified On : Wed Apr 9 08:44:17 2025 13 // Update Count : 128 14 14 // 15 15 … … 190 190 const char * DEBUG_string_heap_start( VbyteHeap * heap ) { 191 191 return heap->StartVbyte; 192 }193 194 // Returns the size of the string in bytes195 size_t len(const string_res & s) with(s) {196 return Handle.lnth;197 192 } 198 193 … … 756 751 } 757 752 758 int find(const string_res & s, char search) { 753 // int find$( const string_res & s, ssize_t start, ssize_t len, const string_res & k, ssize_t kstart, ssize_t klen ) { 754 // if ( start < 0 ) start = s.Handle.lnth + start; // adjust negative starting locations 755 // if ( kstart < 0 ) kstart = k.Handle.lnth + kstart; 756 757 // if ( start + len > s.Handle.lnth ) return start + 1; // cannot be there 758 // if ( kstart + len > k.Handle.lnth ) return start + 1; 759 // if ( klen > len ) return start + 1; 760 761 // int i, r; 762 763 // for ( i = max( start, 1 ); ; i += 1 ) { 764 // if ( i > s.Handle.lnth - k.Handle.lnth + 1 ) { 765 // r = s.Handle.lnth + 1; 766 // break; 767 // } // exit 768 // if ( HeapArea->ByteCmp( s.Handle.s, i, k.Handle.lnth, k.Handle.s, 1, k.Handle.lnth ) == 0 ) { 769 // r = i; 770 // break; 771 // } // exit 772 // } // for 773 // return r; 774 // } 775 776 int find( const string_res & s, char search ) { 759 777 return findFrom(s, 0, search); 760 778 } 761 779 762 int findFrom( const string_res & s, size_t fromPos, char search) {780 int findFrom( const string_res & s, size_t fromPos, char search ) { 763 781 // FIXME: This paricular overload (find of single char) is optimized to use memchr. 764 782 // The general overload (find of string, memchr applying to its first character) and `contains` should be adjusted to match. -
libcfa/src/collections/string_res.hfa
r931f1b4 r9018dcf 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Apr 6 07:35:44202513 // Update Count : 7 012 // Last Modified On : Wed Apr 9 15:16:29 2025 13 // Update Count : 76 14 14 // 15 15 … … 70 70 71 71 // Getters 72 s ize_t len( const string_res & s);72 static inline size_t len( const string_res & s ) { return s.Handle.lnth; } 73 73 74 74 // Constructors, Assignment Operators, Destructor … … 220 220 bool contains( const string_res & s, char ch); // single character 221 221 222 int find$( const string_res & s, ssize_t start, ssize_t len, const string_res & key, ssize_t kstart, ssize_t klen ); 223 222 224 int find( const string_res & s, char search); 223 225 int find( const string_res & s, const string_res & search); … … 245 247 int exclude( const string_res & s, const charclass_res & mask); 246 248 247 // Modifiers248 void padStart(string_res & s, size_t n);249 void padStart(string_res & s, size_t n, char padding);250 void padEnd(string_res & s, size_t n);251 void padEnd(string_res &s, size_t n, char padding);252
Note:
See TracChangeset
for help on using the changeset viewer.