/*
*******************************************************************************
-* Copyright (C) 1996-2014, International Business Machines
+* Copyright (C) 1996-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* collationcompare.cpp
UBool anyVariable = FALSE;
// Fetch CEs, compare primaries, store secondary & tertiary weights.
- U_ALIGN_CODE(16);
for(;;) {
// We fetch CEs until we get a non-ignorable primary or reach the end.
uint32_t leftPrimary;
if(leftPrimary != rightPrimary) {
// Return the primary difference, with script reordering.
- const uint8_t *reorderTable = settings.reorderTable;
- if (reorderTable != NULL) {
- leftPrimary = Collation::reorder(reorderTable, leftPrimary);
- rightPrimary = Collation::reorder(reorderTable, rightPrimary);
+ if(settings.hasReordering()) {
+ leftPrimary = settings.reorder(leftPrimary);
+ rightPrimary = settings.reorder(rightPrimary);
}
return (leftPrimary < rightPrimary) ? UCOL_LESS : UCOL_GREATER;
}
int32_t rightStart = 0;
for(;;) {
// Find the merge separator or the NO_CE terminator.
+ uint32_t p;
int32_t leftLimit = leftStart;
- uint32_t leftLower32;
- while((leftLower32 = (uint32_t)left.getCE(leftLimit)) >
- Collation::MERGE_SEPARATOR_LOWER32 ||
- leftLower32 == 0) {
+ while((p = (uint32_t)(left.getCE(leftLimit) >> 32)) >
+ Collation::MERGE_SEPARATOR_PRIMARY ||
+ p == 0) {
++leftLimit;
}
int32_t rightLimit = rightStart;
- uint32_t rightLower32;
- while((rightLower32 = (uint32_t)right.getCE(rightLimit)) >
- Collation::MERGE_SEPARATOR_LOWER32 ||
- rightLower32 == 0) {
+ while((p = (uint32_t)(right.getCE(rightLimit) >> 32)) >
+ Collation::MERGE_SEPARATOR_PRIMARY ||
+ p == 0) {
++rightLimit;
}
// Both strings have the same number of merge separators,
// or else there would have been a primary-level difference.
U_ASSERT(left.getCE(leftLimit) == right.getCE(rightLimit));
- if(left.getCE(leftLimit) == Collation::NO_CE) { break; }
+ if(p == Collation::NO_CE_PRIMARY) { break; }
// Skip both merge separators and continue.
leftStart = leftLimit + 1;
rightStart = rightLimit + 1;
if(leftTertiary != rightTertiary) {
if(CollationSettings::sortsTertiaryUpperCaseFirst(options)) {
- // Pass through NO_CE and MERGE_SEPARATOR
- // and keep real tertiary weights larger than the MERGE_SEPARATOR.
+ // Pass through NO_CE and keep real tertiary weights larger than that.
// Do not change the artificial uppercase weight of a tertiary CE (0.0.ut),
// to keep tertiary CEs well-formed.
// Their case+tertiary weights must be greater than those of
// primary and secondary CEs.
- if(leftTertiary > Collation::MERGE_SEPARATOR_WEIGHT16) {
+ if(leftTertiary > Collation::NO_CE_WEIGHT16) {
if(leftLower32 > 0xffff) {
leftTertiary ^= 0xc000;
} else {
leftTertiary += 0x4000;
}
}
- if(rightTertiary > Collation::MERGE_SEPARATOR_WEIGHT16) {
+ if(rightTertiary > Collation::NO_CE_WEIGHT16) {
if(rightLower32 > 0xffff) {
rightTertiary ^= 0xc000;
} else {
do {
int64_t ce = left.getCE(leftIndex++);
leftQuaternary = (uint32_t)ce & 0xffff;
- if(leftQuaternary == 0) {
- // Variable primary or completely ignorable.
+ if(leftQuaternary <= Collation::NO_CE_WEIGHT16) {
+ // Variable primary or completely ignorable or NO_CE.
leftQuaternary = (uint32_t)(ce >> 32);
- } else if(leftQuaternary <= Collation::MERGE_SEPARATOR_WEIGHT16) {
- // Leave NO_CE or MERGE_SEPARATOR as is.
} else {
// Regular CE, not tertiary ignorable.
// Preserve the quaternary weight in bits 7..6.
do {
int64_t ce = right.getCE(rightIndex++);
rightQuaternary = (uint32_t)ce & 0xffff;
- if(rightQuaternary == 0) {
- // Variable primary or completely ignorable.
+ if(rightQuaternary <= Collation::NO_CE_WEIGHT16) {
+ // Variable primary or completely ignorable or NO_CE.
rightQuaternary = (uint32_t)(ce >> 32);
- } else if(rightQuaternary <= Collation::MERGE_SEPARATOR_WEIGHT16) {
- // Leave NO_CE or MERGE_SEPARATOR as is.
} else {
// Regular CE, not tertiary ignorable.
// Preserve the quaternary weight in bits 7..6.
if(leftQuaternary != rightQuaternary) {
// Return the difference, with script reordering.
- const uint8_t *reorderTable = settings.reorderTable;
- if (reorderTable != NULL) {
- leftQuaternary = Collation::reorder(reorderTable, leftQuaternary);
- rightQuaternary = Collation::reorder(reorderTable, rightQuaternary);
+ if(settings.hasReordering()) {
+ leftQuaternary = settings.reorder(leftQuaternary);
+ rightQuaternary = settings.reorder(rightQuaternary);
}
return (leftQuaternary < rightQuaternary) ? UCOL_LESS : UCOL_GREATER;
}
- if(leftQuaternary == Collation::NO_CE_WEIGHT16) { break; }
+ if(leftQuaternary == Collation::NO_CE_PRIMARY) { break; }
}
return UCOL_EQUAL;
}