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. :");
| 706 | * Output will be just "HelloWorld". |
| 707 | */ |
| 708 | sds sdstrim(sds s, const char *cset) { |
| 709 | char *start, *end, *sp, *ep; |
| 710 | size_t len; |
| 711 | |
| 712 | sp = start = s; |
| 713 | ep = end = s+sdslen(s)-1; |
| 714 | while(sp <= end && strchr(cset, *sp)) sp++; |
| 715 | while(ep > sp && strchr(cset, *ep)) ep--; |
| 716 | len = (sp > ep) ? 0 : ((ep-sp)+1); |
| 717 | if (s != sp) memmove(s, sp, len); |
| 718 | s[len] = '\0'; |
| 719 | sdssetlen(s,len); |
| 720 | return s; |
| 721 | } |
| 722 | |
| 723 | /* Turn the string into a smaller (or equal) string containing only the |
| 724 | * substring specified by the 'start' and 'end' indexes. |
no test coverage detected