Remove the part of the string from left and from right composed just of * contiguous characters found in 'cset', that is a null terminted C string. * * After the call, the modified sds string is no longer valid and all the * references must be substituted with the new pointer returned by the call. * * Example: * * s = sdsnew("AA...AA.a.aa.aHelloWorld :::"); * s = sdstrim(s,"Aa. :");
| 745 | * Output will be just "HelloWorld". |
| 746 | */ |
| 747 | sds sdstrim(sds s, const char *cset) { |
| 748 | char *start, *end, *sp, *ep; |
| 749 | size_t len; |
| 750 | |
| 751 | sp = start = s; |
| 752 | ep = end = s+sdslen(s)-1; |
| 753 | while(sp <= end && strchr(cset, *sp)) sp++; |
| 754 | while(ep > sp && strchr(cset, *ep)) ep--; |
| 755 | len = (sp > ep) ? 0 : ((ep-sp)+1); |
| 756 | if (s != sp) memmove(s, sp, len); |
| 757 | s[len] = '\0'; |
| 758 | sdssetlen(s,len); |
| 759 | return s; |
| 760 | } |
| 761 | |
| 762 | /* Changes the input string to be a subset of the original. |
| 763 | * It does not release the free space in the string, so a call to |
no test coverage detected