src/string.c

changeset 1426
3a89b31f0724
parent 1415
40074e643663
equal deleted inserted replaced
1425:83284b289430 1426:3a89b31f0724
459 ) { 459 ) {
460 return cx_strsplit_a(allocator, cx_strcast(string), 460 return cx_strsplit_a(allocator, cx_strcast(string),
461 delim, limit, (cxstring **) output); 461 delim, limit, (cxstring **) output);
462 } 462 }
463 463
464 int cx_strcmp( 464 int cx_strcmp_(
465 cxstring s1, 465 cxstring s1,
466 cxstring s2 466 cxstring s2
467 ) { 467 ) {
468 if (s1.length == s2.length) { 468 if (s1.length == s2.length) {
469 return strncmp(s1.ptr, s2.ptr, s1.length); 469 return strncmp(s1.ptr, s2.ptr, s1.length);
476 if (r != 0) return r; 476 if (r != 0) return r;
477 return -1; 477 return -1;
478 } 478 }
479 } 479 }
480 480
481 int cx_strcasecmp( 481 int cx_strcasecmp_(
482 cxstring s1, 482 cxstring s1,
483 cxstring s2 483 cxstring s2
484 ) { 484 ) {
485 if (s1.length == s2.length) { 485 if (s1.length == s2.length) {
486 return cx_strcasecmp_impl(s1.ptr, s2.ptr, s1.length); 486 return cx_strcasecmp_impl(s1.ptr, s2.ptr, s1.length);
545 cxmutstr cx_strtrim_m(cxmutstr string) { 545 cxmutstr cx_strtrim_m(cxmutstr string) {
546 cxstring result = cx_strtrim(cx_strcast(string)); 546 cxstring result = cx_strtrim(cx_strcast(string));
547 return (cxmutstr) {(char *) result.ptr, result.length}; 547 return (cxmutstr) {(char *) result.ptr, result.length};
548 } 548 }
549 549
550 bool cx_strprefix( 550 bool cx_strprefix_(
551 cxstring string, 551 cxstring string,
552 cxstring prefix 552 cxstring prefix
553 ) { 553 ) {
554 if (string.length < prefix.length) return false; 554 if (string.length < prefix.length) return false;
555 return memcmp(string.ptr, prefix.ptr, prefix.length) == 0; 555 return memcmp(string.ptr, prefix.ptr, prefix.length) == 0;
556 } 556 }
557 557
558 bool cx_strsuffix( 558 bool cx_strsuffix_(
559 cxstring string, 559 cxstring string,
560 cxstring suffix 560 cxstring suffix
561 ) { 561 ) {
562 if (string.length < suffix.length) return false; 562 if (string.length < suffix.length) return false;
563 return memcmp(string.ptr + string.length - suffix.length, 563 return memcmp(string.ptr + string.length - suffix.length,
564 suffix.ptr, suffix.length) == 0; 564 suffix.ptr, suffix.length) == 0;
565 } 565 }
566 566
567 bool cx_strcaseprefix( 567 bool cx_strcaseprefix_(
568 cxstring string, 568 cxstring string,
569 cxstring prefix 569 cxstring prefix
570 ) { 570 ) {
571 if (string.length < prefix.length) return false; 571 if (string.length < prefix.length) return false;
572 #ifdef _WIN32 572 #ifdef _WIN32
574 #else 574 #else
575 return strncasecmp(string.ptr, prefix.ptr, prefix.length) == 0; 575 return strncasecmp(string.ptr, prefix.ptr, prefix.length) == 0;
576 #endif 576 #endif
577 } 577 }
578 578
579 bool cx_strcasesuffix( 579 bool cx_strcasesuffix_(
580 cxstring string, 580 cxstring string,
581 cxstring suffix 581 cxstring suffix
582 ) { 582 ) {
583 if (string.length < suffix.length) return false; 583 if (string.length < suffix.length) return false;
584 #ifdef _WIN32 584 #ifdef _WIN32

mercurial