- if (I < J)
- return strncasecmp(A, B, I) < 0 ? -1 : 1;
- return strncasecmp(A, B, J) <= 0 ? -1 : 1;
+
+ if (a == '\0') // A is a prefix of B.
+ return 1;
+ if (b == '\0') // B is a prefix of A.
+ return -1;
+
+ // Otherwise lexicographic.
+ return (a < b) ? -1 : 1;