UBool CollationKey::operator==(const CollationKey& source) const { return getLength() == source.getLength() && (this == &source || uprv_memcmp(getBytes(), source.getBytes(), getLength()) == 0); }
CollationKey::CollationKey(const CollationKey& other) : UObject(other), fFlagAndLength(other.getLength()), fHashCode(other.fHashCode) { if (other.isBogus()) { setToBogus(); return; } int32_t length = fFlagAndLength; if (length > getCapacity() && reallocate(length, 0) == NULL) { setToBogus(); return; } if (length > 0) { uprv_memcpy(getBytes(), other.getBytes(), length); } }
// Bitwise comparison for the collation keys. UCollationResult CollationKey::compareTo(const CollationKey& target, UErrorCode &status) const { if(U_SUCCESS(status)) { const uint8_t *src = getBytes(); const uint8_t *tgt = target.getBytes(); // are we comparing the same string if (src == tgt) return UCOL_EQUAL; UCollationResult result; // are we comparing different lengths? int32_t minLength = getLength(); int32_t targetLength = target.getLength(); if (minLength < targetLength) { result = UCOL_LESS; } else if (minLength == targetLength) { result = UCOL_EQUAL; } else { minLength = targetLength; result = UCOL_GREATER; } if (minLength > 0) { int diff = uprv_memcmp(src, tgt, minLength); if (diff > 0) { return UCOL_GREATER; } else if (diff < 0) { return UCOL_LESS; } } return result; } else { return UCOL_EQUAL; } }