* Compares two strings with an optional collation. */
| 1458 | * Compares two strings with an optional collation. |
| 1459 | */ |
| 1460 | int |
| 1461 | CompareStrings(const char *left, uint32_t leftLength, const char *right, uint32_t |
| 1462 | rightLength, const char *collationString) |
| 1463 | { |
| 1464 | uint32_t minLength = leftLength < rightLength ? leftLength : rightLength; |
| 1465 | if (minLength == 0) |
| 1466 | { |
| 1467 | return leftLength - rightLength; |
| 1468 | } |
| 1469 | |
| 1470 | /* simple collation also uses binary comparison */ |
| 1471 | if (!IsCollationValid(collationString) || |
| 1472 | IsSimpleCollation(collationString)) |
| 1473 | { |
| 1474 | int32_t cmp = memcmp(left, right, minLength); |
| 1475 | if (cmp != 0) |
| 1476 | { |
| 1477 | return cmp; |
| 1478 | } |
| 1479 | |
| 1480 | /* |
| 1481 | * memcmp only inspects the first minLength bytes; if those are equal, |
| 1482 | * the longer string sorts after the shorter one (e.g. "cafe" < "cafes"). |
| 1483 | */ |
| 1484 | return leftLength - rightLength; |
| 1485 | } |
| 1486 | |
| 1487 | /* |
| 1488 | * ucol_strcollUTF8 already takes the full strings into account and applies |
| 1489 | * the configured collation strength, so its result is final. Applying a |
| 1490 | * byte-length tiebreaker here would incorrectly report collation-equal |
| 1491 | * strings of different byte lengths (e.g. "cafe" vs "café" at strength 1) |
| 1492 | * as unequal. |
| 1493 | */ |
| 1494 | return StringCompareWithCollation(left, leftLength, right, rightLength, |
| 1495 | collationString); |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | /* |
no test coverage detected