MCPcopy Create free account
hub / github.com/antirez/botlib / sdscmp

Function sdscmp

sds.c:792–802  ·  view source on GitHub ↗

Compare two sds strings s1 and s2 with memcmp(). * * Return value: * * positive if s1 > s2. * negative if s1 < s2. * 0 if s1 and s2 are exactly the same binary string. * * If two strings share exactly the same prefix, but one of the two has * additional characters, the longer string is considered to be greater than * the smaller one. */

Source from the content-addressed store, hash-verified

790 * additional characters, the longer string is considered to be greater than
791 * the smaller one. */
792int sdscmp(const sds s1, const sds s2) {
793 size_t l1, l2, minlen;
794 int cmp;
795
796 l1 = sdslen(s1);
797 l2 = sdslen(s2);
798 minlen = (l1 < l2) ? l1 : l2;
799 cmp = memcmp(s1,s2,minlen);
800 if (cmp == 0) return l1>l2? 1: (l1<l2? -1: 0);
801 return cmp;
802}
803
804/* Split 's' with separator in 'sep'. An array
805 * of sds strings is returned. *count will be set

Callers 1

sdsTestFunction · 0.85

Calls 1

sdslenFunction · 0.85

Tested by

no test coverage detected