MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sdstrim

Function sdstrim

app/redis-6.2.6/src/sds.c:747–760  ·  view source on GitHub ↗

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. :");

Source from the content-addressed store, hash-verified

745 * Output will be just "HelloWorld".
746 */
747sds 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

Callers 9

rewriteConfigReadOldFileFunction · 0.85
pfdebugCommandFunction · 0.85
expandProcTitleTemplateFunction · 0.85
addReplyErrorFormatFunction · 0.85
ACLLoadFromFileFunction · 0.85
getAbsolutePathFunction · 0.85
sdsTestFunction · 0.85

Calls 4

sdslenFunction · 0.85
strchrFunction · 0.85
sdssetlenFunction · 0.85
memmoveFunction · 0.50

Tested by

no test coverage detected