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. */
| 790 | * additional characters, the longer string is considered to be greater than |
| 791 | * the smaller one. */ |
| 792 | int 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 |