src/string.c

changeset 364
5577d6c27a33
parent 363
8175ba2b3bcb
child 378
952c2df7e7ac
equal deleted inserted replaced
363:8175ba2b3bcb 364:5577d6c27a33
596 return memcmp(string.ptr+string.length-suffix.length, 596 return memcmp(string.ptr+string.length-suffix.length,
597 suffix.ptr, suffix.length) == 0; 597 suffix.ptr, suffix.length) == 0;
598 } 598 }
599 } 599 }
600 600
601 int scstrcaseprefix(scstr_t string, scstr_t prefix) {
602 if (string.length == 0) {
603 return prefix.length == 0;
604 }
605 if (prefix.length == 0) {
606 return 1;
607 }
608
609 if (prefix.length > string.length) {
610 return 0;
611 } else {
612 scstr_t subs = scstrsubsl(string, 0, prefix.length);
613 return scstrcasecmp(subs, prefix) == 0;
614 }
615 }
616
617 int scstrcasesuffix(scstr_t string, scstr_t suffix) {
618 if (string.length == 0) {
619 return suffix.length == 0;
620 }
621 if (suffix.length == 0) {
622 return 1;
623 }
624
625 if (suffix.length > string.length) {
626 return 0;
627 } else {
628 scstr_t subs = scstrsubs(string, string.length-suffix.length);
629 return scstrcasecmp(subs, suffix) == 0;
630 }
631 }
632
601 sstr_t scstrlower(scstr_t string) { 633 sstr_t scstrlower(scstr_t string) {
602 sstr_t ret = sstrdup(string); 634 sstr_t ret = sstrdup(string);
603 for (size_t i = 0; i < ret.length ; i++) { 635 for (size_t i = 0; i < ret.length ; i++) {
604 ret.ptr[i] = tolower(ret.ptr[i]); 636 ret.ptr[i] = tolower(ret.ptr[i]);
605 } 637 }

mercurial