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. */
| 832 | * additional characters, the longer string is considered to be greater than |
| 833 | * the smaller one. */ |
| 834 | int sdscmp(const sds s1, const sds s2) { |
| 835 | size_t l1, l2, minlen; |
| 836 | int cmp; |
| 837 | |
| 838 | l1 = sdslen(s1); |
| 839 | l2 = sdslen(s2); |
| 840 | minlen = (l1 < l2) ? l1 : l2; |
| 841 | cmp = memcmp(s1,s2,minlen); |
| 842 | if (cmp == 0) return l1>l2? 1: (l1<l2? -1: 0); |
| 843 | return cmp; |
| 844 | } |
| 845 | |
| 846 | /* Split 's' with separator in 'sep'. An array |
| 847 | * of sds strings is returned. *count will be set |
no test coverage detected