UCollationResult IntlTestCollator::compareUsingPartials(UCollator *coll, const UChar source[], int32_t sLen, const UChar target[], int32_t tLen, int32_t pieceSize, UErrorCode &status) { int32_t partialSKResult = 0; uint8_t sBuf[512], tBuf[512]; UCharIterator sIter, tIter; uint32_t sState[2], tState[2]; int32_t sSize = pieceSize, tSize = pieceSize; int32_t i = 0; status = U_ZERO_ERROR; sState[0] = 0; sState[1] = 0; tState[0] = 0; tState[1] = 0; while(sSize == pieceSize && tSize == pieceSize && partialSKResult == 0) { uiter_setString(&sIter, source, sLen); uiter_setString(&tIter, target, tLen); sSize = ucol_nextSortKeyPart(coll, &sIter, sState, sBuf, pieceSize, &status); tSize = ucol_nextSortKeyPart(coll, &tIter, tState, tBuf, pieceSize, &status); if(sState[0] != 0 || tState[0] != 0) { log("State != 0 : %08X %08X\n", sState[0], tState[0]); } log("%i ", i++); partialSKResult = memcmp(sBuf, tBuf, pieceSize); } if(partialSKResult < 0) { return UCOL_LESS; } else if(partialSKResult > 0) { return UCOL_GREATER; } else { return UCOL_EQUAL; } }
static UCollationResult compareUsingPartials(UCollator *coll, const UChar source[], int32_t sLen, const UChar target[], int32_t tLen, int32_t pieceSize, UErrorCode *status) { int32_t partialSKResult = 0; UCharIterator sIter, tIter; uint32_t sState[2], tState[2]; int32_t sSize = pieceSize, tSize = pieceSize; /*int32_t i = 0;*/ uint8_t sBuf[16384], tBuf[16384]; if(pieceSize > 16384) { log_err("Partial sortkey size buffer too small. Please consider increasing the buffer!\n"); *status = U_BUFFER_OVERFLOW_ERROR; return UCOL_EQUAL; } *status = U_ZERO_ERROR; sState[0] = 0; sState[1] = 0; tState[0] = 0; tState[1] = 0; while(sSize == pieceSize && tSize == pieceSize && partialSKResult == 0) { uiter_setString(&sIter, source, sLen); uiter_setString(&tIter, target, tLen); sSize = ucol_nextSortKeyPart(coll, &sIter, sState, sBuf, pieceSize, status); tSize = ucol_nextSortKeyPart(coll, &tIter, tState, tBuf, pieceSize, status); if(sState[0] != 0 || tState[0] != 0) { /*log_verbose("State != 0 : %08X %08X\n", sState[0], tState[0]);*/ } /*log_verbose("%i ", i++);*/ partialSKResult = memcmp(sBuf, tBuf, pieceSize); } if(partialSKResult < 0) { return UCOL_LESS; } else if(partialSKResult > 0) { return UCOL_GREATER; } else { return UCOL_EQUAL; } }
// Ticket 7189 // // nextSortKeyPart incorrect for EO_S1 collation static int32_t calcKeyIncremental(UCollator *coll, const UChar* text, int32_t len, uint8_t *keyBuf, int32_t /*keyBufLen*/, UErrorCode& status) { UCharIterator uiter; uint32_t state[2] = { 0, 0 }; int32_t keyLen; int32_t count = 8; uiter_setString(&uiter, text, len); keyLen = 0; while (TRUE) { int32_t keyPartLen = ucol_nextSortKeyPart(coll, &uiter, state, &keyBuf[keyLen], count, &status); if (U_FAILURE(status)) { return -1; } if (keyPartLen == 0) { break; } keyLen += keyPartLen; } return keyLen; }