Changeset 9018dcf for libcfa/src/collections/string.cfa
- Timestamp:
- Apr 10, 2025, 7:33:31 AM (9 months ago)
- Branches:
- master
- Children:
- 7e4f226
- Parents:
- 931f1b4
- File:
-
- 1 edited
-
libcfa/src/collections/string.cfa (modified) (5 diffs)
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 }
Note:
See TracChangeset
for help on using the changeset viewer.