1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-11-23 01:30:04 +00:00
|
|
|
* Copyright (C) 1996-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2000-12-12 01:15:30 +00:00
|
|
|
#include "ucolimp.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/coll.h"
|
|
|
|
#include "unicode/tblcoll.h"
|
|
|
|
#include "unicode/coleitr.h"
|
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/normlzr.h"
|
2001-01-04 00:45:41 +00:00
|
|
|
#include "unicode/unorm.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cpputils.h"
|
2000-12-07 07:22:55 +00:00
|
|
|
#include "cstring.h"
|
2000-12-06 00:53:48 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "ucmp32.h"
|
|
|
|
#include "tcoldata.h"
|
|
|
|
#include "tables.h"
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-01-04 00:45:41 +00:00
|
|
|
#include "unicode/udata.h"
|
|
|
|
#include "umutex.h"
|
|
|
|
|
|
|
|
static UCollatorNew* UCA = NULL;
|
|
|
|
static CompactIntArray* UCAmapping = NULL;
|
|
|
|
|
|
|
|
static UBool
|
|
|
|
isAcceptable(void *context,
|
|
|
|
const char *type, const char *name,
|
|
|
|
const UDataInfo *pInfo){
|
|
|
|
|
|
|
|
if( pInfo->size>=20 &&
|
|
|
|
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
pInfo->charsetFamily==U_CHARSET_FAMILY &&
|
|
|
|
pInfo->dataFormat[0]==0x55 && /* dataFormat="UCol" */
|
|
|
|
pInfo->dataFormat[1]==0x43 &&
|
|
|
|
pInfo->dataFormat[2]==0x6f &&
|
|
|
|
pInfo->dataFormat[3]==0x6c &&
|
|
|
|
pInfo->formatVersion[0]==1 &&
|
2001-01-05 00:47:25 +00:00
|
|
|
pInfo->dataVersion[0]==3 &&
|
|
|
|
pInfo->dataVersion[1]==0 &&
|
|
|
|
pInfo->dataVersion[2]==0 &&
|
|
|
|
pInfo->dataVersion[3]==0) {
|
2001-01-04 00:45:41 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
UCollatorNew* ucol_initCollator(const UCATableHeader *image, UCollatorNew *fillIn, UErrorCode *status) {
|
|
|
|
UCollatorNew *result = fillIn;
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result == NULL) {
|
|
|
|
result = (UCollatorNew *)uprv_malloc(sizeof(UCollatorNew));
|
|
|
|
if(result == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result->freeOnClose = TRUE;
|
|
|
|
} else {
|
|
|
|
result->freeOnClose = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result->image = image;
|
|
|
|
const uint8_t *mapping = (uint8_t*)result->image+result->image->mappingPosition;
|
|
|
|
CompactIntArray *newUCAmapping = ucmp32_openFromData(&mapping, status);
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
result->mapping = newUCAmapping;
|
|
|
|
} else {
|
|
|
|
if(result->freeOnClose == TRUE) {
|
|
|
|
uprv_free(result);
|
|
|
|
result = NULL;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result->latinOneMapping = (uint32_t*)((uint8_t*)result->image+result->image->latinOneMapping);
|
|
|
|
result->contractionCEs = (uint32_t*)((uint8_t*)result->image+result->image->contractionCEs);
|
|
|
|
result->contractionIndex = (UChar*)((uint8_t*)result->image+result->image->contractionIndex);
|
|
|
|
result->expansion = (uint32_t*)((uint8_t*)result->image+result->image->expansion);
|
|
|
|
/* set attributes */
|
2001-01-09 00:52:18 +00:00
|
|
|
result->caseFirst = result->image->caseFirst;
|
|
|
|
result->caseLevel = result->image->caseLevel;
|
|
|
|
result->frenchCollation = result->image->frenchCollation;
|
|
|
|
result->normalizationMode = result->image->normalizationMode;
|
|
|
|
result->strength = result->image->strength;
|
|
|
|
result->variableTopValue = result->image->variableTopValue;
|
|
|
|
|
|
|
|
result->caseFirstisDefault = TRUE;
|
|
|
|
result->caseLevelisDefault = TRUE;
|
|
|
|
result->frenchCollationisDefault = TRUE;
|
|
|
|
result->normalizationModeisDefault = TRUE;
|
|
|
|
result->strengthisDefault = TRUE;
|
|
|
|
result->variableTopValueisDefault = TRUE;
|
|
|
|
|
|
|
|
uint32_t variableMaxCE = ucmp32_get(result->mapping, result->variableTopValue);
|
|
|
|
result->variableMax = (variableMaxCE & 0xFF000000) >> 24;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ucol_initUCA(UErrorCode *status) {
|
|
|
|
if(U_FAILURE(*status)) return;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
|
|
|
if(UCA == NULL) {
|
|
|
|
UCollatorNew *newUCA = (UCollatorNew *)uprv_malloc(sizeof(UCollatorNew));
|
|
|
|
UDataMemory *result = udata_openChoice(NULL, UCA_DATA_TYPE, UCA_DATA_NAME, isAcceptable, NULL, status);
|
2001-01-05 00:47:25 +00:00
|
|
|
newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), newUCA, status);
|
|
|
|
newUCA->rb = NULL;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
2001-01-04 00:45:41 +00:00
|
|
|
udata_close(result);
|
|
|
|
uprv_free(newUCA);
|
|
|
|
}
|
|
|
|
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if(UCA == NULL) {
|
|
|
|
UCA = newUCA;
|
|
|
|
newUCA = NULL;
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
|
|
|
|
if(newUCA != NULL) {
|
|
|
|
udata_close(result);
|
|
|
|
uprv_free(newUCA);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
|
|
|
|
U_CAPI UCollatorNew*
|
|
|
|
ucol_openNew( const char *loc,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
/* New version */
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
ucol_initUCA(status);
|
|
|
|
|
|
|
|
UCollatorNew *result = NULL;
|
|
|
|
UResourceBundle *b = ures_open(NULL, loc, status);
|
2001-01-08 06:51:18 +00:00
|
|
|
UResourceBundle *binary = ures_getByKey(b, "%%CollationNew", NULL, status);
|
2001-01-05 00:47:25 +00:00
|
|
|
|
|
|
|
if(*status = U_MISSING_RESOURCE_ERROR) { /* if we don't find tailoring, we'll fallback to UCA */
|
|
|
|
result = UCA;
|
|
|
|
*status = U_USING_DEFAULT_ERROR;
|
|
|
|
} else if(U_SUCCESS(*status)) { /* otherwise, we'll pick a collation data that exists */
|
|
|
|
int32_t len = 0;
|
|
|
|
const uint8_t *inData = ures_getBinary(binary, &len, status);
|
|
|
|
result = ucol_initCollator((const UCATableHeader *)inData, result, status);
|
|
|
|
result->rb = b;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
ures_close(binary);
|
|
|
|
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
U_CAPI void
|
|
|
|
ucol_closeNew(UCollatorNew *coll)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
/* Here, it would be advisable to close: */
|
|
|
|
/* - UData for UCA (unless we stuff it in the root resb */
|
|
|
|
/* Again, do we need additional housekeeping... HMMM! */
|
|
|
|
if(coll->rb != NULL) {
|
|
|
|
ures_close(coll->rb);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
if(coll->freeOnClose == TRUE) {
|
|
|
|
uprv_free(coll);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
uint32_t ucol_getNextCENew(const UCollatorNew *coll, collIterate *collationSource, UErrorCode *status) {
|
|
|
|
uint32_t order;
|
|
|
|
if (U_FAILURE(*status) || (collationSource->pos>=collationSource->len
|
|
|
|
&& collationSource->CEpos <= collationSource->toReturn)) { /* have we run out of string and CEs?? */
|
|
|
|
order = UCOL_NULLORDER; /* if so, we won't play any more */
|
|
|
|
} else if (collationSource->CEpos > collationSource->toReturn) { /* Are there any CEs from previous expansions? */
|
|
|
|
order = *(collationSource->toReturn++); /* if so, return them */
|
2001-01-10 00:52:06 +00:00
|
|
|
collationSource->pos--;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else { /* This is the real business now */
|
|
|
|
UChar ch = *collationSource->pos;
|
|
|
|
collationSource->CEpos = collationSource->toReturn = collationSource->CEs;
|
|
|
|
if(ch < 0xFF) { /* if it's Latin One, we'll try to fast track it */
|
|
|
|
order = coll->latinOneMapping[ch]; /* by looking in up in an array */
|
|
|
|
} else { /* otherwise, */
|
|
|
|
order = ucmp32_get(coll->mapping, ch); /* we'll go for slightly slower trie */
|
|
|
|
}
|
|
|
|
if(order >= UCOL_NOT_FOUND) { /* if a CE is special */
|
|
|
|
*(collationSource->CEpos) = order; /* prepare the buffer */
|
|
|
|
order = getSpecialCENew(coll, collationSource, status); /* and try to get the special CE */
|
|
|
|
if(order == UCOL_NOT_FOUND) { /* We couldn't find a good CE in the tailoring */
|
2001-01-10 00:52:06 +00:00
|
|
|
order = ucol_getNextUCA(ch, collationSource, status);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
collationSource->pos++; /* we're advancing to the next codepoint */
|
|
|
|
/* This means that contraction should spit back the last codepoint eaten! */
|
|
|
|
return order; /* return the CE */
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
uint32_t ucol_getNextUCA(UChar ch, collIterate *collationSource, UErrorCode *status) {
|
|
|
|
uint32_t order;
|
|
|
|
if(ch < 0xFF) { /* so we'll try to find it in the UCA */
|
|
|
|
order = UCA->latinOneMapping[ch];
|
|
|
|
} else {
|
|
|
|
order = ucmp32_get(UCA->mapping, ch);
|
|
|
|
}
|
|
|
|
if(order >= UCOL_NOT_FOUND) { /* UCA also gives us a special CE */
|
|
|
|
order = getSpecialCENew(UCA, collationSource, status);
|
|
|
|
}
|
|
|
|
if(order == UCOL_NOT_FOUND) { /* This is where we have to resort to algorithmical generation */
|
2001-01-11 22:03:38 +00:00
|
|
|
/* We have to check if ch is possibly a first surrogate - then we need to take the next code unit */
|
|
|
|
/* and make a bigger CE */
|
|
|
|
UChar nextChar;
|
|
|
|
if(UTF_IS_FIRST_SURROGATE(ch) && (collationSource->pos<collationSource->len) &&
|
|
|
|
UTF_IS_SECOND_SURROGATE((nextChar=*(collationSource->pos+1)))) {
|
|
|
|
uint32_t cp = (((ch)<<10UL)+(nextChar)-((0xd800<<10UL)+0xdc00));
|
|
|
|
collationSource->pos++;
|
|
|
|
/* This is a code point minus 0x10000, that's what algorithm requires */
|
|
|
|
order = 0xE0800303 | (cp & 0xF0000) << 8 | (cp & 0xFE00) << 7;
|
|
|
|
*(collationSource->CEpos++) = 0xF0040000 | (cp & 0x1FF) << 19;
|
|
|
|
} else {
|
|
|
|
/* otherwise */
|
|
|
|
/* Make up an artifical CE from code point as per UCA */
|
|
|
|
order = 0xD08004F1;
|
|
|
|
/*order = 0xD01004F1;*/
|
|
|
|
order |= ((uint32_t)ch & 0xF000)<<12;
|
|
|
|
order |= ((uint32_t)ch & 0x0FFF)<<11;
|
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
}
|
|
|
|
return order; /* return the CE */
|
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
uint32_t getSpecialCENew(const UCollatorNew *coll, collIterate *source, UErrorCode *status) {
|
|
|
|
int32_t i = 0; /* general counter */
|
|
|
|
uint32_t CE = *source->CEpos;
|
|
|
|
while (true) {
|
|
|
|
const uint32_t *CEOffset = NULL;
|
|
|
|
const UChar *UCharOffset = NULL;
|
|
|
|
UChar schar, tchar;
|
|
|
|
uint32_t size = 0;
|
|
|
|
switch(getCETag(CE)) {
|
|
|
|
case NOT_FOUND_TAG:
|
|
|
|
/* This one is not found, and we'll let somebody else bother about it... no more games */
|
|
|
|
return CE;
|
|
|
|
break;
|
|
|
|
case SURROGATE_TAG:
|
2001-01-05 06:36:10 +00:00
|
|
|
/* pending surrogate discussion with Markus and Mark */
|
|
|
|
return UCOL_NOT_FOUND;
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
case THAI_TAG:
|
2001-01-05 06:36:10 +00:00
|
|
|
/* Thai/Lao reordering */
|
|
|
|
if(source->isThai == TRUE) { /* if we encountered Thai prevowel & the string is not yet touched */
|
|
|
|
source->isThai = FALSE; /* We will touch the string */
|
|
|
|
if((source->len - source->pos) > UCOL_WRITABLE_BUFFER_SIZE) {
|
|
|
|
/* Problematic part - if the stack buffer is too small, we need to allocate */
|
|
|
|
/* However, somebody needs to keep track of that allocated space */
|
|
|
|
/* And context structure is not good for that */
|
|
|
|
/* allocate a new buffer - This is unfortunate and should be way smarter */
|
|
|
|
/*source->writableBuffer = (UChar *)ucol_getABuffer(coll, (source->len - source->pos)*sizeof(UChar));*/
|
|
|
|
}
|
|
|
|
UChar *sourceCopy = source->pos;
|
|
|
|
UChar *targetCopy = source->writableBuffer;
|
|
|
|
while(sourceCopy < source->len) {
|
|
|
|
if(UCOL_ISTHAIPREVOWEL(*(sourceCopy)) && /* This is the combination that needs to be swapped */
|
|
|
|
UCOL_ISTHAIBASECONSONANT(*(sourceCopy+1))) {
|
|
|
|
*(targetCopy) = *(sourceCopy+1);
|
|
|
|
*(targetCopy+1) = *(sourceCopy);
|
|
|
|
targetCopy+=2;
|
|
|
|
sourceCopy+=2;
|
|
|
|
} else {
|
|
|
|
*(targetCopy++) = *(sourceCopy++);
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-05 06:36:10 +00:00
|
|
|
source->pos = source->writableBuffer;
|
|
|
|
source->len = targetCopy;
|
|
|
|
source->CEpos = source->toReturn = source->CEs;
|
|
|
|
CE = UCOL_IGNORABLE;
|
|
|
|
} else { /* we have already played with the string, so treat Thai as a length one expansion */
|
|
|
|
CEOffset = coll->expansion+getExpansionOffset(CE); /* find the offset to expansion table */
|
|
|
|
CE = *CEOffset++;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
case CONTRACTION_TAG:
|
|
|
|
/* This should handle contractions */
|
|
|
|
while(true) {
|
|
|
|
/* First we position ourselves at the begining of contraction sequence */
|
2001-01-09 00:52:18 +00:00
|
|
|
const UChar *ContractionStart = UCharOffset = (UChar *)coll->image+getContractOffset(CE);
|
2001-01-05 00:47:25 +00:00
|
|
|
|
|
|
|
/* we need to convey the notion of having a backward search - most probably through the context object */
|
2001-01-09 00:52:18 +00:00
|
|
|
/* if (backwardsSearch) offset += contractionUChars[(int16_t)offset]; else UCharOffset++; */
|
|
|
|
UCharOffset++; /* skip the backward offset, see above */
|
2001-01-05 00:47:25 +00:00
|
|
|
if (source->pos>=source->len) { /* this is the end of string */
|
|
|
|
CE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex)); /* So we'll pick whatever we have at the point... */
|
|
|
|
source->pos--; /* I think, since we'll advance in the getCE */
|
|
|
|
break;
|
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
schar = *(++source->pos);
|
2001-01-10 00:52:06 +00:00
|
|
|
while(schar > (tchar = *UCharOffset)) { /* since the contraction codepoints should be ordered, we skip all that are smaller */
|
|
|
|
UCharOffset++;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
if(schar != tchar) { /* we didn't find the correct codepoint. We can use either the first or the last CE */
|
2001-01-10 00:52:06 +00:00
|
|
|
if(tchar != 0xFFFF) {
|
2001-01-09 00:52:18 +00:00
|
|
|
UCharOffset = ContractionStart; /* We're not at the end, bailed out in the middle. Better use starting CE */
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
source->pos--; /* Spit out the last char of the string, wasn't tasty enough */
|
2001-01-10 00:52:06 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
CE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex));
|
2001-01-09 00:52:18 +00:00
|
|
|
if(!isContraction(CE)) {
|
|
|
|
/* Maybe not */
|
|
|
|
/*source->pos--;*/ /* I think, since we'll advance in the getCE */
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPANSION_TAG:
|
|
|
|
/* This should handle expansion. */
|
|
|
|
/* NOTE: we can encounter both continuations and expansions in an expansion! */
|
|
|
|
/* I have to decide where continuations are going to be dealt with */
|
2001-01-10 00:52:06 +00:00
|
|
|
CEOffset = (uint32_t *)coll->image+getExpansionOffset(CE); /* find the offset to expansion table */
|
2001-01-05 00:47:25 +00:00
|
|
|
size = getExpansionCount(CE);
|
|
|
|
CE = *CEOffset++;
|
|
|
|
if(size != 0) { /* if there are less than 16 elements in expansion, we don't terminate */
|
|
|
|
for(i = 1; i<size; i++) {
|
|
|
|
*(source->CEpos++) = *CEOffset++;
|
|
|
|
}
|
|
|
|
} else { /* else, we do */
|
|
|
|
while(*CEOffset != 0) {
|
|
|
|
*(source->CEpos++) = *CEOffset++;
|
|
|
|
}
|
|
|
|
}
|
2001-01-10 00:52:06 +00:00
|
|
|
/*source->toReturn++;*/
|
|
|
|
return CE;
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
case CHARSET_TAG:
|
2001-01-05 06:36:10 +00:00
|
|
|
/* probably after 1.8 */
|
|
|
|
return UCOL_NOT_FOUND;
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
2001-01-10 00:52:06 +00:00
|
|
|
CE=0;
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (CE <= UCOL_NOT_FOUND) break;
|
|
|
|
}
|
|
|
|
return CE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
uint8_t *reallocateBuffer(uint8_t **secondaries, uint8_t *secStart, uint8_t *second, int32_t *secSize, UErrorCode *status) {
|
|
|
|
uint8_t *newStart = NULL;
|
|
|
|
|
|
|
|
if(secStart==second) {
|
|
|
|
newStart=(uint8_t*)uprv_malloc(*secSize*2);
|
|
|
|
if(newStart==NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uprv_memcpy(newStart, secStart, *secondaries-secStart);
|
|
|
|
} else {
|
|
|
|
newStart=(uint8_t*)uprv_realloc(secStart, *secSize*2);
|
|
|
|
if(newStart==NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*secondaries=newStart+(*secondaries-secStart);
|
|
|
|
*secSize*=2;
|
|
|
|
return newStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void uprv_ucol_reverse_buffer(uint8_t *start, uint8_t *end) {
|
|
|
|
uint8_t temp;
|
|
|
|
while(start<end) {
|
|
|
|
temp = *start;
|
|
|
|
*start++ = *end;
|
|
|
|
*end-- = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MIN_VALUE 0x02
|
|
|
|
#define UNMARKED 0x03
|
|
|
|
#define UCOL_VARIABLE_MAX 0x20
|
|
|
|
#define UCOL_NEW_IGNORABLE 0
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t ucol_getSortKeySizeNew(const UCollatorNew *coll, collIterate *s, int32_t currentSize, UColAttributeValue strength, int32_t len) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-01-09 00:52:18 +00:00
|
|
|
uint8_t compareSec = (strength >= UCOL_SECONDARY)?0:0xFF;
|
|
|
|
uint8_t compareTer = (strength >= UCOL_TERTIARY)?0:0xFF;
|
|
|
|
uint8_t compareQuad = (strength >= UCOL_QUATERNARY)?0:0xFF;
|
2001-01-05 00:47:25 +00:00
|
|
|
UBool compareIdent = (strength == UCOL_IDENTICAL);
|
2001-01-09 00:52:18 +00:00
|
|
|
UBool doCase = (coll->caseLevel == UCOL_ON);
|
|
|
|
UBool shifted = (coll->alternateHandling == UCOL_SHIFTED);
|
|
|
|
|
|
|
|
uint8_t variableMax = coll->variableMax;
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t order = UCOL_NULLORDER;
|
|
|
|
uint16_t primary = 0;
|
2001-01-09 00:52:18 +00:00
|
|
|
uint8_t primary1 = 0;
|
|
|
|
uint8_t primary2 = 0;
|
|
|
|
uint8_t primary3 = 0;
|
|
|
|
uint32_t ce = 0;
|
2001-01-05 00:47:25 +00:00
|
|
|
uint8_t secondary = 0;
|
|
|
|
uint8_t tertiary = 0;
|
2001-01-09 00:52:18 +00:00
|
|
|
int32_t caseShift = 0;
|
2001-01-05 00:47:25 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
for(;;) {
|
2001-01-09 00:52:18 +00:00
|
|
|
/*order = ucol_getNextCENew(coll, s, status);*/
|
|
|
|
UCOL_GETNEXTCENEW(order, coll, *s, &status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(order == UCOL_NULLORDER) {
|
|
|
|
break;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
/* We're saving order in ce, since we will destroy order in order to get primary, secondary, tertiary in order ;)*/
|
|
|
|
ce = order;
|
|
|
|
|
|
|
|
|
|
|
|
tertiary = (order & UCOL_TERTIARYORDERMASK);
|
|
|
|
secondary = (order >>= 8) & 0xFF;
|
|
|
|
primary3 = 0; /* the third primary */
|
|
|
|
primary2 = (order >>= 8) & 0xFF;;
|
|
|
|
primary1 = order >>= 8;
|
|
|
|
|
|
|
|
if((tertiary & 0xF0) == 0xF0) { /* This indicates a long primary (11110000) */
|
|
|
|
/* Note: long primary can appear both as a normal CE or as a continuation CE (not that it matters much) */
|
|
|
|
primary3 = secondary;
|
|
|
|
secondary = (tertiary & 0x0F) + MIN_VALUE;
|
|
|
|
tertiary = UNMARKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(shifted && primary1 < variableMax && primary1 != 0) {
|
|
|
|
currentSize++;
|
|
|
|
if(primary2 != 0) {
|
|
|
|
currentSize++;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
} else {
|
|
|
|
/* Note: This code assumes that the table is well built i.e. not having 0 bytes where they are not supposed to be. */
|
|
|
|
/* Usually, we'll have non-zero primary1 & primary2, except in cases of LatinOne and friends, when primary2 will */
|
|
|
|
/* be zero with non zero primary1. primary3 is different than 0 only for long primaries - see above. */
|
|
|
|
if(primary1 != UCOL_NEW_IGNORABLE) {
|
|
|
|
currentSize++;
|
|
|
|
if(primary2 != UCOL_NEW_IGNORABLE) {
|
2001-01-05 00:47:25 +00:00
|
|
|
currentSize++;
|
2001-01-09 00:52:18 +00:00
|
|
|
if(primary3 != UCOL_NEW_IGNORABLE) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(secondary > compareSec) { /* I think that != 0 test should be != IGNORABLE */
|
|
|
|
/* This thing should also contain the compression logic, as in: */
|
|
|
|
/*
|
|
|
|
if (ws == COMMON2 && COMMON2 <= secondary[-1] && secondary[-1] < COMMON_MAX2)
|
|
|
|
++secondary[-1]; // simply increment!!
|
|
|
|
else *secondary++ = ws;
|
|
|
|
*/
|
|
|
|
|
|
|
|
currentSize++;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
if(doCase) {
|
|
|
|
if (caseShift == 0) {
|
2001-01-05 00:47:25 +00:00
|
|
|
currentSize++;
|
2001-01-09 00:52:18 +00:00
|
|
|
caseShift = 7;
|
|
|
|
}
|
|
|
|
caseShift--;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
if(tertiary > compareTer) { /* I think that != 0 test should be != IGNORABLE */
|
|
|
|
/* This thing should also contain the compression logic, as in: */
|
|
|
|
/*
|
|
|
|
if (ws == COMMON2 && COMMON2 <= secondary[-1] && secondary[-1] < COMMON_MAX2)
|
|
|
|
++secondary[-1]; // simply increment!!
|
|
|
|
else *secondary++ = ws;
|
|
|
|
*/
|
|
|
|
currentSize++;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
if(shifted && primary1 > compareQuad) {
|
|
|
|
currentSize++;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(compareIdent) {
|
|
|
|
currentSize += len*sizeof(UChar);
|
|
|
|
UChar *ident = s->string;
|
|
|
|
while(ident<s->len) {
|
|
|
|
if((*(ident) >> 8) + utf16fixup[*(ident) >> 11]<0x02) {
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
if((*(ident) & 0xFF)<0x02) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
return currentSize;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
ucol_calcSortKeyNew(const UCollatorNew *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t **result,
|
|
|
|
int32_t resultLength,
|
2001-01-05 06:36:10 +00:00
|
|
|
UBool allocatePrimary,
|
|
|
|
UErrorCode *status)
|
2001-01-05 00:47:25 +00:00
|
|
|
{
|
2001-01-05 06:36:10 +00:00
|
|
|
uint32_t i = 0; /* general purpose counter */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
/* Stack allocated buffers for buffers we use */
|
|
|
|
uint8_t second[UCOL_MAX_BUFFER], tert[UCOL_MAX_BUFFER], caseB[UCOL_MAX_BUFFER], quad[UCOL_MAX_BUFFER];
|
1999-10-22 00:43:39 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
uint8_t *primaries = *result, *secondaries = second, *tertiaries = tert, *cases = caseB, *quads = quad;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(primaries == NULL && allocatePrimary == TRUE) {
|
|
|
|
primaries = *result = (uint8_t *)uprv_malloc(2*UCOL_MAX_BUFFER);
|
|
|
|
resultLength = 2*UCOL_MAX_BUFFER;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
int32_t primSize = resultLength, secSize = UCOL_MAX_BUFFER, terSize = UCOL_MAX_BUFFER,
|
|
|
|
caseSize = UCOL_MAX_BUFFER, quadSize = UCOL_MAX_BUFFER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t sortKeySize = 1; // it is always \0 terminated
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
UChar normBuffer[UCOL_NORMALIZATION_GROWTH*UCOL_MAX_BUFFER];
|
|
|
|
UChar *normSource = normBuffer;
|
|
|
|
int32_t normSourceLen = UCOL_NORMALIZATION_GROWTH*UCOL_MAX_BUFFER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t len = (sourceLength == -1 ? u_strlen(source) : sourceLength);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
uint8_t variableMax = coll->variableMax;
|
2000-12-14 01:11:11 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
UColAttributeValue strength = coll->strength;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
uint8_t compareSec = (strength >= UCOL_SECONDARY)?0:0xFF;
|
|
|
|
uint8_t compareTer = (strength >= UCOL_TERTIARY)?0:0xFF;
|
|
|
|
uint8_t compareQuad = (strength >= UCOL_QUATERNARY)?0:0xFF;
|
2001-01-05 00:47:25 +00:00
|
|
|
UBool compareIdent = (strength == UCOL_IDENTICAL);
|
2001-01-09 00:52:18 +00:00
|
|
|
UBool doCase = (coll->caseLevel == UCOL_ON);
|
|
|
|
UBool upperFirst = (coll->caseFirst == UCOL_UPPER_FIRST);
|
|
|
|
UBool shifted = (coll->alternateHandling == UCOL_SHIFTED);
|
|
|
|
UBool isFrenchSec = (coll->frenchCollation == UCOL_ON);
|
2001-01-08 06:51:18 +00:00
|
|
|
|
|
|
|
/* support for special features like caselevel and funky secondaries */
|
|
|
|
uint8_t *frenchStartPtr = NULL;
|
|
|
|
uint8_t *frenchEndPtr = NULL;
|
|
|
|
uint32_t caseShift = 0;
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-01-11 22:03:38 +00:00
|
|
|
sortKeySize += ((compareSec?0:1) + (compareTer?0:1) + (doCase?1:0) + (compareQuad?0:1) + (compareIdent?1:0));
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
collIterate s;
|
|
|
|
init_collIterate((UChar *)source, len, &s, FALSE);
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
// If we need to normalize, we'll do it all at once at the beggining!
|
2001-01-09 00:52:18 +00:00
|
|
|
UColAttributeValue normMode = coll->normalizationMode;
|
2001-01-05 00:47:25 +00:00
|
|
|
if(normMode != UCOL_OFF) {
|
2001-01-05 06:36:10 +00:00
|
|
|
normSourceLen = u_normalize(source, sourceLength, UNORM_NFD, 0, normSource, normSourceLen, status);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
*status=U_ZERO_ERROR;
|
2001-01-05 00:47:25 +00:00
|
|
|
normSource = (UChar *) uprv_malloc((normSourceLen+1)*sizeof(UChar));
|
2001-01-05 06:36:10 +00:00
|
|
|
normSourceLen = u_normalize(source, sourceLength, UNORM_NFD, 0, normSource, (normSourceLen+1), status);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
normSource[normSourceLen] = 0;
|
|
|
|
s.string = normSource;
|
|
|
|
s.pos = normSource;
|
|
|
|
s.len = normSource+normSourceLen;
|
|
|
|
}
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
len = s.len-s.pos;
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(resultLength == 0) {
|
|
|
|
return ucol_getSortKeySizeNew(coll, &s, sortKeySize, strength, len);
|
2000-12-07 07:22:55 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
int32_t minBufferSize = UCOL_MAX_BUFFER;
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
uint8_t *primStart = primaries;
|
|
|
|
uint8_t *secStart = secondaries;
|
|
|
|
uint8_t *terStart = tertiaries;
|
2001-01-05 06:36:10 +00:00
|
|
|
uint8_t *caseStart = cases;
|
|
|
|
uint8_t *quadStart = quads;
|
2000-11-22 23:52:43 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
uint32_t order = 0;
|
2001-01-08 06:51:18 +00:00
|
|
|
uint32_t ce = 0;
|
2000-11-22 00:04:03 +00:00
|
|
|
|
2001-01-10 00:52:06 +00:00
|
|
|
uint8_t carry = 0;
|
2001-01-08 06:51:18 +00:00
|
|
|
uint8_t primary1 = 0;
|
|
|
|
uint8_t primary2 = 0;
|
|
|
|
uint8_t primary3 = 0;
|
2001-01-05 00:47:25 +00:00
|
|
|
uint8_t secondary = 0;
|
|
|
|
uint8_t tertiary = 0;
|
2000-11-22 00:04:03 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
UBool finished = FALSE;
|
|
|
|
UBool resultOverflow = FALSE;
|
2000-11-22 23:52:43 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t prevBuffSize = 0;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
for(;;) {
|
|
|
|
for(i=prevBuffSize; i<minBufferSize; ++i) {
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2001-01-10 00:52:06 +00:00
|
|
|
order = ucol_getNextCENew(coll, &s, status);
|
|
|
|
/*UCOL_GETNEXTCENEW(order, coll, s, status);*/
|
2000-11-29 00:16:15 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(order == UCOL_NULLORDER) {
|
|
|
|
finished = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-08 06:51:18 +00:00
|
|
|
/* We're saving order in ce, since we will destroy order in order to get primary, secondary, tertiary in order ;)*/
|
|
|
|
ce = order;
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
tertiary = (order & UCOL_TERTIARYORDERMASK);
|
2001-01-08 06:51:18 +00:00
|
|
|
secondary = (order >>= 8) & 0xFF;
|
2001-01-10 00:52:06 +00:00
|
|
|
if(!isContinuation(ce)) {
|
|
|
|
primary3 = 0; /* the third primary */
|
|
|
|
primary2 = (order >>= 8) & 0xFF;
|
|
|
|
primary1 = order >>= 8;
|
2001-01-11 22:03:38 +00:00
|
|
|
if(upperFirst && !isContinuation(ce)) {
|
2001-01-10 00:52:06 +00:00
|
|
|
/* Upper cases have this bit turned on, so that they always come after the lower cases */
|
|
|
|
/* if we want to reverse this situation, we'll flip this bit */
|
|
|
|
tertiary ^= 0x80;
|
|
|
|
}
|
2001-01-11 22:03:38 +00:00
|
|
|
|
2001-01-10 00:52:06 +00:00
|
|
|
} else {
|
|
|
|
primary3 = 0;
|
2001-01-11 22:03:38 +00:00
|
|
|
if(carry == 0) {
|
2001-01-10 00:52:06 +00:00
|
|
|
carry = (order >>= 8) & 0xF;
|
|
|
|
primary1 = (order >>= 4) & 0xFF;
|
|
|
|
} else {
|
|
|
|
primary2 = (order >>= 8) & 0xFF;
|
|
|
|
primary1 = ((order >>= 8) & 0xF) | carry<<4;
|
2001-01-11 22:03:38 +00:00
|
|
|
carry = 0;
|
2001-01-10 00:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-11 22:03:38 +00:00
|
|
|
|
2001-01-08 06:51:18 +00:00
|
|
|
if((tertiary & 0xF0) == 0xF0) { /* This indicates a long primary (11110000) */
|
|
|
|
/* Note: long primary can appear both as a normal CE or as a continuation CE (not that it matters much) */
|
|
|
|
primary3 = secondary;
|
|
|
|
secondary = (tertiary & 0x0F) + MIN_VALUE;
|
|
|
|
tertiary = UNMARKED;
|
|
|
|
}
|
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-08 06:51:18 +00:00
|
|
|
/* In the code below, every increase in any of buffers is followed by the increase to */
|
|
|
|
/* sortKeySize - this might look tedious, but it is needed so that we can find out if */
|
|
|
|
/* we're using too much space and need to reallocate the primary buffer or easily bail */
|
|
|
|
/* out to ucol_getSortKeySizeNew. */
|
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(shifted && primary1 < variableMax && primary1 != 0) {
|
2001-01-08 06:51:18 +00:00
|
|
|
/* We are dealing with a variable and we're treating them as shifted */
|
|
|
|
/* This is a shifted ignorable */
|
|
|
|
*quads++ = primary1;
|
|
|
|
sortKeySize++;
|
|
|
|
if(primary2 != 0) {
|
|
|
|
*quads++ = primary2;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Note: This code assumes that the table is well built i.e. not having 0 bytes where they are not supposed to be. */
|
|
|
|
/* Usually, we'll have non-zero primary1 & primary2, except in cases of LatinOne and friends, when primary2 will */
|
|
|
|
/* be zero with non zero primary1. primary3 is different than 0 only for long primaries - see above. */
|
2001-01-09 00:52:18 +00:00
|
|
|
if(primary1 != UCOL_NEW_IGNORABLE) {
|
2001-01-08 06:51:18 +00:00
|
|
|
*primaries++ = primary1; /* scriptOrder[primary1]; */ /* This is the script ordering thingie */
|
|
|
|
sortKeySize++;
|
2001-01-09 00:52:18 +00:00
|
|
|
if(primary2 != UCOL_NEW_IGNORABLE) {
|
|
|
|
*primaries++ = primary2; /* second part */
|
|
|
|
sortKeySize++;
|
|
|
|
if(primary3 != UCOL_NEW_IGNORABLE) {
|
2001-01-10 00:52:06 +00:00
|
|
|
*primaries++ = primary3; /* third part */
|
2001-01-09 00:52:18 +00:00
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(secondary > compareSec) { /* I think that != 0 test should be != IGNORABLE */
|
2001-01-08 06:51:18 +00:00
|
|
|
/* This thing should also contain the compression logic, as in: */
|
|
|
|
/*
|
|
|
|
if (ws == COMMON2 && COMMON2 <= secondary[-1] && secondary[-1] < COMMON_MAX2)
|
|
|
|
++secondary[-1]; // simply increment!!
|
|
|
|
else *secondary++ = ws;
|
|
|
|
*/
|
|
|
|
|
|
|
|
*secondaries++ = secondary;
|
|
|
|
sortKeySize++;
|
|
|
|
if(isFrenchSec) {
|
|
|
|
/* Do the special handling for French secondaries */
|
|
|
|
/* We need to get continuation elements and do intermediate restore */
|
|
|
|
/* abc1c2c3de with french secondaries need to be edc1c2c3ba NOT edc3c2c1ba */
|
|
|
|
if(isContinuation(ce)) {
|
|
|
|
if (frenchStartPtr == NULL) {
|
|
|
|
frenchStartPtr = secondaries - 2;
|
|
|
|
}
|
|
|
|
frenchEndPtr = secondaries-1;
|
|
|
|
} else if (frenchStartPtr != NULL) {
|
|
|
|
/* reverse secondaries from frenchStartPtr up to frenchEndPtr */
|
|
|
|
uprv_ucol_reverse_buffer(frenchStartPtr, frenchEndPtr);
|
|
|
|
frenchStartPtr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doCase) {
|
|
|
|
if (caseShift == 0) {
|
|
|
|
*cases++ = 0x80;
|
|
|
|
sortKeySize++;
|
|
|
|
caseShift = 7;
|
|
|
|
}
|
|
|
|
*(cases-1) |= (tertiary & 0x80) >> (8-caseShift--);
|
|
|
|
}
|
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(tertiary > compareTer) { /* I think that != 0 test should be != IGNORABLE */
|
2001-01-08 06:51:18 +00:00
|
|
|
/* This thing should also contain the compression logic, as in: */
|
|
|
|
/*
|
|
|
|
if (ws == COMMON2 && COMMON2 <= secondary[-1] && secondary[-1] < COMMON_MAX2)
|
|
|
|
++secondary[-1]; // simply increment!!
|
|
|
|
else *secondary++ = ws;
|
|
|
|
*/
|
|
|
|
|
|
|
|
*tertiaries++ = tertiary;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(shifted && primary1 > compareQuad) {
|
2001-01-08 06:51:18 +00:00
|
|
|
*quads++ = 0xFF;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sortKeySize>resultLength) { /* We have stepped over the primary buffer */
|
|
|
|
if(allocatePrimary == FALSE) { /* need to save our butts if we cannot reallocate */
|
|
|
|
resultOverflow = TRUE;
|
|
|
|
sortKeySize = ucol_getSortKeySizeNew(coll, &s, sortKeySize, strength, len);
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
finished = TRUE;
|
|
|
|
break;
|
|
|
|
} else { /* It's much nicer if we can actually reallocate */
|
|
|
|
uint8_t *newStart;
|
|
|
|
newStart = (uint8_t *)uprv_realloc(primStart, 2*sortKeySize);
|
|
|
|
if(primStart == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
finished = TRUE;
|
|
|
|
break;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
primaries=newStart+(primaries-primStart);
|
|
|
|
resultLength = 2*sortKeySize;
|
|
|
|
primStart = *result = newStart;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(finished) {
|
|
|
|
break;
|
|
|
|
} else {
|
2001-01-05 06:36:10 +00:00
|
|
|
prevBuffSize = minBufferSize;
|
|
|
|
secStart = reallocateBuffer(&secondaries, secStart, second, &secSize, status);
|
|
|
|
terStart = reallocateBuffer(&tertiaries, terStart, tert, &terSize, status);
|
|
|
|
caseStart = reallocateBuffer(&cases, caseStart, cases, &caseSize, status);
|
|
|
|
quadStart = reallocateBuffer(&quads, quadStart, quads, &quadSize, status);
|
|
|
|
minBufferSize *= 2;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-14 01:11:11 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
/* we have done all the CE's, now let's put them together to form a key */
|
2001-01-09 00:52:18 +00:00
|
|
|
if(compareSec == 0) {
|
2001-01-05 06:36:10 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
uint32_t secsize = secondaries-secStart;
|
2001-01-08 06:51:18 +00:00
|
|
|
if(isFrenchSec) { /* do the reverse copy */
|
|
|
|
/* If there are any unresolved continuation secondaries, reverse them here so that we can reverse the whole secondary thing */
|
|
|
|
if(frenchStartPtr != NULL) {
|
|
|
|
uprv_ucol_reverse_buffer(frenchStartPtr, frenchEndPtr);
|
|
|
|
}
|
|
|
|
for(i = 0; i<secsize; i++) {
|
|
|
|
*(primaries++) = *(secondaries-i-1);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
} else {
|
|
|
|
uprv_memcpy(primaries, secStart, secsize);
|
|
|
|
primaries += secsize;
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
}
|
2000-12-14 01:11:11 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
if(doCase) {
|
2001-01-05 00:47:25 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
2001-01-05 06:36:10 +00:00
|
|
|
uint32_t casesize = cases - caseStart;
|
|
|
|
uprv_memcpy(primaries, caseStart, casesize);
|
|
|
|
primaries += casesize;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(compareTer == 0) {
|
2001-01-05 00:47:25 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
2001-01-05 06:36:10 +00:00
|
|
|
uint32_t tersize = tertiaries - terStart;
|
|
|
|
uprv_memcpy(primaries, terStart, tersize);
|
|
|
|
primaries += tersize;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(compareQuad == 0) {
|
2001-01-05 06:36:10 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
uint32_t quadsize = quads - quadStart;
|
|
|
|
uprv_memcpy(primaries, quadStart, quadsize);
|
|
|
|
primaries += quadsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(compareIdent) {
|
|
|
|
UChar *ident = s.string;
|
|
|
|
uint8_t idByte = 0;
|
|
|
|
sortKeySize += len * sizeof(UChar);
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
while(ident < s.len) {
|
|
|
|
idByte = (*(ident) >> 8) + utf16fixup[*(ident) >> 11];
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
if(sortKeySize < resultLength) {
|
|
|
|
*(primaries++) = 0x01;
|
|
|
|
sortKeySize++;
|
|
|
|
*(primaries++) = idByte + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(primaries++) = idByte;
|
|
|
|
}
|
|
|
|
idByte = (*(ident) & 0xFF);
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
if(sortKeySize < resultLength) {
|
|
|
|
*(primaries++) = 0x01;
|
|
|
|
sortKeySize++;
|
|
|
|
*(primaries++) = idByte + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(primaries++) = idByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
ident++;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-05 06:36:10 +00:00
|
|
|
} else {
|
|
|
|
while(ident < s.len) {
|
|
|
|
idByte = (*(ident) >> 8) + utf16fixup[*(ident) >> 11];
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
idByte = (*(ident) & 0xFF);
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
ident++;
|
|
|
|
}
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
*(primaries++) = '\0';
|
|
|
|
} else {
|
|
|
|
sortKeySize = 0;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
|
|
|
if(terStart != tert) {
|
|
|
|
uprv_free(terStart);
|
|
|
|
uprv_free(secStart);
|
2001-01-05 06:36:10 +00:00
|
|
|
uprv_free(caseStart);
|
|
|
|
uprv_free(quadStart);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-05 06:36:10 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(normSource != normBuffer) {
|
|
|
|
uprv_free(normSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sortKeySize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
|
|
|
ucol_getSortKeyNew(const UCollatorNew *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t *result,
|
|
|
|
int32_t resultLength)
|
|
|
|
{
|
2001-01-05 06:36:10 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
return ucol_calcSortKeyNew(coll, source, sourceLength, &result, resultLength, FALSE, &status);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void ucol_setAttributeNew(UCollatorNew *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status) {
|
|
|
|
switch(attr) {
|
|
|
|
case UCOL_FRENCH_COLLATION: /* attribute for direction of secondary weights*/
|
|
|
|
if(value == UCOL_ON) {
|
|
|
|
coll->frenchCollation = UCOL_ON;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->frenchCollationisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_OFF) {
|
|
|
|
coll->frenchCollation = UCOL_OFF;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->frenchCollationisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->frenchCollationisDefault = TRUE;
|
|
|
|
coll->frenchCollation = coll->image->frenchCollation;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_ALTERNATE_HANDLING: /* attribute for handling variable elements*/
|
|
|
|
if(value == UCOL_SHIFTED) {
|
|
|
|
coll->alternateHandling = UCOL_SHIFTED;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->alternateHandlingisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_NON_IGNORABLE) {
|
|
|
|
coll->alternateHandling = UCOL_NON_IGNORABLE;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->alternateHandlingisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->alternateHandlingisDefault = TRUE;
|
|
|
|
coll->alternateHandling = coll->image->alternateHandling ;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_CASE_FIRST: /* who goes first, lower case or uppercase */
|
|
|
|
if(value == UCOL_LOWER_FIRST) {
|
|
|
|
coll->caseFirst = UCOL_LOWER_FIRST;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseFirstisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_UPPER_FIRST) {
|
|
|
|
coll->caseFirst = UCOL_UPPER_FIRST;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseFirstisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseFirst = coll->image->caseFirst;
|
|
|
|
coll->caseFirstisDefault = TRUE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_CASE_LEVEL: /* do we have an extra case level */
|
|
|
|
if(value == UCOL_ON) {
|
|
|
|
coll->caseLevel = UCOL_ON;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseLevelisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_OFF) {
|
|
|
|
coll->caseLevel = UCOL_OFF;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseLevelisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseLevel = coll->image->caseLevel;
|
|
|
|
coll->caseLevelisDefault = TRUE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_NORMALIZATION_MODE: /* attribute for normalization */
|
|
|
|
if(value == UCOL_ON) {
|
|
|
|
coll->normalizationMode = UCOL_ON;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_OFF) {
|
|
|
|
coll->normalizationMode = UCOL_OFF;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_ON_WITHOUT_HANGUL) {
|
|
|
|
coll->normalizationMode = UCOL_ON_WITHOUT_HANGUL ;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = TRUE;
|
|
|
|
coll->normalizationMode = coll->image->normalizationMode;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_STRENGTH: /* attribute for strength */
|
|
|
|
if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->strengthisDefault = TRUE;
|
|
|
|
coll->strength = coll->image->strength;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else if (value <= UCOL_IDENTICAL) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->strengthisDefault = FALSE;
|
2001-01-05 00:47:25 +00:00
|
|
|
coll->strength = value;
|
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_ATTRIBUTE_COUNT:
|
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UColAttributeValue ucol_getAttributeNew(const UCollatorNew *coll, UColAttribute attr, UErrorCode *status) {
|
|
|
|
switch(attr) {
|
|
|
|
case UCOL_FRENCH_COLLATION: /* attribute for direction of secondary weights*/
|
2001-01-09 00:52:18 +00:00
|
|
|
if(coll->frenchCollationisDefault) {
|
|
|
|
return coll->image->frenchCollation;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
return coll->frenchCollation;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_ALTERNATE_HANDLING: /* attribute for handling variable elements*/
|
2001-01-09 00:52:18 +00:00
|
|
|
if(coll->alternateHandlingisDefault) {
|
|
|
|
return coll->image->alternateHandling;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
return coll->alternateHandling;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_CASE_FIRST: /* who goes first, lower case or uppercase */
|
2001-01-09 00:52:18 +00:00
|
|
|
if(coll->caseFirstisDefault) {
|
|
|
|
return coll->image->caseFirst;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
return coll->caseFirst;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_CASE_LEVEL: /* do we have an extra case level */
|
2001-01-09 00:52:18 +00:00
|
|
|
if(coll->caseLevelisDefault) {
|
|
|
|
return coll->image->caseLevel;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
return coll->caseLevel;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_NORMALIZATION_MODE: /* attribute for normalization */
|
2001-01-09 00:52:18 +00:00
|
|
|
if(coll->normalizationModeisDefault) {
|
|
|
|
return coll->image->normalizationMode;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
return coll->normalizationMode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_STRENGTH: /* attribute for strength */
|
2001-01-09 00:52:18 +00:00
|
|
|
if(coll->strengthisDefault) {
|
|
|
|
return coll->image->strength;
|
2001-01-05 00:47:25 +00:00
|
|
|
} else {
|
|
|
|
return coll->strength;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_ATTRIBUTE_COUNT:
|
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return UCOL_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollator*
|
|
|
|
ucol_open( const char *loc,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status)) return 0;
|
|
|
|
|
|
|
|
Collator *col = 0;
|
|
|
|
|
|
|
|
if(loc == 0)
|
|
|
|
col = Collator::createInstance(*status);
|
|
|
|
else
|
|
|
|
col = Collator::createInstance(Locale(loc), *status);
|
|
|
|
|
|
|
|
if(col == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UCollator*)col;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollator*
|
|
|
|
ucol_openRules( const UChar *rules,
|
|
|
|
int32_t rulesLength,
|
|
|
|
UNormalizationMode mode,
|
|
|
|
UCollationStrength strength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status)) return 0;
|
|
|
|
|
|
|
|
int32_t len = (rulesLength == -1 ? u_strlen(rules) : rulesLength);
|
|
|
|
const UnicodeString ruleString((UChar*)rules, len, len);
|
|
|
|
|
|
|
|
Normalizer::EMode normMode;
|
|
|
|
switch(mode) {
|
|
|
|
case UCOL_NO_NORMALIZATION:
|
|
|
|
normMode = Normalizer::NO_OP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN:
|
|
|
|
normMode = Normalizer::DECOMP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT:
|
|
|
|
normMode = Normalizer::DECOMP_COMPAT;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN_COMP_COMPAT:
|
|
|
|
normMode = Normalizer::COMPOSE;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT_COMP_CAN:
|
|
|
|
normMode = Normalizer::COMPOSE_COMPAT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RuleBasedCollator *col = 0;
|
|
|
|
col = new RuleBasedCollator(ruleString,
|
|
|
|
(Collator::ECollationStrength) strength,
|
|
|
|
normMode,
|
|
|
|
*status);
|
|
|
|
|
|
|
|
if(col == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UCollator*) col;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
ucol_close(UCollator *coll)
|
|
|
|
{
|
|
|
|
delete (Collator*)coll;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UBool
|
|
|
|
ucol_greater( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
|
|
|
== UCOL_GREATER);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UBool
|
|
|
|
ucol_greaterOrEqual( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
|
|
|
!= UCOL_LESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UBool
|
|
|
|
ucol_equal( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
|
|
|
== UCOL_EQUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollationStrength
|
|
|
|
ucol_getStrength(const UCollator *coll)
|
|
|
|
{
|
|
|
|
return (UCollationStrength) ((Collator*)coll)->getStrength();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
ucol_setStrength( UCollator *coll,
|
|
|
|
UCollationStrength strength)
|
|
|
|
{
|
|
|
|
((Collator*)coll)->setStrength((Collator::ECollationStrength)strength);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UNormalizationMode
|
|
|
|
ucol_getNormalization(const UCollator* coll)
|
|
|
|
{
|
|
|
|
switch(((Collator*)coll)->getDecomposition()) {
|
|
|
|
case Normalizer::NO_OP:
|
|
|
|
return UCOL_NO_NORMALIZATION;
|
|
|
|
|
|
|
|
case Normalizer::COMPOSE:
|
|
|
|
return UCOL_DECOMP_COMPAT_COMP_CAN;
|
|
|
|
|
|
|
|
case Normalizer::COMPOSE_COMPAT:
|
|
|
|
return UCOL_DECOMP_CAN_COMP_COMPAT;
|
|
|
|
|
|
|
|
case Normalizer::DECOMP:
|
|
|
|
return UCOL_DECOMP_CAN;
|
|
|
|
|
|
|
|
case Normalizer::DECOMP_COMPAT:
|
|
|
|
return UCOL_DECOMP_COMPAT;
|
|
|
|
|
|
|
|
}
|
|
|
|
return UCOL_NO_NORMALIZATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
ucol_setNormalization( UCollator *coll,
|
|
|
|
UNormalizationMode mode)
|
|
|
|
{
|
|
|
|
Normalizer::EMode normMode;
|
|
|
|
switch(mode) {
|
|
|
|
case UCOL_NO_NORMALIZATION:
|
|
|
|
normMode = Normalizer::NO_OP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN:
|
|
|
|
normMode = Normalizer::DECOMP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT:
|
|
|
|
normMode = Normalizer::DECOMP_COMPAT;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT_COMP_CAN:
|
|
|
|
normMode = Normalizer::COMPOSE;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN_COMP_COMPAT:
|
|
|
|
normMode = Normalizer::COMPOSE_COMPAT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Shouldn't get here. */
|
|
|
|
/* *status = U_ILLEGAL_ARGUMENT_ERROR; */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
((Collator*)coll)->setDecomposition(normMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
|
|
|
ucol_getDisplayName( const char *objLoc,
|
|
|
|
const char *dispLoc,
|
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status)) return -1;
|
|
|
|
|
|
|
|
UnicodeString dst(result, resultLength, resultLength);
|
|
|
|
Collator::getDisplayName(Locale(objLoc), Locale(dispLoc), dst);
|
|
|
|
int32_t actLen;
|
|
|
|
T_fillOutputParams(&dst, result, resultLength, &actLen, status);
|
|
|
|
return actLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const char*
|
|
|
|
ucol_getAvailable(int32_t index)
|
|
|
|
{
|
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
|
|
|
ucol_countAvailable()
|
|
|
|
{
|
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void *ucol_getABuffer(const UCollator *coll, uint32_t size) {
|
|
|
|
return ((RuleBasedCollator *)coll)->getSomeMemory(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar*
|
|
|
|
ucol_getRules( const UCollator *coll,
|
|
|
|
int32_t *length)
|
|
|
|
{
|
|
|
|
const UnicodeString& rules = ((RuleBasedCollator*)coll)->getRules();
|
|
|
|
*length = rules.length();
|
|
|
|
return rules.getUChars();
|
|
|
|
}
|
|
|
|
|
|
|
|
UCollationResult ucol_compareUsingSortKeys(const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
uint8_t sourceKey[UCOL_MAX_BUFFER], targetKey[UCOL_MAX_BUFFER];
|
|
|
|
uint8_t *sourceKeyP = sourceKey;
|
|
|
|
uint8_t *targetKeyP = targetKey;
|
|
|
|
int32_t sourceKeyLen = UCOL_MAX_BUFFER, targetKeyLen = UCOL_MAX_BUFFER;
|
|
|
|
|
|
|
|
sourceKeyLen = ucol_getSortKey(coll, source, sourceLength, sourceKeyP, sourceKeyLen);
|
|
|
|
if(sourceKeyLen > UCOL_MAX_BUFFER) {
|
|
|
|
sourceKeyP = (uint8_t*)uprv_malloc(sourceKeyLen*sizeof(uint8_t));
|
|
|
|
sourceKeyLen = ucol_getSortKey(coll, source, sourceLength, sourceKeyP, sourceKeyLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
targetKeyLen = ucol_getSortKey(coll, target, targetLength, targetKeyP, targetKeyLen);
|
|
|
|
if(targetKeyLen > UCOL_MAX_BUFFER) {
|
|
|
|
targetKeyP = (uint8_t*)uprv_malloc(targetKeyLen*sizeof(uint8_t));
|
|
|
|
targetKeyLen = ucol_getSortKey(coll, target, targetLength, targetKeyP, targetKeyLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t result = uprv_strcmp((const char*)sourceKeyP, (const char*)targetKeyP);
|
|
|
|
|
|
|
|
if(sourceKeyP != sourceKey) {
|
|
|
|
uprv_free(sourceKeyP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(targetKeyP != targetKey) {
|
|
|
|
uprv_free(targetKeyP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result<0) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else if(result>0) {
|
|
|
|
return UCOL_GREATER;
|
|
|
|
} else {
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t getComplicatedCE(const UCollator *coll, collIterate *source, UErrorCode *status) {
|
|
|
|
if (*(source->CEpos) == UCOL_UNMAPPED) {
|
|
|
|
// Returned an "unmapped" flag and save the character so it can be
|
|
|
|
// returned next time this method is called.
|
|
|
|
if (*(source->pos) == 0x0000) return *(source->pos++); // \u0000 is not valid in C++'s UnicodeString
|
|
|
|
*(source->CEpos++) = UCOL_UNMAPPEDCHARVALUE;
|
|
|
|
*(source->CEpos++) = *(source->pos)<<16;
|
|
|
|
} else {
|
|
|
|
// Contraction sequence start...
|
|
|
|
if (*(source->CEpos) >= UCOL_CONTRACTCHARINDEX) {
|
|
|
|
UChar key[1024];
|
|
|
|
uint32_t posKey = 0;
|
|
|
|
|
|
|
|
VectorOfPToContractElement* list = ((RuleBasedCollator *)coll)->data->contractTable->at(*(source->CEpos)-UCOL_CONTRACTCHARINDEX);
|
|
|
|
// The upper line obtained a list of contracting sequences.
|
|
|
|
if (list != NULL) {
|
|
|
|
EntryPair *pair = (EntryPair *)list->at(0); // Taking out the first one.
|
|
|
|
int32_t order = pair->value; // This got us mapping for just the first element - the one that signalled a contraction.
|
|
|
|
|
|
|
|
key[posKey++] = *(source->pos++);
|
|
|
|
// This tries to find the longes common match for the data in contraction table...
|
|
|
|
// and needs to be rewritten, especially the test down there!
|
|
|
|
int32_t i;
|
|
|
|
int32_t listSize = list->size();
|
|
|
|
UBool foundSmaller = TRUE;
|
|
|
|
while(source->pos<source->len && foundSmaller) {
|
|
|
|
key[posKey++] = *source->pos;
|
|
|
|
|
|
|
|
foundSmaller = FALSE;
|
|
|
|
i = 0;
|
|
|
|
while(i<listSize && !foundSmaller) {
|
|
|
|
pair = list->at(i);
|
|
|
|
if ((pair != NULL) && (pair->fwd == TRUE /*fwd*/) && (pair->equalTo(key, posKey))) {
|
|
|
|
/* Found a matching contraction sequence */
|
|
|
|
order = pair->value; /* change the CE value */
|
|
|
|
source->pos++; /* consume another char from the source */
|
|
|
|
foundSmaller = TRUE;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
source->pos--; /* spit back the last char - it wasn't part of the sequence */
|
|
|
|
*(source->CEpos) = order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Expansion sequence start...
|
|
|
|
if (*(source->CEpos) >= UCOL_EXPANDCHARINDEX) {
|
|
|
|
VectorOfInt *v = ((RuleBasedCollator *)coll)->data->expandTable->at(*(source->CEpos)-UCOL_EXPANDCHARINDEX);
|
|
|
|
if(v != NULL) {
|
|
|
|
int32_t expandindex=0;
|
|
|
|
int32_t vSize = v->size();
|
|
|
|
while(expandindex < vSize) {
|
|
|
|
*(source->CEpos++) = v->at(expandindex++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Thai/Lao reordering
|
|
|
|
if (UCOL_ISTHAIPREVOWEL(*(source->pos)) &&
|
|
|
|
UCOL_ISTHAIBASECONSONANT(*(source->pos+1))) {
|
|
|
|
if(source->isThai == TRUE) {
|
|
|
|
source->isThai = FALSE;
|
|
|
|
if((source->len - source->pos) > UCOL_WRITABLE_BUFFER_SIZE) {
|
|
|
|
// allocate a new buffer
|
|
|
|
source->writableBuffer = (UChar *)ucol_getABuffer(coll, (source->len - source->pos)*sizeof(UChar));
|
|
|
|
}
|
|
|
|
UChar *sourceCopy = source->pos;
|
|
|
|
UChar *targetCopy = source->writableBuffer;
|
|
|
|
while(sourceCopy < source->len) {
|
|
|
|
if(UCOL_ISTHAIPREVOWEL(*(sourceCopy)) &&
|
|
|
|
UCOL_ISTHAIBASECONSONANT(*(sourceCopy+1))) {
|
|
|
|
*(targetCopy) = *(sourceCopy+1);
|
|
|
|
*(targetCopy+1) = *(sourceCopy);
|
|
|
|
targetCopy+=2;
|
|
|
|
sourceCopy+=2;
|
|
|
|
} else {
|
|
|
|
*(targetCopy++) = *(sourceCopy++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
source->pos = source->writableBuffer;
|
|
|
|
source->len = targetCopy;
|
|
|
|
source->CEpos = source->toReturn = source->CEs;
|
|
|
|
return UCOL_IGNORABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
source->pos++;
|
|
|
|
return (*(source->toReturn++));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is the original function */
|
|
|
|
U_CAPI UCollationResult
|
|
|
|
ucol_strcollEx( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
if (coll == NULL) return UCOL_EQUAL;
|
|
|
|
if (sourceLength == -1) sourceLength = u_strlen(source);
|
|
|
|
if (targetLength == -1) targetLength = u_strlen(target);
|
|
|
|
return (UCollationResult) ((RuleBasedCollator*)coll)->compareEx(source,sourceLength,target,targetLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_incrementalContext(UCharForwardIterator *source, void *sourceContext, incrementalContext *s) {
|
|
|
|
s->len = s->stringP = s->stackString ;
|
|
|
|
s->capacity = s->stackString+UCOL_MAX_BUFFER;
|
|
|
|
s->CEpos = s->toReturn = s->CEs;
|
|
|
|
s->source = source;
|
|
|
|
s->sourceContext = sourceContext;
|
|
|
|
s->currentChar = 0xFFFF;
|
|
|
|
s->lastChar = 0xFFFF;
|
|
|
|
s->panic = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ucol_getIncrementalCE(const UCollator *coll, incrementalContext *ctx, UErrorCode *status) {
|
|
|
|
|
|
|
|
uint32_t order;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status) /*|| (ctx->CEpos <= ctx->toReturn)*/) {
|
|
|
|
return UCOL_NULLORDER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->CEpos > ctx->toReturn) {
|
|
|
|
return(*(ctx->toReturn++));
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->CEpos = ctx->toReturn = ctx->CEs;
|
|
|
|
|
|
|
|
if(ctx->lastChar == 0xFFFF) {
|
|
|
|
ctx->currentChar = ctx->source(ctx->sourceContext);
|
|
|
|
incctx_appendChar(ctx, ctx->currentChar);
|
|
|
|
//*(ctx->len++) = ctx->currentChar;
|
|
|
|
if(ctx->currentChar == 0xFFFF) {
|
|
|
|
return UCOL_NULLORDER;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctx->currentChar = ctx->lastChar;
|
|
|
|
ctx->lastChar = 0xFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
order = ucmp32_get(((RuleBasedCollator *)coll)->data->mapping, ctx->currentChar);
|
|
|
|
|
|
|
|
// this should benefit from reordering of the clauses, so that the cleanest case is returned the first.
|
|
|
|
|
|
|
|
if(order < UCOL_EXPANDCHARINDEX && !(UCOL_ISTHAIPREVOWEL(ctx->currentChar))) {
|
|
|
|
return (order);
|
|
|
|
}
|
|
|
|
if (order == UCOL_UNMAPPED) {
|
|
|
|
// Returned an "unmapped" flag and save the character so it can be
|
|
|
|
// returned next time this method is called.
|
|
|
|
if (ctx->currentChar == 0x0000) return ctx->currentChar; // \u0000 is not valid in C++'s UnicodeString
|
|
|
|
//*(ctx->CEpos++) = UCOL_UNMAPPEDCHARVALUE;
|
|
|
|
order = UCOL_UNMAPPEDCHARVALUE;
|
|
|
|
*(ctx->CEpos++) = ctx->currentChar<<16;
|
|
|
|
} else {
|
|
|
|
// Contraction sequence start...
|
|
|
|
if (order >= UCOL_CONTRACTCHARINDEX) {
|
|
|
|
UChar key[1024];
|
|
|
|
uint32_t posKey = 0;
|
|
|
|
|
|
|
|
VectorOfPToContractElement* list = ((RuleBasedCollator *)coll)->data->contractTable->at(order-UCOL_CONTRACTCHARINDEX);
|
|
|
|
// The upper line obtained a list of contracting sequences.
|
|
|
|
if (list != NULL) {
|
|
|
|
EntryPair *pair = (EntryPair *)list->at(0); // Taking out the first one.
|
|
|
|
order = pair->value; // This got us mapping for just the first element - the one that signalled a contraction.
|
|
|
|
|
|
|
|
key[posKey++] = ctx->currentChar;
|
|
|
|
// This tries to find the longes common match for the data in contraction table...
|
|
|
|
// and needs to be rewritten, especially the test down there!
|
|
|
|
int32_t i;
|
|
|
|
int32_t listSize = list->size();
|
|
|
|
UBool foundSmaller = TRUE;
|
|
|
|
UBool endOfString = FALSE;
|
|
|
|
//*(ctx->len++) = ctx->lastChar;
|
|
|
|
incctx_appendChar(ctx, ctx->lastChar);
|
|
|
|
while(!endOfString && foundSmaller) {
|
|
|
|
endOfString = ((ctx->lastChar = ctx->source(ctx->sourceContext)) == 0xFFFF);
|
|
|
|
key[posKey++] = ctx->lastChar;
|
|
|
|
|
|
|
|
foundSmaller = FALSE;
|
|
|
|
i = 0;
|
|
|
|
while(i<listSize && !foundSmaller) {
|
|
|
|
pair = list->at(i);
|
|
|
|
if ((pair != NULL) && (pair->fwd == TRUE /*fwd*/) && (pair->equalTo(key, posKey))) {
|
|
|
|
order = pair->value;
|
|
|
|
//*(ctx->len++) = ctx->lastChar;
|
|
|
|
incctx_appendChar(ctx, ctx->lastChar);
|
|
|
|
foundSmaller = TRUE;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Expansion sequence start...
|
|
|
|
if (order >= UCOL_EXPANDCHARINDEX) {
|
|
|
|
VectorOfInt *v = ((RuleBasedCollator *)coll)->data->expandTable->at(order-UCOL_EXPANDCHARINDEX);
|
|
|
|
if(v != NULL) {
|
|
|
|
int32_t expandindex=0;
|
|
|
|
int32_t vSize = v->size();
|
|
|
|
order = v->at(expandindex++); // first character....
|
|
|
|
while(expandindex < vSize) {
|
|
|
|
*(ctx->CEpos++) = v->at(expandindex++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Thai/Lao reordering
|
|
|
|
// This is gonna be way too goofy - so we're gonna bail out and let others do the work...
|
|
|
|
if (UCOL_ISTHAIPREVOWEL(ctx->currentChar)) {
|
|
|
|
ctx->panic = TRUE;
|
|
|
|
return UCOL_NULLORDER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
void incctx_cleanUpContext(incrementalContext *ctx) {
|
|
|
|
if(ctx->stringP != ctx->stackString) {
|
|
|
|
uprv_free(ctx->stringP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar incctx_appendChar(incrementalContext *ctx, UChar c) {
|
|
|
|
if(ctx->len == ctx->capacity) { /* bother, said Pooh, we need to reallocate */
|
|
|
|
UChar *newStuff;
|
|
|
|
if(ctx->stringP == ctx->stackString) { /* we haven't allocated before, need to allocate */
|
|
|
|
newStuff = (UChar *)uprv_malloc(2*(ctx->capacity - ctx->stringP)*sizeof(UChar));
|
|
|
|
if(newStuff == NULL) {
|
|
|
|
/*freak out*/
|
|
|
|
}
|
|
|
|
uprv_memcpy(newStuff, ctx->stringP, (ctx->capacity - ctx->stringP)*sizeof(UChar));
|
|
|
|
} else { /* we have already allocated, need to reallocate */
|
|
|
|
newStuff = (UChar *)uprv_realloc(ctx->stringP, 2*(ctx->capacity - ctx->stringP)*sizeof(UChar));
|
|
|
|
if(newStuff == NULL) {
|
|
|
|
/*freak out*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx->len=newStuff+(ctx->len - ctx->stringP);
|
|
|
|
ctx->capacity = newStuff+2*(ctx->capacity - ctx->stringP);
|
|
|
|
ctx->stringP = newStuff;
|
|
|
|
}
|
|
|
|
*(ctx->len++) = c;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UCollationResult alternateIncrementalProcessing(const UCollator *coll, incrementalContext *srcCtx, incrementalContext *trgCtx) {
|
|
|
|
if(srcCtx->stringP == srcCtx->len || *(srcCtx->len-1) != 0xFFFF) {
|
|
|
|
while(incctx_appendChar(srcCtx, srcCtx->source(srcCtx->sourceContext)) != 0xFFFF);
|
|
|
|
}
|
|
|
|
if(trgCtx->stringP == trgCtx->len || *(trgCtx->len-1) != 0xFFFF) {
|
|
|
|
while(incctx_appendChar(trgCtx, trgCtx->source(trgCtx->sourceContext)) != 0xFFFF);
|
2000-12-14 01:11:11 +00:00
|
|
|
}
|
|
|
|
UCollationResult result = ucol_strcoll(coll, srcCtx->stringP, srcCtx->len-srcCtx->stringP-1, trgCtx->stringP, trgCtx->len-trgCtx->stringP-1);
|
|
|
|
incctx_cleanUpContext(srcCtx);
|
|
|
|
incctx_cleanUpContext(trgCtx);
|
|
|
|
return result;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the incremental function */
|
|
|
|
U_CAPI UCollationResult ucol_strcollinc(const UCollator *coll,
|
|
|
|
UCharForwardIterator *source, void *sourceContext,
|
|
|
|
UCharForwardIterator *target, void *targetContext)
|
|
|
|
{
|
|
|
|
Collator *cppColl = (Collator*)coll;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
|
|
|
UCollationResult result = UCOL_EQUAL;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
incrementalContext sColl, tColl;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-12-06 00:53:48 +00:00
|
|
|
init_incrementalContext(source, sourceContext, &sColl);
|
|
|
|
init_incrementalContext(target, targetContext, &tColl);
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
if(cppColl->getDecomposition() != Normalizer::NO_OP) { // run away screaming!!!!
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (U_FAILURE(status))
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
|
2000-12-05 01:03:35 +00:00
|
|
|
UColAttributeValue strength = ucol_getAttribute(coll, UCOL_STRENGTH, &status);
|
2000-12-06 00:53:48 +00:00
|
|
|
uint32_t sOrder=UCOL_NULLORDER, tOrder=UCOL_NULLORDER;
|
2000-11-29 00:16:15 +00:00
|
|
|
uint32_t pSOrder, pTOrder;
|
2000-11-20 19:17:17 +00:00
|
|
|
UBool gets = TRUE, gett = TRUE;
|
2000-12-05 01:03:35 +00:00
|
|
|
UBool initialCheckSecTer = strength >= UCOL_SECONDARY;
|
2000-11-20 19:17:17 +00:00
|
|
|
UBool checkSecTer = initialCheckSecTer;
|
2000-12-05 01:03:35 +00:00
|
|
|
UBool checkTertiary = strength >= UCOL_TERTIARY;
|
|
|
|
UBool checkQuad = strength >= UCOL_QUATERNARY;
|
2000-11-29 04:48:39 +00:00
|
|
|
UBool isFrenchSec = (cppColl->getAttribute(UCOL_FRENCH_COLLATION, status) == UCOL_ON) && checkSecTer;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if(!isFrenchSec) {
|
|
|
|
for(;;)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Get the next collation element in each of the strings, unless
|
|
|
|
// we've been requested to skip it.
|
|
|
|
if (gets)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-30 23:20:14 +00:00
|
|
|
sOrder = ucol_getIncrementalCE(coll, &sColl, &status);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
gets = TRUE;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (gett)
|
|
|
|
{
|
2000-11-30 23:20:14 +00:00
|
|
|
tOrder = ucol_getIncrementalCE(coll, &tColl, &status);
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
|
|
|
gett = TRUE;
|
|
|
|
|
|
|
|
// If we've hit the end of one of the strings, jump out of the loop
|
2000-11-30 23:20:14 +00:00
|
|
|
if ((sOrder == UCOL_NULLORDER)||
|
|
|
|
(tOrder == UCOL_NULLORDER)) {
|
|
|
|
if(sColl.panic == TRUE || tColl.panic == TRUE) {
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// If there's no difference at this position, we can skip to the
|
|
|
|
// next one.
|
|
|
|
if (sOrder == tOrder)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// Compare primary differences first.
|
2000-11-30 23:20:14 +00:00
|
|
|
pSOrder = UCOL_PRIMARYORDER(sOrder);
|
|
|
|
pTOrder = UCOL_PRIMARYORDER(tOrder);
|
2000-11-29 00:16:15 +00:00
|
|
|
if (pSOrder != pTOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (sOrder == UCOL_IGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// The entire source element is ignorable.
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (tOrder == UCOL_IGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
gets = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The source and target elements aren't ignorable, but it's still possible
|
|
|
|
// for the primary component of one of the elements to be ignorable....
|
2000-12-08 22:03:01 +00:00
|
|
|
if (pSOrder == UCOL_PRIMIGNORABLE) // primary order in source is ignorable
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// The source's primary is ignorable, but the target's isn't. We treat ignorables
|
|
|
|
// as a secondary difference, so remember that we found one.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER; // (strength is SECONDARY) - still need to check for tertiary or quad
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
}
|
2000-12-08 22:03:01 +00:00
|
|
|
else if (pTOrder == UCOL_PRIMIGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// record differences - see the comment above.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS; // (strength is SECONDARY) - still need to check for tertiary or quad
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
// Skip to the next target element, but don't fetch another source element.
|
|
|
|
gets = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Neither of the orders is ignorable, and we already know that the primary
|
|
|
|
// orders are different because of the (pSOrder != pTOrder) test above.
|
|
|
|
// Record the difference and stop the comparison.
|
2000-12-14 01:11:11 +00:00
|
|
|
incctx_cleanUpContext(&sColl);
|
|
|
|
incctx_cleanUpContext(&tColl);
|
2000-11-29 00:16:15 +00:00
|
|
|
if (pSOrder < pTOrder)
|
|
|
|
{
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
else
|
|
|
|
{ // else of if ( pSOrder != pTOrder )
|
|
|
|
// primary order is the same, but complete order is different. So there
|
|
|
|
// are no base elements at this point, only ignorables (Since the strings are
|
|
|
|
// normalized)
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
// a secondary or tertiary difference may still matter
|
2000-11-30 23:20:14 +00:00
|
|
|
uint32_t secSOrder = UCOL_SECONDARYORDER(sOrder);
|
|
|
|
uint32_t secTOrder = UCOL_SECONDARYORDER(tOrder);
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (secSOrder != secTOrder)
|
|
|
|
{
|
|
|
|
// there is a secondary difference
|
|
|
|
result = (secSOrder < secTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (checkTertiary)
|
|
|
|
{
|
|
|
|
// a tertiary difference may still matter
|
2000-11-30 23:20:14 +00:00
|
|
|
uint32_t terSOrder = UCOL_TERTIARYORDER(sOrder);
|
|
|
|
uint32_t terTOrder = UCOL_TERTIARYORDER(tOrder);
|
2000-11-29 00:16:15 +00:00
|
|
|
|
|
|
|
if (terSOrder != terTOrder)
|
|
|
|
{
|
|
|
|
// there is a tertiary difference
|
|
|
|
result = (terSOrder < terTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is TERTIARY)
|
|
|
|
checkTertiary = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if (checkSecTer)
|
|
|
|
|
|
|
|
} // if ( pSOrder != pTOrder )
|
|
|
|
} // while()
|
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
if (sOrder != UCOL_NULLORDER)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// (tOrder must be CollationElementIterator::NULLORDER,
|
|
|
|
// since this point is only reached when sOrder or tOrder is NULLORDER.)
|
|
|
|
// The source string has more elements, but the target string hasn't.
|
|
|
|
do
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_PRIMARYORDER(sOrder) != UCOL_PRIMIGNORABLE)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// We found an additional non-ignorable base character in the source string.
|
|
|
|
// This is a primary difference, so the source is greater
|
2000-12-14 01:11:11 +00:00
|
|
|
incctx_cleanUpContext(&sColl);
|
|
|
|
incctx_cleanUpContext(&tColl);
|
2000-11-29 00:16:15 +00:00
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_SECONDARYORDER(sOrder) != UCOL_SECIGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// Additional secondary elements mean the source string is greater
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER; // (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
sOrder = ucol_getIncrementalCE(coll, &sColl, &status);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
//while ((sOrder = ucol_getIncrementalCE(coll, &sColl, &status)) != CollationElementIterator::NULLORDER);
|
|
|
|
while (sOrder != UCOL_NULLORDER);
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
else if (tOrder != UCOL_NULLORDER)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// The target string has more elements, but the source string hasn't.
|
|
|
|
do
|
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_PRIMARYORDER(tOrder) != UCOL_PRIMIGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the target string.
|
|
|
|
// This is a primary difference, so the source is less
|
2000-12-14 01:11:11 +00:00
|
|
|
incctx_cleanUpContext(&sColl);
|
|
|
|
incctx_cleanUpContext(&tColl);
|
2000-11-29 00:16:15 +00:00
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_SECONDARYORDER(tOrder) != UCOL_SECIGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// Additional secondary elements in the target mean the source string is less
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS; // (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
tOrder = ucol_getIncrementalCE(coll, &tColl, &status);
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
while ( tOrder != UCOL_NULLORDER);
|
|
|
|
//while ((tOrder = ucol_getIncrementalCE(coll, &tColl, &status)) != CollationElementIterator::NULLORDER);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
} else { //French
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// there is a bad situation with French when there is a different number of secondaries...
|
|
|
|
// If that situation arises (when one primary is ignorable with nonignorable secondary and the other primary is not
|
|
|
|
// ignorable
|
2000-11-30 23:20:14 +00:00
|
|
|
// TODO: if the buffer is not big enough, we should use sortkeys
|
2000-11-29 00:16:15 +00:00
|
|
|
UBool bufferFrenchSec = FALSE;
|
|
|
|
uint32_t sourceFrenchSec[UCOL_MAX_BUFFER], targetFrenchSec[UCOL_MAX_BUFFER];
|
|
|
|
uint32_t *sFSBEnd = sourceFrenchSec+UCOL_MAX_BUFFER;
|
|
|
|
uint32_t *tFSBEnd = targetFrenchSec+UCOL_MAX_BUFFER;
|
|
|
|
|
|
|
|
for(;;)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Get the next collation element in each of the strings, unless
|
|
|
|
// we've been requested to skip it.
|
|
|
|
if (gets)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-30 23:20:14 +00:00
|
|
|
sOrder = ucol_getIncrementalCE(coll, &sColl, &status);
|
|
|
|
*(--sFSBEnd) = UCOL_SECONDARYORDER(sOrder);
|
2000-12-07 07:22:55 +00:00
|
|
|
if(sFSBEnd == sourceFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-12-06 00:53:48 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
gets = TRUE;
|
|
|
|
|
|
|
|
if (gett)
|
|
|
|
{
|
2000-11-30 23:20:14 +00:00
|
|
|
tOrder = ucol_getIncrementalCE(coll, &tColl, &status);
|
|
|
|
*(--tFSBEnd) = UCOL_SECONDARYORDER(tOrder);
|
2000-12-07 07:22:55 +00:00
|
|
|
if(tFSBEnd == targetFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gett = TRUE;
|
|
|
|
|
|
|
|
// If we've hit the end of one of the strings, jump out of the loop
|
2000-11-30 23:20:14 +00:00
|
|
|
if ((sOrder == UCOL_NULLORDER)||
|
|
|
|
(tOrder == UCOL_NULLORDER)) {
|
2000-11-29 00:16:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no difference at this position, we can skip to the
|
|
|
|
// next one.
|
|
|
|
if (sOrder == tOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// Compare primary differences first.
|
2000-11-30 23:20:14 +00:00
|
|
|
pSOrder = UCOL_PRIMARYORDER(sOrder);
|
|
|
|
pTOrder = UCOL_PRIMARYORDER(tOrder);
|
2000-11-29 00:16:15 +00:00
|
|
|
if (pSOrder != pTOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (sOrder == UCOL_IGNORABLE)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// The entire source element is ignorable.
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
continue;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (tOrder == UCOL_IGNORABLE)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
gets = FALSE;
|
|
|
|
continue;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// The source and target elements aren't ignorable, but it's still possible
|
|
|
|
// for the primary component of one of the elements to be ignorable....
|
2000-12-08 22:03:01 +00:00
|
|
|
if (pSOrder == UCOL_PRIMIGNORABLE) // primary order in source is ignorable
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// The source's primary is ignorable, but the target's isn't. We treat ignorables
|
|
|
|
// as a secondary difference, so remember that we found one.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-12-08 22:03:01 +00:00
|
|
|
else if (pTOrder == UCOL_PRIMIGNORABLE)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// record differences - see the comment above.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
// Skip to the next target element, but don't fetch another source element.
|
|
|
|
gets = FALSE;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Neither of the orders is ignorable, and we already know that the primary
|
|
|
|
// orders are different because of the (pSOrder != pTOrder) test above.
|
|
|
|
// Record the difference and stop the comparison.
|
2000-12-14 01:11:11 +00:00
|
|
|
incctx_cleanUpContext(&sColl);
|
|
|
|
incctx_cleanUpContext(&tColl);
|
2000-11-29 00:16:15 +00:00
|
|
|
if (pSOrder < pTOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // else of if ( pSOrder != pTOrder )
|
|
|
|
// primary order is the same, but complete order is different. So there
|
|
|
|
// are no base elements at this point, only ignorables (Since the strings are
|
|
|
|
// normalized)
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
// a secondary or tertiary difference may still matter
|
2000-11-30 23:20:14 +00:00
|
|
|
uint32_t secSOrder = UCOL_SECONDARYORDER(sOrder);
|
|
|
|
uint32_t secTOrder = UCOL_SECONDARYORDER(tOrder);
|
2000-11-29 00:16:15 +00:00
|
|
|
|
|
|
|
if (secSOrder != secTOrder)
|
|
|
|
{
|
|
|
|
// there is a secondary difference
|
|
|
|
result = (secSOrder < secTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is SECONDARY)
|
|
|
|
checkSecTer = isFrenchSec; // We still want to track the French secondaries
|
|
|
|
//checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (checkTertiary)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// a tertiary difference may still matter
|
2000-11-30 23:20:14 +00:00
|
|
|
uint32_t terSOrder = UCOL_TERTIARYORDER(sOrder);
|
|
|
|
uint32_t terTOrder = UCOL_TERTIARYORDER(tOrder);
|
2000-11-29 00:16:15 +00:00
|
|
|
|
|
|
|
if (terSOrder != terTOrder)
|
|
|
|
{
|
|
|
|
// there is a tertiary difference
|
|
|
|
result = (terSOrder < terTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is TERTIARY)
|
|
|
|
checkTertiary = FALSE;
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
} // if (checkSecTer)
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
} // if ( pSOrder != pTOrder )
|
|
|
|
} // while()
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
if (sOrder != UCOL_NULLORDER)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// (tOrder must be CollationElementIterator::NULLORDER,
|
|
|
|
// since this point is only reached when sOrder or tOrder is NULLORDER.)
|
|
|
|
// The source string has more elements, but the target string hasn't.
|
|
|
|
do
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_PRIMARYORDER(sOrder) != UCOL_PRIMIGNORABLE)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// We found an additional non-ignorable base character in the source string.
|
|
|
|
// This is a primary difference, so the source is greater
|
2000-12-14 01:11:11 +00:00
|
|
|
incctx_cleanUpContext(&sColl);
|
|
|
|
incctx_cleanUpContext(&tColl);
|
2000-11-29 00:16:15 +00:00
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_SECONDARYORDER(sOrder) != UCOL_SECIGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// Additional secondary elements mean the source string is greater
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-12-07 07:22:55 +00:00
|
|
|
sOrder = ucol_getIncrementalCE(coll, &sColl, &status);
|
|
|
|
*(--sFSBEnd) = UCOL_SECONDARYORDER(sOrder);
|
|
|
|
if(sFSBEnd == sourceFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
//while ((sOrder = ucol_getIncrementalCE(coll, &sColl, &status)) != CollationElementIterator::NULLORDER);
|
|
|
|
while (sOrder != UCOL_NULLORDER);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
else if (tOrder != UCOL_NULLORDER)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// The target string has more elements, but the source string hasn't.
|
|
|
|
do
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_PRIMARYORDER(tOrder) != UCOL_PRIMIGNORABLE)
|
2000-11-29 00:16:15 +00:00
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the target string.
|
|
|
|
// This is a primary difference, so the source is less
|
2000-12-14 01:11:11 +00:00
|
|
|
incctx_cleanUpContext(&sColl);
|
|
|
|
incctx_cleanUpContext(&tColl);
|
2000-11-29 00:16:15 +00:00
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_SECONDARYORDER(tOrder) != UCOL_SECIGNORABLE)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Additional secondary elements in the target mean the source string is less
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
tOrder = ucol_getIncrementalCE(coll, &tColl, &status);
|
|
|
|
*(--tFSBEnd) = UCOL_SECONDARYORDER(tOrder);
|
2000-12-07 07:22:55 +00:00
|
|
|
if(tFSBEnd == targetFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
while ( tOrder != UCOL_NULLORDER);
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(bufferFrenchSec) {
|
|
|
|
while(sFSBEnd < sourceFrenchSec+UCOL_MAX_BUFFER && tFSBEnd < targetFrenchSec+UCOL_MAX_BUFFER) {
|
|
|
|
if(*sFSBEnd == *tFSBEnd) {
|
|
|
|
sFSBEnd++;
|
|
|
|
tFSBEnd++;
|
|
|
|
} else if(*sFSBEnd < *tFSBEnd) {
|
|
|
|
result = UCOL_LESS;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
break;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-06 00:53:48 +00:00
|
|
|
|
2000-11-20 19:17:17 +00:00
|
|
|
// For IDENTICAL comparisons, we use a bitwise character comparison
|
|
|
|
// as a tiebreaker if all else is equal
|
|
|
|
// NOTE: The java code compares result with 0, and
|
|
|
|
// puts the result of the string comparison directly into result
|
2000-12-05 01:03:35 +00:00
|
|
|
if (result == UCOL_EQUAL && strength == UCOL_IDENTICAL)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
|
|
|
UnicodeString sourceDecomp, targetDecomp;
|
|
|
|
|
|
|
|
int8_t comparison;
|
|
|
|
|
2000-12-14 01:11:11 +00:00
|
|
|
Normalizer::normalize(UnicodeString(sColl.stringP, sColl.len-sColl.stringP-1), ((RuleBasedCollator *)coll)->getDecomposition(),
|
2000-11-20 19:17:17 +00:00
|
|
|
0, sourceDecomp, status);
|
|
|
|
|
2000-12-14 01:11:11 +00:00
|
|
|
Normalizer::normalize(UnicodeString(tColl.stringP, tColl.len-tColl.stringP-1), ((RuleBasedCollator *)coll)->getDecomposition(),
|
2000-11-20 19:17:17 +00:00
|
|
|
0, targetDecomp, status);
|
|
|
|
|
|
|
|
comparison = sourceDecomp.compare(targetDecomp);
|
|
|
|
|
|
|
|
if (comparison < 0)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS;
|
|
|
|
}
|
|
|
|
else if (comparison == 0)
|
|
|
|
{
|
|
|
|
result = UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-14 01:11:11 +00:00
|
|
|
incctx_cleanUpContext(&sColl);
|
|
|
|
incctx_cleanUpContext(&tColl);
|
2000-11-20 19:17:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
/* This is the new function */
|
|
|
|
U_CAPI UCollationResult
|
|
|
|
ucol_strcoll( const UCollator *coll,
|
2000-11-20 19:17:17 +00:00
|
|
|
const UChar *source,
|
2000-11-30 23:20:14 +00:00
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-30 23:20:14 +00:00
|
|
|
Collator *cppColl = (Collator*)coll;
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
// check if source and target are valid strings
|
|
|
|
if (((source == 0) && (target == 0)) ||
|
|
|
|
((sourceLength == 0) && (targetLength == 0)))
|
|
|
|
{
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
UCollationResult result = UCOL_EQUAL;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
UChar normSource[UCOL_MAX_BUFFER], normTarget[UCOL_MAX_BUFFER];
|
2000-12-07 07:22:55 +00:00
|
|
|
UChar *normSourceP = normSource;
|
|
|
|
UChar *normTargetP = normTarget;
|
2000-11-30 23:20:14 +00:00
|
|
|
uint32_t normSourceLength = UCOL_MAX_BUFFER, normTargetLength = UCOL_MAX_BUFFER;
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
collIterate sColl, tColl;
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
if(cppColl->getDecomposition() == Normalizer::NO_OP) {
|
2000-12-13 01:26:07 +00:00
|
|
|
init_collIterate(source, sourceLength == -1 ? u_strlen(source) : sourceLength, &sColl, FALSE);
|
|
|
|
init_collIterate(target, targetLength == -1 ? u_strlen(target) : targetLength, &tColl, FALSE);
|
2000-12-07 07:22:55 +00:00
|
|
|
} else { /* TODO: This is bad behaved if we're working with small buffers */
|
|
|
|
/* We really need the normalization quick check here*/
|
2000-11-30 23:20:14 +00:00
|
|
|
UNormalizationMode normMode = ucol_getNormalization(coll);
|
|
|
|
normSourceLength = u_normalize(source, sourceLength, normMode, 0, normSource, normSourceLength, &status);
|
2000-12-07 07:22:55 +00:00
|
|
|
if(U_FAILURE(status)) { /* This would be buffer overflow */
|
|
|
|
normSourceP = (UChar *)uprv_malloc((normSourceLength+1)*sizeof(UChar));
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
normSourceLength = u_normalize(source, sourceLength, normMode, 0, normSourceP, normSourceLength+1, &status);
|
|
|
|
normTargetLength = u_normalize(target, targetLength, normMode, 0, normTargetP, normTargetLength, &status);
|
|
|
|
if(U_FAILURE(status)) { /* This would be buffer overflow */
|
|
|
|
normTargetP = (UChar *)uprv_malloc((normTargetLength+1)*sizeof(UChar));
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
normTargetLength = u_normalize(target, targetLength, normMode, 0, normTargetP, normTargetLength+1, &status);
|
|
|
|
}
|
|
|
|
Normalizer::EMode mode = cppColl->getDecomposition();
|
|
|
|
cppColl->setDecomposition(Normalizer::NO_OP);
|
|
|
|
UCollationResult result = ucol_strcoll(coll, normSourceP, normSourceLength, normTargetP, normTargetLength);
|
|
|
|
cppColl->setDecomposition(mode);
|
|
|
|
uprv_free(normSourceP);
|
|
|
|
if(normTargetP != normTarget) {
|
|
|
|
uprv_free(normTargetP);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
normTargetLength = u_normalize(target, targetLength, normMode, 0, normTarget, normTargetLength, &status);
|
2000-12-07 07:22:55 +00:00
|
|
|
if(U_FAILURE(status)) { /* This would be buffer overflow */
|
|
|
|
normTargetP = (UChar *)uprv_malloc((normTargetLength+1)*sizeof(UChar));
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
normTargetLength = u_normalize(target, targetLength, normMode, 0, normTargetP, normTargetLength+1, &status);
|
|
|
|
Normalizer::EMode mode = cppColl->getDecomposition();
|
|
|
|
cppColl->setDecomposition(Normalizer::NO_OP);
|
|
|
|
UCollationResult result = ucol_strcoll(coll, normSourceP, normSourceLength, normTargetP, normTargetLength);
|
|
|
|
cppColl->setDecomposition(mode);
|
|
|
|
uprv_free(normTargetP);
|
|
|
|
return result;
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
init_collIterate(normSource, normSourceLength, &sColl, TRUE);
|
|
|
|
init_collIterate(normTarget, normTargetLength, &tColl, TRUE);
|
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
if (U_FAILURE(status))
|
|
|
|
{
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-12-05 01:03:35 +00:00
|
|
|
UColAttributeValue strength = ucol_getAttribute(coll, UCOL_STRENGTH, &status);
|
2000-12-06 00:53:48 +00:00
|
|
|
uint32_t sOrder=UCOL_NULLORDER, tOrder=UCOL_NULLORDER;
|
2000-11-30 23:20:14 +00:00
|
|
|
uint32_t pSOrder, pTOrder;
|
|
|
|
UBool gets = TRUE, gett = TRUE;
|
2000-12-05 01:03:35 +00:00
|
|
|
UBool initialCheckSecTer = strength >= UCOL_SECONDARY;
|
2000-11-30 23:20:14 +00:00
|
|
|
UBool checkSecTer = initialCheckSecTer;
|
2001-01-05 00:47:25 +00:00
|
|
|
UBool checkTertiary = strength >= UCOL_TERTIARY;
|
|
|
|
UBool checkQuad = strength >= UCOL_QUATERNARY;
|
|
|
|
UBool isFrenchSec = (cppColl->getAttribute(UCOL_FRENCH_COLLATION, status) == UCOL_ON) && checkSecTer;
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(!isFrenchSec) {
|
2000-11-30 23:20:14 +00:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
// Get the next collation element in each of the strings, unless
|
|
|
|
// we've been requested to skip it.
|
|
|
|
if (gets)
|
|
|
|
{
|
|
|
|
UCOL_GETNEXTCE(sOrder, coll, sColl, status);
|
|
|
|
}
|
|
|
|
gets = TRUE;
|
|
|
|
|
|
|
|
if (gett)
|
|
|
|
{
|
|
|
|
UCOL_GETNEXTCE(tOrder, coll, tColl, status);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
gett = TRUE;
|
|
|
|
|
|
|
|
// If we've hit the end of one of the strings, jump out of the loop
|
|
|
|
if ((sOrder == UCOL_NULLORDER)||
|
|
|
|
(tOrder == UCOL_NULLORDER)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no difference at this position, we can skip to the
|
|
|
|
// next one.
|
|
|
|
if (sOrder == tOrder)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare primary differences first.
|
|
|
|
pSOrder = UCOL_PRIMARYORDER(sOrder);
|
|
|
|
pTOrder = UCOL_PRIMARYORDER(tOrder);
|
|
|
|
if (pSOrder != pTOrder)
|
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (sOrder == UCOL_IGNORABLE)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
// The entire source element is ignorable.
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (tOrder == UCOL_IGNORABLE)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
gets = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The source and target elements aren't ignorable, but it's still possible
|
|
|
|
// for the primary component of one of the elements to be ignorable....
|
2000-12-08 22:03:01 +00:00
|
|
|
if (pSOrder == UCOL_PRIMIGNORABLE) // primary order in source is ignorable
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
// The source's primary is ignorable, but the target's isn't. We treat ignorables
|
|
|
|
// as a secondary difference, so remember that we found one.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
result = UCOL_GREATER; // (strength is SECONDARY) - still need to check for tertiary or quad
|
|
|
|
checkSecTer = FALSE;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
}
|
2000-12-08 22:03:01 +00:00
|
|
|
else if (pTOrder == UCOL_PRIMIGNORABLE)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
// record differences - see the comment above.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
result = UCOL_LESS; // (strength is SECONDARY) - still need to check for tertiary or quad
|
|
|
|
checkSecTer = FALSE;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
// Skip to the next target element, but don't fetch another source element.
|
|
|
|
gets = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Neither of the orders is ignorable, and we already know that the primary
|
|
|
|
// orders are different because of the (pSOrder != pTOrder) test above.
|
|
|
|
// Record the difference and stop the comparison.
|
|
|
|
if (pSOrder < pTOrder)
|
|
|
|
{
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // else of if ( pSOrder != pTOrder )
|
|
|
|
// primary order is the same, but complete order is different. So there
|
|
|
|
// are no base elements at this point, only ignorables (Since the strings are
|
|
|
|
// normalized)
|
|
|
|
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
// a secondary or tertiary difference may still matter
|
|
|
|
uint32_t secSOrder = UCOL_SECONDARYORDER(sOrder);
|
|
|
|
uint32_t secTOrder = UCOL_SECONDARYORDER(tOrder);
|
|
|
|
|
|
|
|
if (secSOrder != secTOrder)
|
|
|
|
{
|
|
|
|
// there is a secondary difference
|
|
|
|
result = (secSOrder < secTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is SECONDARY)
|
2001-01-05 00:47:25 +00:00
|
|
|
checkSecTer = FALSE;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (checkTertiary)
|
|
|
|
{
|
|
|
|
// a tertiary difference may still matter
|
|
|
|
uint32_t terSOrder = UCOL_TERTIARYORDER(sOrder);
|
|
|
|
uint32_t terTOrder = UCOL_TERTIARYORDER(tOrder);
|
|
|
|
|
|
|
|
if (terSOrder != terTOrder)
|
|
|
|
{
|
|
|
|
// there is a tertiary difference
|
|
|
|
result = (terSOrder < terTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is TERTIARY)
|
|
|
|
checkTertiary = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if (checkSecTer)
|
|
|
|
|
|
|
|
} // if ( pSOrder != pTOrder )
|
|
|
|
} // while()
|
|
|
|
|
|
|
|
if (sOrder != UCOL_NULLORDER)
|
|
|
|
{
|
|
|
|
// (tOrder must be CollationElementIterator::NULLORDER,
|
|
|
|
// since this point is only reached when sOrder or tOrder is NULLORDER.)
|
|
|
|
// The source string has more elements, but the target string hasn't.
|
|
|
|
do
|
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_PRIMARYORDER(sOrder) != UCOL_PRIMIGNORABLE)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the source string.
|
|
|
|
// This is a primary difference, so the source is greater
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_SECONDARYORDER(sOrder) != UCOL_SECIGNORABLE)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
// Additional secondary elements mean the source string is greater
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
result = UCOL_GREATER; // (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
UCOL_GETNEXTCE(sOrder, coll, sColl, status);
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
//while ((sOrder = ucol_getNextCE(coll, &sColl, &status)) != CollationElementIterator::NULLORDER);
|
|
|
|
while (sOrder != UCOL_NULLORDER);
|
|
|
|
}
|
|
|
|
else if (tOrder != UCOL_NULLORDER)
|
|
|
|
{
|
|
|
|
// The target string has more elements, but the source string hasn't.
|
|
|
|
do
|
|
|
|
{
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_PRIMARYORDER(tOrder) != UCOL_PRIMIGNORABLE)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the target string.
|
|
|
|
// This is a primary difference, so the source is less
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
2000-12-08 22:03:01 +00:00
|
|
|
if (UCOL_SECONDARYORDER(tOrder) != UCOL_SECIGNORABLE)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
|
|
|
// Additional secondary elements in the target mean the source string is less
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
result = UCOL_LESS; // (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UCOL_GETNEXTCE(tOrder, coll, tColl, status);
|
|
|
|
}
|
|
|
|
while ( tOrder != UCOL_NULLORDER);
|
2001-01-05 00:47:25 +00:00
|
|
|
//while ((tOrder = ucol_getNextCE(coll, &tColl, &status)) != CollationElementIterator::NULLORDER);
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
} else { //French
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
// there is a bad situation with French when there is a different number of secondaries...
|
|
|
|
// If that situation arises (when one primary is ignorable with nonignorable secondary and the other primary is not
|
|
|
|
// ignorable
|
|
|
|
// TODO: if the buffer is not big enough, we should use sortkeys
|
|
|
|
UBool bufferFrenchSec = FALSE;
|
|
|
|
uint32_t sourceFrenchSec[UCOL_MAX_BUFFER], targetFrenchSec[UCOL_MAX_BUFFER];
|
|
|
|
uint32_t *sFSBEnd = sourceFrenchSec+UCOL_MAX_BUFFER;
|
|
|
|
uint32_t *tFSBEnd = targetFrenchSec+UCOL_MAX_BUFFER;
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
for(;;)
|
2000-11-30 23:20:14 +00:00
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
// Get the next collation element in each of the strings, unless
|
|
|
|
// we've been requested to skip it.
|
|
|
|
if (gets)
|
|
|
|
{
|
|
|
|
UCOL_GETNEXTCE(sOrder, coll, sColl, status);
|
|
|
|
*(--sFSBEnd) = UCOL_SECONDARYORDER(sOrder);
|
|
|
|
if(sFSBEnd == sourceFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return ucol_compareUsingSortKeys(coll, source, sourceLength, target, targetLength);
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
gets = TRUE;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if (gett)
|
|
|
|
{
|
|
|
|
UCOL_GETNEXTCE(tOrder, coll, tColl, status);
|
|
|
|
*(--tFSBEnd) = UCOL_SECONDARYORDER(tOrder);
|
|
|
|
if(tFSBEnd == targetFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return ucol_compareUsingSortKeys(coll, source, sourceLength, target, targetLength);
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
|
|
|
gett = TRUE;
|
|
|
|
|
|
|
|
// If we've hit the end of one of the strings, jump out of the loop
|
|
|
|
if ((sOrder == UCOL_NULLORDER)||
|
|
|
|
(tOrder == UCOL_NULLORDER)) {
|
|
|
|
break;
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
|
|
|
// If there's no difference at this position, we can skip to the
|
|
|
|
// next one.
|
|
|
|
if (sOrder == tOrder)
|
|
|
|
{
|
|
|
|
continue;
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
// Compare primary differences first.
|
|
|
|
pSOrder = UCOL_PRIMARYORDER(sOrder);
|
|
|
|
pTOrder = UCOL_PRIMARYORDER(tOrder);
|
|
|
|
if (pSOrder != pTOrder)
|
|
|
|
{
|
|
|
|
if (sOrder == UCOL_IGNORABLE)
|
|
|
|
{
|
|
|
|
// The entire source element is ignorable.
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
2000-12-08 00:52:46 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if (tOrder == UCOL_IGNORABLE)
|
|
|
|
{
|
|
|
|
gets = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
// The source and target elements aren't ignorable, but it's still possible
|
|
|
|
// for the primary component of one of the elements to be ignorable....
|
|
|
|
if (pSOrder == UCOL_PRIMIGNORABLE) // primary order in source is ignorable
|
|
|
|
{
|
|
|
|
// The source's primary is ignorable, but the target's isn't. We treat ignorables
|
|
|
|
// as a secondary difference, so remember that we found one.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
}
|
|
|
|
else if (pTOrder == UCOL_PRIMIGNORABLE)
|
|
|
|
{
|
|
|
|
// record differences - see the comment above.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
// Skip to the next target element, but don't fetch another source element.
|
|
|
|
gets = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Neither of the orders is ignorable, and we already know that the primary
|
|
|
|
// orders are different because of the (pSOrder != pTOrder) test above.
|
|
|
|
// Record the difference and stop the comparison.
|
|
|
|
if (pSOrder < pTOrder)
|
|
|
|
{
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
else
|
|
|
|
{ // else of if ( pSOrder != pTOrder )
|
|
|
|
// primary order is the same, but complete order is different. So there
|
|
|
|
// are no base elements at this point, only ignorables (Since the strings are
|
|
|
|
// normalized)
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
// a secondary or tertiary difference may still matter
|
|
|
|
uint32_t secSOrder = UCOL_SECONDARYORDER(sOrder);
|
|
|
|
uint32_t secTOrder = UCOL_SECONDARYORDER(tOrder);
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if (secSOrder != secTOrder)
|
|
|
|
{
|
|
|
|
// there is a secondary difference
|
|
|
|
result = (secSOrder < secTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is SECONDARY)
|
|
|
|
checkSecTer = isFrenchSec; // We still want to track the French secondaries
|
|
|
|
//checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (checkTertiary)
|
|
|
|
{
|
|
|
|
// a tertiary difference may still matter
|
|
|
|
uint32_t terSOrder = UCOL_TERTIARYORDER(sOrder);
|
|
|
|
uint32_t terTOrder = UCOL_TERTIARYORDER(tOrder);
|
|
|
|
|
|
|
|
if (terSOrder != terTOrder)
|
|
|
|
{
|
|
|
|
// there is a tertiary difference
|
|
|
|
result = (terSOrder < terTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is TERTIARY)
|
|
|
|
checkTertiary = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if (checkSecTer)
|
|
|
|
|
|
|
|
} // if ( pSOrder != pTOrder )
|
|
|
|
} // while()
|
|
|
|
|
|
|
|
if (sOrder != UCOL_NULLORDER)
|
|
|
|
{
|
|
|
|
// (tOrder must be CollationElementIterator::NULLORDER,
|
|
|
|
// since this point is only reached when sOrder or tOrder is NULLORDER.)
|
|
|
|
// The source string has more elements, but the target string hasn't.
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (UCOL_PRIMARYORDER(sOrder) != UCOL_PRIMIGNORABLE)
|
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the source string.
|
|
|
|
// This is a primary difference, so the source is greater
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UCOL_SECONDARYORDER(sOrder) != UCOL_SECIGNORABLE)
|
|
|
|
{
|
|
|
|
// Additional secondary elements mean the source string is greater
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UCOL_GETNEXTCE(sOrder, coll, sColl, status);
|
|
|
|
*(--sFSBEnd) = UCOL_SECONDARYORDER(sOrder);
|
|
|
|
if(sFSBEnd == sourceFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return ucol_compareUsingSortKeys(coll, source, sourceLength, target, targetLength);
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
//while ((sOrder = ucol_getNextCE(coll, &sColl, &status)) != CollationElementIterator::NULLORDER);
|
|
|
|
while (sOrder != UCOL_NULLORDER);
|
|
|
|
}
|
|
|
|
else if (tOrder != UCOL_NULLORDER)
|
|
|
|
{
|
|
|
|
// The target string has more elements, but the source string hasn't.
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (UCOL_PRIMARYORDER(tOrder) != UCOL_PRIMIGNORABLE)
|
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the target string.
|
|
|
|
// This is a primary difference, so the source is less
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UCOL_SECONDARYORDER(tOrder) != UCOL_SECIGNORABLE)
|
|
|
|
{
|
|
|
|
// Additional secondary elements in the target mean the source string is less
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UCOL_GETNEXTCE(tOrder, coll, tColl, status);
|
|
|
|
*(--tFSBEnd) = UCOL_SECONDARYORDER(tOrder);
|
|
|
|
if(tFSBEnd == targetFrenchSec) { /* overflowing the buffer, bail out */
|
|
|
|
return ucol_compareUsingSortKeys(coll, source, sourceLength, target, targetLength);
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
while ( tOrder != UCOL_NULLORDER);
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(bufferFrenchSec) {
|
|
|
|
while(sFSBEnd < sourceFrenchSec+UCOL_MAX_BUFFER && tFSBEnd < targetFrenchSec+UCOL_MAX_BUFFER) {
|
|
|
|
if(*sFSBEnd == *tFSBEnd) {
|
|
|
|
sFSBEnd++;
|
|
|
|
tFSBEnd++;
|
|
|
|
} else if(*sFSBEnd < *tFSBEnd) {
|
|
|
|
result = UCOL_LESS;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
// For IDENTICAL comparisons, we use a bitwise character comparison
|
|
|
|
// as a tiebreaker if all else is equal
|
|
|
|
// NOTE: The java code compares result with 0, and
|
|
|
|
// puts the result of the string comparison directly into result
|
|
|
|
if (result == UCOL_EQUAL && strength == UCOL_IDENTICAL)
|
|
|
|
{
|
|
|
|
UnicodeString sourceDecomp, targetDecomp;
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
int8_t comparison;
|
|
|
|
|
|
|
|
Normalizer::normalize(UnicodeString(source, sourceLength), ((RuleBasedCollator *)coll)->getDecomposition(),
|
|
|
|
0, sourceDecomp, status);
|
2000-12-08 00:52:46 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
Normalizer::normalize(UnicodeString(target, targetLength), ((RuleBasedCollator *)coll)->getDecomposition(),
|
|
|
|
0, targetDecomp, status);
|
|
|
|
|
|
|
|
comparison = sourceDecomp.compare(targetDecomp);
|
2000-12-12 01:15:30 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if (comparison < 0)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS;
|
|
|
|
}
|
|
|
|
else if (comparison == 0)
|
|
|
|
{
|
|
|
|
result = UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
}
|
2000-12-12 01:15:30 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
2000-12-08 00:52:46 +00:00
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
/* This is the original sort key function */
|
|
|
|
U_CAPI int32_t
|
|
|
|
ucol_getSortKeyEx(const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t *result,
|
|
|
|
int32_t resultLength)
|
|
|
|
{
|
|
|
|
int32_t count;
|
|
|
|
const uint8_t* bytes = NULL;
|
|
|
|
CollationKey key;
|
|
|
|
int32_t copyLen;
|
|
|
|
int32_t len = (sourceLength == -1 ? u_strlen(source)
|
|
|
|
: sourceLength);
|
|
|
|
// UnicodeString string((UChar*)source, len, len);
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
((RuleBasedCollator*)coll)->getCollationKeyEx(source, len, key, status);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
return 0;
|
2000-12-06 00:53:48 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
bytes = key.getByteArray(count);
|
|
|
|
|
|
|
|
copyLen = uprv_min(count, resultLength);
|
|
|
|
uprv_arrayCopy((const int8_t*)bytes, (int8_t*)result, copyLen);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2000-12-06 00:53:48 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t ucol_getSortKeySize(const UCollator *coll, collIterate *s, int32_t currentSize, UColAttributeValue strength, int32_t len) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-12-07 07:22:55 +00:00
|
|
|
UBool compareSec = (strength >= UCOL_SECONDARY);
|
|
|
|
UBool compareTer = (strength >= UCOL_TERTIARY);
|
|
|
|
UBool compareQuad = (strength >= UCOL_QUATERNARY);
|
|
|
|
UBool compareIdent = (strength == UCOL_IDENTICAL);
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t order = UCOL_NULLORDER;
|
2000-11-07 00:00:17 +00:00
|
|
|
uint16_t primary = 0;
|
|
|
|
uint8_t secondary = 0;
|
|
|
|
uint8_t tertiary = 0;
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2000-12-08 00:52:46 +00:00
|
|
|
|
|
|
|
for(;;) {
|
2001-01-05 00:47:25 +00:00
|
|
|
UCOL_GETNEXTCE(order, coll, *s, status);
|
|
|
|
if(order == UCOL_NULLORDER) {
|
|
|
|
break;
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
primary = ((order & UCOL_PRIMARYORDERMASK)>> UCOL_PRIMARYORDERSHIFT);
|
|
|
|
secondary = ((order & UCOL_SECONDARYORDERMASK)>> UCOL_SECONDARYORDERSHIFT);
|
|
|
|
tertiary = (order & UCOL_TERTIARYORDERMASK);
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(primary != UCOL_PRIMIGNORABLE) {
|
|
|
|
currentSize += 2;
|
|
|
|
if(compareSec) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
if(compareTer) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
} else if(secondary != 0) {
|
|
|
|
if(compareSec) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
if(compareTer) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
} else if(tertiary != 0) {
|
|
|
|
if(compareTer) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
}
|
2000-12-08 00:52:46 +00:00
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
|
|
|
|
if(compareIdent) {
|
2001-01-05 00:47:25 +00:00
|
|
|
currentSize += len*sizeof(UChar);
|
|
|
|
UChar *ident = s->string;
|
|
|
|
while(ident<s->len) {
|
|
|
|
if((*(ident) >> 8) + utf16fixup[*(ident) >> 11]<0x02) {
|
2000-12-08 00:52:46 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
currentSize++;
|
|
|
|
}
|
|
|
|
if((*(ident) & 0xFF)<0x02) {
|
|
|
|
currentSize++;
|
2000-12-08 00:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
return currentSize;
|
|
|
|
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
2001-01-04 00:45:41 +00:00
|
|
|
int32_t
|
2001-01-05 00:47:25 +00:00
|
|
|
ucol_calcSortKey(const UCollator *coll,
|
2001-01-04 00:45:41 +00:00
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t **result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UBool allocatePrimary)
|
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-01-04 00:45:41 +00:00
|
|
|
uint32_t i = 0; // general purpose counter
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
uint8_t second[UCOL_MAX_BUFFER], tert[UCOL_MAX_BUFFER];
|
|
|
|
|
|
|
|
uint8_t *primaries = *result, *secondaries = second, *tertiaries = tert;
|
|
|
|
|
|
|
|
if(primaries == NULL && allocatePrimary == TRUE) {
|
|
|
|
primaries = *result = (uint8_t *)uprv_malloc(2*UCOL_MAX_BUFFER);
|
|
|
|
resultLength = 2*UCOL_MAX_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t primSize = resultLength, secSize = UCOL_MAX_BUFFER, terSize = UCOL_MAX_BUFFER;
|
|
|
|
|
|
|
|
int32_t sortKeySize = 1; // it is always \0 terminated
|
|
|
|
|
|
|
|
UChar normBuffer[UCOL_NORMALIZATION_GROWTH*UCOL_MAX_BUFFER];
|
|
|
|
UChar *normSource = normBuffer;
|
|
|
|
int32_t normSourceLen = UCOL_NORMALIZATION_GROWTH*UCOL_MAX_BUFFER;
|
|
|
|
|
|
|
|
int32_t len = (sourceLength == -1 ? u_strlen(source) : sourceLength);
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
UColAttributeValue strength = ucol_getAttribute(coll, UCOL_STRENGTH, &status);
|
2001-01-04 00:45:41 +00:00
|
|
|
|
|
|
|
UBool compareSec = (strength >= UCOL_SECONDARY);
|
|
|
|
UBool compareTer = (strength >= UCOL_TERTIARY);
|
|
|
|
UBool compareQuad = (strength >= UCOL_QUATERNARY);
|
|
|
|
UBool compareIdent = (strength == UCOL_IDENTICAL);
|
|
|
|
|
|
|
|
sortKeySize += ((compareSec?1:0) + (compareTer?1:0) + (compareQuad?1:0) + (compareIdent?1:0));
|
|
|
|
|
|
|
|
collIterate s;
|
|
|
|
init_collIterate((UChar *)source, len, &s, FALSE);
|
|
|
|
|
|
|
|
// If we need to normalize, we'll do it all at once at the beggining!
|
2001-01-05 00:47:25 +00:00
|
|
|
UNormalizationMode normMode = ucol_getNormalization(coll);
|
|
|
|
if(normMode != UNORM_NONE) {
|
|
|
|
normSourceLen = u_normalize(source, sourceLength, normMode, 0, normSource, normSourceLen, &status);
|
2001-01-04 00:45:41 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
status=U_ZERO_ERROR;
|
|
|
|
normSource = (UChar *) uprv_malloc((normSourceLen+1)*sizeof(UChar));
|
2001-01-05 00:47:25 +00:00
|
|
|
normSourceLen = u_normalize(source, sourceLength, normMode, 0, normSource, (normSourceLen+1), &status);
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
normSource[normSourceLen] = 0;
|
|
|
|
s.string = normSource;
|
|
|
|
s.pos = normSource;
|
|
|
|
s.len = normSource+normSourceLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = s.len-s.pos;
|
|
|
|
|
|
|
|
if(resultLength == 0) {
|
2001-01-05 00:47:25 +00:00
|
|
|
return ucol_getSortKeySize(coll, &s, sortKeySize, strength, len);
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t minBufferSize = uprv_min(secSize, terSize);
|
|
|
|
|
|
|
|
uint8_t *primStart = primaries;
|
|
|
|
uint8_t *secStart = secondaries;
|
|
|
|
uint8_t *terStart = tertiaries;
|
|
|
|
|
|
|
|
uint32_t order = 0;
|
|
|
|
|
|
|
|
uint16_t primary = 0;
|
|
|
|
uint8_t secondary = 0;
|
|
|
|
uint8_t tertiary = 0;
|
|
|
|
|
|
|
|
UBool finished = FALSE;
|
|
|
|
UBool resultOverflow = FALSE;
|
|
|
|
|
|
|
|
int32_t prevBuffSize = 0;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
for(i=prevBuffSize; i<minBufferSize; ++i) {
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
UCOL_GETNEXTCE(order, coll, s, status);
|
2001-01-04 00:45:41 +00:00
|
|
|
|
|
|
|
if(order == UCOL_NULLORDER) {
|
|
|
|
finished = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
primary = ((order & UCOL_PRIMARYORDERMASK)>> UCOL_PRIMARYORDERSHIFT);
|
|
|
|
secondary = ((order & UCOL_SECONDARYORDERMASK)>> UCOL_SECONDARYORDERSHIFT);
|
|
|
|
tertiary = (order & UCOL_TERTIARYORDERMASK);
|
|
|
|
|
|
|
|
if(primary != UCOL_PRIMIGNORABLE) {
|
|
|
|
*(primaries++) = (primary>>8);
|
|
|
|
*(primaries++) = (primary&0xFF);
|
|
|
|
sortKeySize += 2;
|
|
|
|
if(compareSec) {
|
|
|
|
*(secondaries++) = secondary;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
if(compareTer) {
|
|
|
|
*(tertiaries++) = tertiary;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
} else if(secondary != UCOL_SECIGNORABLE) {
|
|
|
|
if(compareSec) {
|
|
|
|
*(secondaries++) = secondary;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
if(compareTer) {
|
|
|
|
*(tertiaries++) = tertiary;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
} else if(tertiary != UCOL_TERIGNORABLE) {
|
|
|
|
if(compareTer) {
|
|
|
|
*(tertiaries++) = tertiary;
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(sortKeySize>resultLength) {
|
|
|
|
if(allocatePrimary == FALSE) {
|
|
|
|
resultOverflow = TRUE;
|
2001-01-05 00:47:25 +00:00
|
|
|
sortKeySize = ucol_getSortKeySize(coll, &s, sortKeySize, strength, len);
|
2001-01-04 00:45:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
uint8_t *newStart;
|
|
|
|
newStart = (uint8_t *)uprv_realloc(primStart, 2*sortKeySize);
|
|
|
|
if(primStart == NULL) {
|
|
|
|
/*freak out*/
|
|
|
|
}
|
|
|
|
primaries=newStart+(primaries-primStart);
|
|
|
|
resultLength = 2*sortKeySize;
|
|
|
|
primStart = *result = newStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(finished) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
prevBuffSize = minBufferSize;
|
|
|
|
uint8_t *newStart;
|
|
|
|
|
|
|
|
if(secStart==second) {
|
|
|
|
newStart=(uint8_t*)uprv_malloc(2*secSize);
|
|
|
|
if(newStart==NULL) {
|
|
|
|
/*freak out;*/
|
|
|
|
}
|
|
|
|
uprv_memcpy(newStart, secStart, secondaries-secStart);
|
|
|
|
} else {
|
|
|
|
newStart=(uint8_t*)uprv_realloc(secStart, 2*secSize);
|
|
|
|
if(newStart==NULL) {
|
|
|
|
/*freak out;*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
secondaries=newStart+(secondaries-secStart);
|
|
|
|
secStart = newStart;
|
|
|
|
secSize*=2;
|
|
|
|
|
|
|
|
if(terStart==tert) {
|
|
|
|
newStart=(uint8_t*)uprv_malloc(2*terSize);
|
|
|
|
if(newStart==NULL) {
|
|
|
|
/*freak out;*/
|
|
|
|
}
|
|
|
|
uprv_memcpy(newStart, terStart, tertiaries-terStart);
|
|
|
|
} else {
|
|
|
|
newStart=(uint8_t*)uprv_realloc(terStart, 2*terSize);
|
|
|
|
if(newStart==NULL) {
|
|
|
|
/*freak out;*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tertiaries=newStart+(tertiaries-terStart);
|
|
|
|
terStart = newStart;
|
|
|
|
terSize*=2;
|
|
|
|
|
|
|
|
minBufferSize = uprv_min(secSize, terSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(compareSec) {
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
uint32_t secsize = secondaries-secStart;
|
2001-01-05 00:47:25 +00:00
|
|
|
if(ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &status) == UCOL_ON) { // do the reverse copy
|
2001-01-04 00:45:41 +00:00
|
|
|
for(i = 0; i<secsize; i++) {
|
|
|
|
*(primaries++) = *(secondaries-i-1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uprv_memcpy(primaries, secStart, secsize);
|
|
|
|
primaries += secsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(compareTer) {
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
uint32_t tersize = tertiaries - terStart;
|
|
|
|
uprv_memcpy(primaries, terStart, tersize);
|
|
|
|
primaries += tersize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(compareQuad) {
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(compareIdent) {
|
|
|
|
UChar *ident = s.string;
|
|
|
|
uint8_t idByte = 0;
|
|
|
|
sortKeySize += len * sizeof(UChar);
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
while(ident < s.len) {
|
|
|
|
idByte = (*(ident) >> 8) + utf16fixup[*(ident) >> 11];
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
if(sortKeySize < resultLength) {
|
|
|
|
*(primaries++) = 0x01;
|
|
|
|
sortKeySize++;
|
|
|
|
*(primaries++) = idByte + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(primaries++) = idByte;
|
|
|
|
}
|
|
|
|
idByte = (*(ident) & 0xFF);
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
if(sortKeySize < resultLength) {
|
|
|
|
*(primaries++) = 0x01;
|
|
|
|
sortKeySize++;
|
|
|
|
*(primaries++) = idByte + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(primaries++) = idByte;
|
|
|
|
}
|
|
|
|
|
|
|
|
ident++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while(ident < s.len) {
|
|
|
|
idByte = (*(ident) >> 8) + utf16fixup[*(ident) >> 11];
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
idByte = (*(ident) & 0xFF);
|
|
|
|
if(idByte < 0x02) {
|
|
|
|
sortKeySize++;
|
|
|
|
}
|
|
|
|
ident++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*(primaries++) = '\0';
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if(terStart != tert) {
|
|
|
|
uprv_free(terStart);
|
|
|
|
}
|
|
|
|
if(secStart != second) {
|
|
|
|
uprv_free(secStart);
|
|
|
|
}
|
|
|
|
if(normSource != normBuffer) {
|
|
|
|
uprv_free(normSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sortKeySize;
|
|
|
|
}
|
|
|
|
|
2000-12-12 01:15:30 +00:00
|
|
|
U_CFUNC uint8_t *ucol_getSortKeyWithAllocation(const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
int32_t *resultLen) {
|
|
|
|
uint8_t *result = NULL;
|
|
|
|
*resultLen = ucol_calcSortKey(coll, source, sourceLength, &result, 0, TRUE);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
|
|
|
ucol_getSortKey(const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t *result,
|
|
|
|
int32_t resultLength)
|
|
|
|
{
|
|
|
|
return ucol_calcSortKey(coll, source, sourceLength, &result, resultLength, FALSE);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_keyHashCode( const uint8_t* key,
|
|
|
|
int32_t length)
|
|
|
|
{
|
|
|
|
CollationKey newKey(key, length);
|
|
|
|
return newKey.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
UCollationElements*
|
|
|
|
ucol_openElements( const UCollator *coll,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
int32_t len = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
|
|
|
|
CollationElementIterator *iter = 0;
|
|
|
|
iter = ((RuleBasedCollator*)coll)->createCollationElementIterator(src);
|
|
|
|
if(iter == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UCollationElements*) iter;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_closeElements(UCollationElements *elems)
|
|
|
|
{
|
|
|
|
delete (CollationElementIterator*)elems;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_reset(UCollationElements *elems)
|
|
|
|
{
|
|
|
|
((CollationElementIterator*)elems)->reset();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_next( UCollationElements *elems,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return UCOL_NULLORDER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return ((CollationElementIterator*)elems)->next(*status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_previous( UCollationElements *elems,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return UCOL_NULLORDER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return ((CollationElementIterator*)elems)->previous(*status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getMaxExpansion( const UCollationElements *elems,
|
|
|
|
int32_t order)
|
|
|
|
{
|
|
|
|
return ((CollationElementIterator*)elems)->getMaxExpansion(order);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_setText(UCollationElements *elems,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t len = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
|
|
|
|
((CollationElementIterator*)elems)->setText(src, *status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getOffset(const UCollationElements *elems)
|
|
|
|
{
|
|
|
|
return ((CollationElementIterator*)elems)->getOffset();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_setOffset( UCollationElements *elems,
|
|
|
|
UTextOffset offset,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
((CollationElementIterator*)elems)->setOffset(offset, *status);
|
|
|
|
}
|
2000-05-15 19:48:26 +00:00
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
ucol_getVersion(const UCollator* coll,
|
|
|
|
UVersionInfo versionInfo)
|
|
|
|
{
|
|
|
|
((Collator*)coll)->getVersion(versionInfo);
|
|
|
|
}
|
2000-05-18 21:25:51 +00:00
|
|
|
|
|
|
|
U_CAPI uint8_t *
|
|
|
|
ucol_cloneRuleData(UCollator *coll, int32_t *length, UErrorCode *status)
|
|
|
|
{
|
|
|
|
return ((RuleBasedCollator*)coll)->cloneRuleData(*length,*status);
|
|
|
|
}
|
2000-11-17 23:32:32 +00:00
|
|
|
|
2000-11-20 06:40:54 +00:00
|
|
|
U_CAPI void ucol_setAttribute(UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status) {
|
2000-11-22 00:04:03 +00:00
|
|
|
((RuleBasedCollator *)coll)->setAttribute(attr, value, *status);
|
2000-11-17 23:32:32 +00:00
|
|
|
}
|
|
|
|
|
2000-11-20 06:40:54 +00:00
|
|
|
U_CAPI UColAttributeValue ucol_getAttribute(const UCollator *coll, UColAttribute attr, UErrorCode *status) {
|
2000-11-22 00:04:03 +00:00
|
|
|
return (((RuleBasedCollator *)coll)->getAttribute(attr, *status));
|
2000-11-17 23:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollator *ucol_safeClone(const UCollator *coll, void *stackBuffer, uint32_t bufferSize, UErrorCode *status) {
|
2000-12-07 07:22:55 +00:00
|
|
|
return (UCollator *)(((RuleBasedCollator *)coll)->safeClone());
|
2000-11-17 23:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen) {
|
|
|
|
return 0;
|
|
|
|
}
|