- File:
-
- 1 edited
-
libcfa/src/collections/string.cfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string.cfa
r9018dcf red5023d1 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 9 22:27:40 202513 // Update Count : 3 6812 // Last Modified On : Sat Apr 5 15:18:30 2025 13 // Update Count : 318 14 14 // 15 15 … … 295 295 bool ?<? ( const char * s1, const string & s2 ) { return s1 < *s2.inner; } 296 296 297 298 //////////////////////////////////////////////////////// 299 // Getter 300 301 size_t len( const string & s ) { 302 return len( *s.inner ); 303 } 304 297 305 //////////////////////////////////////////////////////// 298 306 // Concatenation … … 416 424 } 417 425 418 size_t find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen ) {426 int find( const string & s, size_t start, size_t len, const string & key, size_t kstart, size_t klen ) { 419 427 if ( start < 0 ) { start += len( s ); } 420 428 if ( len < 0 ) { len = -len; start -= len; } … … 426 434 if ( kstart >= len( key ) ) return 0; 427 435 if ( kstart + klen > len( key ) ) klen = len( key ) - kstart; 428 436 429 437 return findFrom( *s.inner, start, *key.inner ); 430 438 } 431 439 432 size_t find( const string & s, char key ) {440 int find( const string & s, char key ) { 433 441 return find( *s.inner, key ); 434 442 } 435 443 436 size_t find( const string & s, const string & key ) {444 int find( const string & s, const string & key ) { 437 445 return find( *s.inner, *key.inner ); 438 446 } 439 447 440 size_t find( const string & s, const char * key ) {448 int find( const string & s, const char * key ) { 441 449 return find( *s.inner, key ); 442 450 } 443 451 444 size_t find( const string & s, const char * key, size_t keysize ) {452 int find( const string & s, const char * key, size_t keysize ) { 445 453 return find( *s.inner, key, keysize ); 446 454 } 447 455 448 size_t find( const string & s, size_t start, char key ) {456 int find( const string & s, size_t start, char key ) { 449 457 return findFrom( *s.inner, start, key ); 450 458 } 451 459 452 size_t find( const string & s, size_t start, const char * key ) {460 int find( const string & s, size_t start, const char * key ) { 453 461 return findFrom( *s.inner, start, key ); 454 462 } 455 463 456 size_t find( const string & s, size_t start, const char * key, size_t keysize ) {464 int find( const string & s, size_t start, const char * key, size_t keysize ) { 457 465 return findFrom( *s.inner, start, key, keysize ); 458 466 } … … 519 527 } 520 528 521 size_t exclude( const string & s, const charclass & mask ) { 529 530 int exclude( const string & s, const charclass & mask ) { 522 531 return exclude( *s.inner, *mask.inner ); 523 532 } 524 525 size_t include( const string & s, const charclass & mask ) { 533 /* 534 StrSlice exclude( string & s, const charclass & mask ) { 535 } 536 */ 537 538 int include( const string & s, const charclass & mask ) { 526 539 return include( *s.inner, *mask.inner ); 527 540 } 528 541 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 } 542 /* 543 StrSlice include( string & s, const charclass & mask ) { 544 } 545 */
Note:
See TracChangeset
for help on using the changeset viewer.