MCPcopy Index your code
hub / github.com/antirez/botlib / sdstrim

Function sdstrim

sds.c:708–721  ·  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

706 * Output will be just "HelloWorld".
707 */
708sds 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.

Callers 2

readApiKeyFromFileFunction · 0.85
sdsTestFunction · 0.85

Calls 2

sdslenFunction · 0.85
sdssetlenFunction · 0.85

Tested by

no test coverage detected