1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2001-03-17 00:46:46 +00:00
|
|
|
* Copyright (C) 1996-2001, International Business Machines
|
1999-11-23 01:30:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
2001-03-17 00:46:46 +00:00
|
|
|
* file name: ucol.cpp
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
2001-02-20 00:26:50 +00:00
|
|
|
* Modification history
|
|
|
|
* Date Name Comments
|
2001-03-17 00:46:46 +00:00
|
|
|
* 1996-1999 various members of ICU team maintained C API for collation framework
|
2001-04-23 01:53:49 +00:00
|
|
|
* 02/16/2001 synwee Added internal method getPrevSpecialCE
|
2001-03-02 01:14:03 +00:00
|
|
|
* 03/01/2001 synwee Added maxexpansion functionality.
|
2001-03-17 00:46:46 +00:00
|
|
|
* 03/16/2001 weiv Collation framework is rewritten in C and made UCA compliant
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2001-03-08 17:40:42 +00:00
|
|
|
|
|
|
|
#include "ucol_bld.h"
|
|
|
|
#include "ucol_imp.h"
|
|
|
|
#include "ucol_tok.h"
|
|
|
|
#include "ucol_elm.h"
|
2001-05-18 19:49:04 +00:00
|
|
|
#include "bocsu.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"
|
2001-01-04 00:45:41 +00:00
|
|
|
#include "unicode/unorm.h"
|
2001-02-21 17:45:06 +00:00
|
|
|
#include "unicode/udata.h"
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cpputils.h"
|
2000-12-07 07:22:55 +00:00
|
|
|
#include "cstring.h"
|
2001-02-21 17:45:06 +00:00
|
|
|
#include "ucmp32.h"
|
|
|
|
#include "umutex.h"
|
2001-02-26 10:28:56 +00:00
|
|
|
#include "uhash.h"
|
2000-12-06 00:53:48 +00:00
|
|
|
|
2001-06-01 22:08:06 +00:00
|
|
|
#ifdef UCOL_DEBUG
|
2000-11-30 23:20:14 +00:00
|
|
|
#include <stdio.h>
|
2001-06-01 22:08:06 +00:00
|
|
|
#endif
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/* added by synwee for trie manipulation*/
|
|
|
|
#define STAGE_1_SHIFT_ 10
|
|
|
|
#define STAGE_2_SHIFT_ 4
|
|
|
|
#define STAGE_2_MASK_AFTER_SHIFT_ 0x3F
|
|
|
|
#define STAGE_3_MASK_ 0xF
|
|
|
|
#define LAST_BYTE_MASK_ 0xFF
|
|
|
|
#define SECOND_LAST_BYTE_SHIFT_ 8
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
#define ZERO_CC_LIMIT_ 0xC0
|
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
static UCollator* UCA = NULL;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
extern "C" UBool checkFCD(const UChar*, int32_t, UErrorCode*);
|
|
|
|
|
2001-02-12 20:44:05 +00:00
|
|
|
/* Fixup table a la Markus */
|
|
|
|
/* see http://www.ibm.com/software/developer/library/utf16.html for further explanation */
|
2001-05-21 22:54:51 +00:00
|
|
|
static const UChar utf16Fixup[32]={
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0x2000, 0xf800, 0xf800, 0xf800, 0xf800
|
2001-02-12 20:44:05 +00:00
|
|
|
};
|
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
static UBool U_CALLCONV
|
2001-06-01 22:08:06 +00:00
|
|
|
isAcceptableUCA(void * /*context*/,
|
|
|
|
const char * /*type*/, const char * /*name*/,
|
2001-01-04 00:45:41 +00:00
|
|
|
const UDataInfo *pInfo){
|
2001-02-28 19:01:23 +00:00
|
|
|
/* context, type & name are intentionally not used */
|
2001-01-04 00:45:41 +00:00
|
|
|
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-04-06 23:37:48 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
/* added for Han implicit CE */
|
|
|
|
static const uint32_t IMPLICIT_HAN_START_ = 0x3400;
|
|
|
|
static const uint32_t IMPLICIT_HAN_LIMIT_ = 0xA000;
|
|
|
|
static const uint32_t IMPLICIT_SUPPLEMENTARY_COUNT_ = 0x100000;
|
|
|
|
static const uint32_t IMPLICIT_BYTES_TO_AVOID_ = 3;
|
|
|
|
static const uint32_t IMPLICIT_OTHER_COUNT_ = 256 - IMPLICIT_BYTES_TO_AVOID_;
|
|
|
|
static const uint32_t IMPLICIT_LAST_COUNT_ = IMPLICIT_OTHER_COUNT_ / 2;
|
2001-05-11 01:13:08 +00:00
|
|
|
static const uint32_t IMPLICIT_LAST_COUNT2_ =
|
|
|
|
(IMPLICIT_SUPPLEMENTARY_COUNT_ - 1) /
|
2001-04-20 22:29:53 +00:00
|
|
|
(IMPLICIT_OTHER_COUNT_ * IMPLICIT_OTHER_COUNT_) + 1;
|
2001-05-11 01:13:08 +00:00
|
|
|
static const uint32_t IMPLICIT_HAN_SHIFT_ = IMPLICIT_LAST_COUNT_ *
|
2001-04-20 22:29:53 +00:00
|
|
|
IMPLICIT_OTHER_COUNT_ - IMPLICIT_HAN_START_;
|
2001-05-11 01:13:08 +00:00
|
|
|
static const uint32_t IMPLICIT_BOUNDARY_ = 2 * IMPLICIT_OTHER_COUNT_ *
|
2001-04-20 22:29:53 +00:00
|
|
|
IMPLICIT_LAST_COUNT_ + IMPLICIT_HAN_START_;
|
2001-05-11 01:13:08 +00:00
|
|
|
static const uint32_t IMPLICIT_LAST2_MULTIPLIER_ = IMPLICIT_OTHER_COUNT_ /
|
2001-04-20 22:29:53 +00:00
|
|
|
IMPLICIT_LAST_COUNT2_;
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
inline void IInit_collIterate(const UCollator *collator, const UChar *sourceString,
|
|
|
|
int32_t sourceLen, collIterate *s) {
|
|
|
|
(s)->string = (s)->pos = (UChar *)(sourceString);
|
2001-05-10 17:49:24 +00:00
|
|
|
(s)->origFlags = 0;
|
2001-04-06 23:37:48 +00:00
|
|
|
(s)->flags = 0;
|
|
|
|
if (sourceLen >= 0) {
|
|
|
|
s->flags |= UCOL_ITER_HASLEN;
|
2001-04-26 01:15:34 +00:00
|
|
|
(s)->endp = (UChar *)sourceString+sourceLen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* change to enable easier checking for end of string for fcdpositon */
|
|
|
|
(s)->endp = NULL;
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
(s)->CEpos = (s)->toReturn = (s)->CEs;
|
|
|
|
(s)->writableBuffer = (s)->stackWritableBuffer;
|
|
|
|
(s)->writableBufSize = UCOL_WRITABLE_BUFFER_SIZE;
|
|
|
|
(s)->coll = (collator);
|
|
|
|
(s)->fcdPosition = 0;
|
2001-04-12 19:59:28 +00:00
|
|
|
if(collator->normalizationMode == UCOL_ON) {
|
|
|
|
(s)->flags |= UCOL_ITER_NORM; }
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void init_collIterate(const UCollator *collator, const UChar *sourceString,
|
|
|
|
int32_t sourceLen, collIterate *s){
|
2001-04-12 19:59:28 +00:00
|
|
|
/* Out-of-line version for use from other files. */
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(collator, sourceString, sourceLen, s);
|
|
|
|
}
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
/**
|
2001-04-18 01:34:26 +00:00
|
|
|
* Backup the state of the collIterate struct data
|
|
|
|
* @param data collIterate to backup
|
2001-04-23 01:53:49 +00:00
|
|
|
* @param backup storage
|
2001-04-18 01:34:26 +00:00
|
|
|
*/
|
2001-04-23 01:53:49 +00:00
|
|
|
inline void backupState(const collIterate *data, collIterateState *backup)
|
2001-04-18 01:34:26 +00:00
|
|
|
{
|
2001-04-23 01:53:49 +00:00
|
|
|
backup->fcdPosition = data->fcdPosition;
|
|
|
|
backup->flags = data->flags;
|
|
|
|
backup->origFlags = data->origFlags;
|
|
|
|
backup->pos = data->pos;
|
2001-05-02 01:36:29 +00:00
|
|
|
backup->bufferaddress = data->writableBuffer;
|
2001-04-20 22:29:53 +00:00
|
|
|
backup->buffersize = data->writableBufSize;
|
2001-04-18 01:34:26 +00:00
|
|
|
}
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
/**
|
2001-04-18 01:34:26 +00:00
|
|
|
* Loads the state into the collIterate struct data
|
|
|
|
* @param data collIterate to backup
|
2001-04-23 01:53:49 +00:00
|
|
|
* @param backup storage
|
2001-05-11 01:13:08 +00:00
|
|
|
* @param forwards boolean to indicate if forwards iteration is used,
|
2001-05-02 01:36:29 +00:00
|
|
|
* false indicates backwards iteration
|
2001-04-18 01:34:26 +00:00
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
inline void loadState(collIterate *data, const collIterateState *backup,
|
2001-05-02 01:36:29 +00:00
|
|
|
UBool forwards)
|
2001-04-18 01:34:26 +00:00
|
|
|
{
|
|
|
|
data->flags = backup->flags;
|
|
|
|
data->origFlags = backup->origFlags;
|
|
|
|
data->pos = backup->pos;
|
2001-05-11 01:13:08 +00:00
|
|
|
if ((data->flags & UCOL_ITER_INNORMBUF) &&
|
2001-05-02 01:36:29 +00:00
|
|
|
data->writableBuffer != backup->bufferaddress) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
|
|
|
this is when a new buffer has been reallocated and we'll have to
|
2001-04-20 22:29:53 +00:00
|
|
|
calculate the new position.
|
|
|
|
note the new buffer has to contain the contents of the old buffer.
|
|
|
|
*/
|
2001-05-02 01:36:29 +00:00
|
|
|
if (forwards) {
|
2001-05-11 01:13:08 +00:00
|
|
|
data->pos = data->writableBuffer +
|
2001-05-02 01:36:29 +00:00
|
|
|
(data->pos - backup->bufferaddress);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* backwards direction */
|
2001-05-11 01:13:08 +00:00
|
|
|
uint32_t temp = backup->buffersize -
|
2001-05-02 01:36:29 +00:00
|
|
|
(data->pos - backup->bufferaddress);
|
|
|
|
data->pos = data->writableBuffer + (data->writableBufSize - temp);
|
|
|
|
}
|
2001-04-25 23:28:55 +00:00
|
|
|
}
|
|
|
|
if ((data->flags & UCOL_ITER_INNORMBUF) == 0) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-25 23:28:55 +00:00
|
|
|
this is alittle tricky.
|
2001-05-11 01:13:08 +00:00
|
|
|
if we are initially not in the normalization buffer, even if we
|
2001-04-25 23:28:55 +00:00
|
|
|
normalize in the later stage, the data in the buffer will be
|
|
|
|
ignored, since we skip back up to the data string.
|
|
|
|
however if we are already in the normalization buffer, any
|
2001-05-11 01:13:08 +00:00
|
|
|
further normalization will pull data into the normalization
|
2001-04-25 23:28:55 +00:00
|
|
|
buffer and modify the fcdPosition.
|
2001-05-11 01:13:08 +00:00
|
|
|
since we are keeping the data in the buffer for use, the
|
2001-04-25 23:28:55 +00:00
|
|
|
fcdPosition can not be reverted back.
|
|
|
|
arrgghh....
|
|
|
|
*/
|
|
|
|
data->fcdPosition = backup->fcdPosition;
|
|
|
|
}
|
2001-04-18 01:34:26 +00:00
|
|
|
}
|
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* collIter_eos()
|
|
|
|
* Checks for a collIterate being positioned at the end of
|
|
|
|
* its source string.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
inline UBool collIter_eos(collIterate *s) {
|
|
|
|
if ((s->flags & UCOL_ITER_HASLEN) == 0 && *s->pos != 0) {
|
|
|
|
// Null terminated string, but not at null, so not at end.
|
|
|
|
// Whether in main or normalization buffer doesn't matter.
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// String with length. Can't be in normalization buffer, which is always
|
|
|
|
// null termintated.
|
|
|
|
if (s->flags & UCOL_ITER_HASLEN) {
|
|
|
|
return (s->pos == s->endp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are at a null termination, could be either normalization buffer or main string.
|
|
|
|
if ((s->flags & UCOL_ITER_INNORMBUF) == 0) {
|
|
|
|
// At null at end of main string.
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At null at end of normalization buffer. Need to check whether there there are
|
|
|
|
// any characters left in the main buffer.
|
|
|
|
|
|
|
|
if ((s->origFlags & UCOL_ITER_HASLEN) == 0) {
|
|
|
|
// Null terminated main string. fcdPosition is the 'return' position into main buf.
|
|
|
|
return (*s->fcdPosition == 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Main string with an end pointer.
|
|
|
|
return s->fcdPosition == s->endp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
/**
|
|
|
|
* Checks and free writable buffer if it is not the original stack buffer
|
|
|
|
* in collIterate. This function does not reassign the writable buffer.
|
|
|
|
* @param data collIterate struct to determine and free the writable buffer
|
|
|
|
*/
|
|
|
|
inline void freeHeapWritableBuffer(collIterate *data)
|
|
|
|
{
|
|
|
|
if (data->writableBuffer != data->stackWritableBuffer) {
|
|
|
|
uprv_free(data->writableBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Following are the open/close functions */
|
|
|
|
/* */
|
|
|
|
/****************************************************************************/
|
|
|
|
U_CAPI UCollator*
|
|
|
|
ucol_open( const char *loc,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-05 01:40:36 +00:00
|
|
|
ucol_initUCA(status);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* New version */
|
|
|
|
if(U_FAILURE(*status)) return 0;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
UCollator *result = NULL;
|
|
|
|
UResourceBundle *b = ures_open(NULL, loc, status);
|
2001-02-09 01:04:08 +00:00
|
|
|
/* first take on tailoring version: */
|
|
|
|
/* get CollationElements -> Version */
|
2001-01-16 00:28:40 +00:00
|
|
|
UResourceBundle *binary = ures_getByKey(b, "%%CollationNew", NULL, status);
|
2001-02-26 23:52:44 +00:00
|
|
|
|
2001-02-10 02:42:54 +00:00
|
|
|
if(*status == U_MISSING_RESOURCE_ERROR) { /* if we don't find tailoring, we'll fallback to UCA */
|
2001-01-16 00:28:40 +00:00
|
|
|
*status = U_USING_DEFAULT_ERROR;
|
2001-04-23 01:53:49 +00:00
|
|
|
result = ucol_initCollator(UCA->image, result, status);
|
2001-02-27 21:01:11 +00:00
|
|
|
/*result = UCA;*/
|
|
|
|
result->hasRealData = FALSE;
|
2001-01-16 00:28:40 +00:00
|
|
|
} 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);
|
2001-04-05 01:40:36 +00:00
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
goto clean;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-30 00:23:46 +00:00
|
|
|
if((uint32_t)len > (paddedsize(sizeof(UCATableHeader)) + paddedsize(sizeof(UColOptionSet)))) {
|
2001-04-23 01:53:49 +00:00
|
|
|
result = ucol_initCollator((const UCATableHeader *)inData, result, status);
|
2001-04-05 01:40:36 +00:00
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
goto clean;
|
|
|
|
}
|
2001-02-26 10:28:56 +00:00
|
|
|
result->hasRealData = TRUE;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
result = ucol_initCollator(UCA->image, result, status);
|
2001-03-30 00:23:46 +00:00
|
|
|
ucol_setOptionsFromHeader(result, (UColOptionSet *)(inData+((const UCATableHeader *)inData)->options), status);
|
2001-04-05 01:40:36 +00:00
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
goto clean;
|
|
|
|
}
|
2001-02-26 10:28:56 +00:00
|
|
|
result->hasRealData = FALSE;
|
|
|
|
}
|
|
|
|
} else { /* There is another error, and we're just gonna clean up */
|
2001-04-05 01:40:36 +00:00
|
|
|
clean:
|
2001-02-26 10:28:56 +00:00
|
|
|
ures_close(b);
|
2001-04-05 01:40:36 +00:00
|
|
|
ures_close(binary);
|
2001-02-26 10:28:56 +00:00
|
|
|
return NULL;
|
2001-02-10 02:42:54 +00:00
|
|
|
}
|
2001-02-21 21:43:17 +00:00
|
|
|
|
2001-02-27 21:01:11 +00:00
|
|
|
result->rb = b;
|
2001-01-16 00:28:40 +00:00
|
|
|
ures_close(binary);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-14 00:22:56 +00:00
|
|
|
U_CAPI UCollator * U_EXPORT2
|
|
|
|
ucol_openVersion(const char *loc,
|
|
|
|
UVersionInfo version,
|
|
|
|
UErrorCode *status) {
|
|
|
|
UCollator *collator;
|
|
|
|
UVersionInfo info;
|
|
|
|
|
|
|
|
collator=ucol_open(loc, status);
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
ucol_getVersion(collator, info);
|
|
|
|
if(0!=uprv_memcmp(version, info, sizeof(UVersionInfo))) {
|
|
|
|
ucol_close(collator);
|
|
|
|
*status=U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return collator;
|
|
|
|
}
|
2001-02-21 21:43:17 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
U_CAPI void
|
|
|
|
ucol_close(UCollator *coll)
|
|
|
|
{
|
|
|
|
/* 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! */
|
2001-02-22 16:32:40 +00:00
|
|
|
if(coll->freeOnClose == FALSE){
|
2001-04-23 01:53:49 +00:00
|
|
|
return; /* for safeClone, if freeOnClose is FALSE,
|
2001-02-22 16:32:40 +00:00
|
|
|
don't free the other instance data */
|
|
|
|
}
|
2001-03-30 00:23:46 +00:00
|
|
|
if(coll->freeOptionsOnClose != FALSE) {
|
|
|
|
if(coll->options != NULL) {
|
|
|
|
uprv_free(coll->options);
|
|
|
|
}
|
|
|
|
}
|
2001-02-27 21:01:11 +00:00
|
|
|
if(coll->mapping != NULL) {
|
|
|
|
ucmp32_close(coll->mapping);
|
|
|
|
}
|
2001-03-03 09:27:42 +00:00
|
|
|
if(coll->rules != NULL && coll->freeRulesOnClose) {
|
|
|
|
uprv_free((UChar *)coll->rules);
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
2001-02-27 07:48:00 +00:00
|
|
|
if(coll->rb != NULL) { /* pointing to read-only memory */
|
2001-01-16 00:28:40 +00:00
|
|
|
ures_close(coll->rb);
|
2001-02-27 07:48:00 +00:00
|
|
|
} else if(coll->hasRealData == TRUE) {
|
|
|
|
uprv_free((UCATableHeader *)coll->image);
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
2001-02-22 16:32:40 +00:00
|
|
|
uprv_free(coll);
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
U_CAPI UCollator*
|
|
|
|
ucol_openRules( const UChar *rules,
|
|
|
|
int32_t rulesLength,
|
|
|
|
UNormalizationMode mode,
|
|
|
|
UCollationStrength strength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-06-06 20:18:38 +00:00
|
|
|
uint32_t listLen = 0;
|
2001-02-05 05:36:12 +00:00
|
|
|
UColTokenParser src;
|
2001-04-24 23:32:40 +00:00
|
|
|
UColAttributeValue norm;
|
|
|
|
|
|
|
|
switch(mode) {
|
|
|
|
case UNORM_NONE:
|
|
|
|
norm = UCOL_OFF;
|
|
|
|
break;
|
|
|
|
case UNORM_NFD:
|
|
|
|
norm = UCOL_ON;
|
|
|
|
break;
|
2001-05-11 01:13:08 +00:00
|
|
|
case UCOL_DEFAULT_NORMALIZATION:
|
2001-05-02 05:09:40 +00:00
|
|
|
case UCOL_DEFAULT:
|
2001-04-24 23:32:40 +00:00
|
|
|
norm = UCOL_DEFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-01-29 22:09:24 +00:00
|
|
|
|
|
|
|
ucol_initUCA(status);
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
|
|
|
|
2001-06-06 20:18:38 +00:00
|
|
|
ucol_tok_initTokenList(&src, rules, rulesLength, UCA, status);
|
2001-01-31 20:17:12 +00:00
|
|
|
listLen = ucol_tok_assembleTokenList(&src, status);
|
2001-06-06 20:18:38 +00:00
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
2001-03-06 07:44:37 +00:00
|
|
|
/* if status is U_ILLEGAL_ARGUMENT_ERROR, src->current points at the offending option */
|
|
|
|
/* if status is U_INVALID_FORMAT_ERROR, src->current points after the problematic part of the rules */
|
|
|
|
/* so something might be done here... or on lower level */
|
|
|
|
#ifdef UCOL_DEBUG
|
|
|
|
if(*status == U_ILLEGAL_ARGUMENT_ERROR) {
|
|
|
|
fprintf(stderr, "bad option starting at offset %i\n", src.current-src.source);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid rule just before offset %i\n", src.current-src.source);
|
|
|
|
}
|
|
|
|
#endif
|
2001-02-28 21:50:23 +00:00
|
|
|
ucol_tok_closeTokenList(&src);
|
2001-01-29 22:34:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-26 10:28:56 +00:00
|
|
|
UCollator *result = NULL;
|
|
|
|
UCATableHeader *table = NULL;
|
|
|
|
|
2001-03-07 19:43:06 +00:00
|
|
|
if(src.resultLen > 0) { /* we have a set of rules, let's make something of it */
|
2001-02-28 19:01:23 +00:00
|
|
|
table = ucol_assembleTailoringTable(&src, status);
|
2001-04-23 01:53:49 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
result = ucol_initCollator(table,0,status);
|
|
|
|
result->hasRealData = TRUE;
|
|
|
|
}
|
2001-02-26 10:28:56 +00:00
|
|
|
} else { /* no rules, but no error either */
|
2001-06-07 21:28:56 +00:00
|
|
|
// must be only options
|
|
|
|
// We will init the collator from UCA
|
2001-02-26 10:28:56 +00:00
|
|
|
result = ucol_initCollator(UCA->image,0,status);
|
2001-06-07 21:28:56 +00:00
|
|
|
// And set only the options
|
|
|
|
UColOptionSet *opts = (UColOptionSet *)uprv_malloc(sizeof(UColOptionSet));
|
|
|
|
uprv_memcpy(opts, src.opts, sizeof(UColOptionSet));
|
|
|
|
ucol_setOptionsFromHeader(result, opts, status);
|
2001-03-30 00:23:46 +00:00
|
|
|
result->freeOptionsOnClose = TRUE;
|
2001-02-26 10:28:56 +00:00
|
|
|
result->hasRealData = FALSE;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-31 07:20:56 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
2001-03-22 18:45:31 +00:00
|
|
|
result->dataInfo.dataVersion[0] = UCOL_BUILDER_VERSION;
|
2001-01-31 07:20:56 +00:00
|
|
|
result->rules = (UChar *)uprv_malloc((u_strlen(rules)+1)*sizeof(UChar));
|
2001-03-03 09:27:42 +00:00
|
|
|
u_strcpy((UChar *)result->rules, rules);
|
|
|
|
result->freeRulesOnClose = TRUE;
|
2001-01-31 07:20:56 +00:00
|
|
|
result->rb = 0;
|
2001-04-24 23:32:40 +00:00
|
|
|
ucol_setAttribute(result, UCOL_STRENGTH, strength, status);
|
|
|
|
ucol_setAttribute(result, UCOL_NORMALIZATION_MODE, norm, status);
|
2001-01-31 07:20:56 +00:00
|
|
|
} else {
|
|
|
|
if(table != NULL) {
|
|
|
|
uprv_free(table);
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
|
|
|
if(result != NULL) {
|
2001-01-31 07:20:56 +00:00
|
|
|
ucol_close(result);
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
result = NULL;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
2001-06-06 20:18:38 +00:00
|
|
|
|
2001-02-28 21:50:23 +00:00
|
|
|
ucol_tok_closeTokenList(&src);
|
2001-02-27 21:01:11 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This one is currently used by genrb & tests. After constructing from rules (tailoring),*/
|
|
|
|
/* you should be able to get the binary chunk to write out... Doesn't look very full now */
|
|
|
|
U_CAPI uint8_t *
|
|
|
|
ucol_cloneRuleData(UCollator *coll, int32_t *length, UErrorCode *status)
|
|
|
|
{
|
2001-02-26 10:28:56 +00:00
|
|
|
uint8_t *result = NULL;
|
2001-05-28 20:57:59 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-26 10:28:56 +00:00
|
|
|
if(coll->hasRealData == TRUE) {
|
|
|
|
*length = coll->image->size;
|
|
|
|
result = (uint8_t *)uprv_malloc(*length);
|
|
|
|
uprv_memcpy(result, coll->image, *length);
|
|
|
|
} else {
|
2001-03-30 00:23:46 +00:00
|
|
|
*length = paddedsize(sizeof(UCATableHeader))+paddedsize(sizeof(UColOptionSet));
|
|
|
|
result = (uint8_t *)uprv_malloc(*length);
|
|
|
|
uprv_memcpy(result, UCA->image, sizeof(UCATableHeader));
|
|
|
|
uprv_memcpy(result+paddedsize(sizeof(UCATableHeader)), coll->options, sizeof(UColOptionSet));
|
2001-02-26 10:28:56 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-30 00:23:46 +00:00
|
|
|
void ucol_setOptionsFromHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status) {
|
2001-02-28 19:01:23 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-03-30 00:23:46 +00:00
|
|
|
result->caseFirst = opts->caseFirst;
|
|
|
|
result->caseLevel = opts->caseLevel;
|
|
|
|
result->frenchCollation = opts->frenchCollation;
|
|
|
|
result->normalizationMode = opts->normalizationMode;
|
|
|
|
result->strength = opts->strength;
|
|
|
|
result->variableTopValue = opts->variableTopValue;
|
|
|
|
result->alternateHandling = opts->alternateHandling;
|
2001-02-26 10:28:56 +00:00
|
|
|
|
|
|
|
result->caseFirstisDefault = TRUE;
|
|
|
|
result->caseLevelisDefault = TRUE;
|
|
|
|
result->frenchCollationisDefault = TRUE;
|
|
|
|
result->normalizationModeisDefault = TRUE;
|
|
|
|
result->strengthisDefault = TRUE;
|
|
|
|
result->variableTopValueisDefault = TRUE;
|
2001-03-02 00:19:43 +00:00
|
|
|
|
|
|
|
ucol_updateInternalState(result);
|
2001-03-30 00:23:46 +00:00
|
|
|
|
|
|
|
result->options = opts;
|
2001-02-26 10:28:56 +00:00
|
|
|
}
|
|
|
|
|
2001-03-30 00:23:46 +00:00
|
|
|
void ucol_putOptionsToHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status) {
|
2001-02-28 19:01:23 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->caseFirst = result->caseFirst;
|
|
|
|
opts->caseLevel = result->caseLevel;
|
|
|
|
opts->frenchCollation = result->frenchCollation;
|
|
|
|
opts->normalizationMode = result->normalizationMode;
|
|
|
|
opts->strength = result->strength;
|
2001-04-23 01:53:49 +00:00
|
|
|
opts->variableTopValue = result->variableTopValue;
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->alternateHandling = result->alternateHandling;
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
2001-03-03 03:35:17 +00:00
|
|
|
|
2001-04-10 22:06:25 +00:00
|
|
|
U_CAPI const uint16_t * getFCHK_STAGE_1_(UErrorCode *);
|
|
|
|
U_CAPI const uint16_t * getFCHK_STAGE_2_(UErrorCode *);
|
|
|
|
U_CAPI const uint16_t * getFCHK_STAGE_3_(UErrorCode *);
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
static const uint16_t *FCD_STAGE_1_;
|
2001-04-10 22:06:25 +00:00
|
|
|
static const uint16_t *FCD_STAGE_2_;
|
|
|
|
static const uint16_t *FCD_STAGE_3_;
|
|
|
|
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
inline UBool ucol_unsafeCP(UChar c, const UCollator *coll) {
|
2001-05-10 22:12:53 +00:00
|
|
|
if (c < coll->minUnsafeCP) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
|
|
|
int32_t hash = c;
|
|
|
|
uint8_t htbyte;
|
|
|
|
|
|
|
|
if (hash >= UCOL_UNSAFECP_TABLE_SIZE*8) {
|
|
|
|
if (hash >= 0xd800 && hash <= 0xf8ff) {
|
|
|
|
/* Part of a surrogate, or in private use area. */
|
|
|
|
/* These are always considered unsafe. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
hash = (hash & UCOL_UNSAFECP_TABLE_MASK) + 256;
|
|
|
|
}
|
|
|
|
htbyte = coll->unsafeCP[hash>>3];
|
2001-05-11 01:13:08 +00:00
|
|
|
return (((htbyte >> (hash & 7)) & 1) == 1);
|
2001-04-18 19:31:05 +00:00
|
|
|
}
|
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
/**
|
2001-05-17 01:06:25 +00:00
|
|
|
* Approximate determination if a character is at a contraction end.
|
2001-06-06 23:26:50 +00:00
|
|
|
* Guaranteed to be TRUE if a character is at the end of a contraction,
|
2001-05-17 01:06:25 +00:00
|
|
|
* otherwise it is not deterministic.
|
|
|
|
* @param c character to be determined
|
|
|
|
* @param coll collator
|
|
|
|
*/
|
2001-05-10 17:49:24 +00:00
|
|
|
inline UBool ucol_contractionEndCP(UChar c, const UCollator *coll) {
|
2001-05-10 22:12:53 +00:00
|
|
|
if (c < coll->minContrEndCP) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t hash = c;
|
|
|
|
uint8_t htbyte;
|
|
|
|
|
|
|
|
if (hash >= UCOL_UNSAFECP_TABLE_SIZE*8) {
|
|
|
|
hash = (hash & UCOL_UNSAFECP_TABLE_MASK) + 256;
|
|
|
|
}
|
|
|
|
htbyte = coll->contrEndCP[hash>>3];
|
2001-05-11 01:13:08 +00:00
|
|
|
return (((htbyte >> (hash & 7)) & 1) == 1);
|
2001-05-10 17:49:24 +00:00
|
|
|
}
|
2001-04-10 22:06:25 +00:00
|
|
|
|
2001-03-03 03:35:17 +00:00
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
/*
|
|
|
|
* i_getCombiningClass()
|
|
|
|
* A fast, at least partly inline version of u_getCombiningClass()
|
|
|
|
* This is a candidate for further optimization. Used heavily
|
|
|
|
* in contraction processing.
|
|
|
|
*/
|
|
|
|
inline uint8_t i_getCombiningClass(UChar c, const UCollator *coll) {
|
|
|
|
uint8_t sCC = 0;
|
|
|
|
if (c >= 0x300 && ucol_unsafeCP(c, coll)) {
|
|
|
|
sCC = u_getCombiningClass(c);
|
|
|
|
}
|
|
|
|
return sCC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
UCollator* ucol_initCollator(const UCATableHeader *image, UCollator *fillIn, UErrorCode *status) {
|
2001-04-18 19:31:05 +00:00
|
|
|
UChar c;
|
2001-01-15 07:28:54 +00:00
|
|
|
UCollator *result = fillIn;
|
2001-01-29 22:09:24 +00:00
|
|
|
if(U_FAILURE(*status) || image == NULL) {
|
2001-01-05 00:47:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result == NULL) {
|
2001-01-15 19:02:30 +00:00
|
|
|
result = (UCollator *)uprv_malloc(sizeof(UCollator));
|
2001-01-05 00:47:25 +00:00
|
|
|
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);
|
2001-03-30 00:23:46 +00:00
|
|
|
|
|
|
|
result->options = (UColOptionSet*)((uint8_t*)result->image+result->image->options);
|
|
|
|
result->freeOptionsOnClose = FALSE;
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
/* set attributes */
|
2001-03-30 00:23:46 +00:00
|
|
|
result->caseFirst = result->options->caseFirst;
|
|
|
|
result->caseLevel = result->options->caseLevel;
|
|
|
|
result->frenchCollation = result->options->frenchCollation;
|
|
|
|
result->normalizationMode = result->options->normalizationMode;
|
|
|
|
result->strength = result->options->strength;
|
|
|
|
result->variableTopValue = result->options->variableTopValue;
|
|
|
|
result->alternateHandling = result->options->alternateHandling;
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
result->caseFirstisDefault = TRUE;
|
|
|
|
result->caseLevelisDefault = TRUE;
|
|
|
|
result->frenchCollationisDefault = TRUE;
|
|
|
|
result->normalizationModeisDefault = TRUE;
|
|
|
|
result->strengthisDefault = TRUE;
|
|
|
|
result->variableTopValueisDefault = TRUE;
|
2001-02-27 21:01:11 +00:00
|
|
|
result->alternateHandlingisDefault = TRUE;
|
2001-01-09 00:52:18 +00:00
|
|
|
|
2001-01-18 00:46:19 +00:00
|
|
|
result->scriptOrder = NULL;
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
result->zero = 0;
|
|
|
|
result->rules = NULL;
|
2001-04-20 22:29:53 +00:00
|
|
|
/* get the version info form UCATableHeader and populate the Collator struct*/
|
2001-02-26 23:52:44 +00:00
|
|
|
result->dataInfo.dataVersion[0] = result->image->version[0]; /* UCA Builder version*/
|
|
|
|
result->dataInfo.dataVersion[1] = result->image->version[1]; /* UCA Tailoring rules version*/
|
2001-03-02 01:14:03 +00:00
|
|
|
|
2001-03-03 03:35:17 +00:00
|
|
|
result->unsafeCP = (uint8_t *)result->image + result->image->unsafeCP;
|
2001-04-18 19:31:05 +00:00
|
|
|
result->minUnsafeCP = 0;
|
|
|
|
for (c=0; c<0x300; c++) { // Find the smallest unsafe char.
|
|
|
|
if (ucol_unsafeCP(c, result)) break;
|
|
|
|
}
|
|
|
|
result->minUnsafeCP = c;
|
2001-03-03 03:35:17 +00:00
|
|
|
|
2001-05-10 22:12:53 +00:00
|
|
|
result->contrEndCP = (uint8_t *)result->image + result->image->contrEndCP;
|
|
|
|
result->minContrEndCP = 0;
|
|
|
|
for (c=0; c<0x300; c++) { // Find the Contraction-ending char.
|
|
|
|
if (ucol_contractionEndCP(c, result)) break;
|
|
|
|
}
|
|
|
|
result->minContrEndCP = c;
|
|
|
|
|
2001-03-02 01:14:03 +00:00
|
|
|
/* max expansion tables */
|
2001-04-23 01:53:49 +00:00
|
|
|
result->endExpansionCE = (uint32_t*)((uint8_t*)result->image +
|
2001-03-02 01:14:03 +00:00
|
|
|
result->image->endExpansionCE);
|
2001-04-23 01:53:49 +00:00
|
|
|
result->lastEndExpansionCE = result->endExpansionCE +
|
2001-03-02 01:14:03 +00:00
|
|
|
result->image->endExpansionCECount - 1;
|
2001-04-23 01:53:49 +00:00
|
|
|
result->expansionCESize = (uint8_t*)result->image +
|
2001-03-02 01:14:03 +00:00
|
|
|
result->image->expansionCESize;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-10 22:06:25 +00:00
|
|
|
if (FCD_STAGE_1_ == NULL) {
|
2001-04-23 01:53:49 +00:00
|
|
|
FCD_STAGE_1_ = getFCHK_STAGE_1_(status);
|
2001-04-10 22:06:25 +00:00
|
|
|
}
|
|
|
|
if (FCD_STAGE_2_ == NULL) {
|
2001-04-23 01:53:49 +00:00
|
|
|
FCD_STAGE_2_ = getFCHK_STAGE_2_(status);
|
2001-04-10 22:06:25 +00:00
|
|
|
}
|
|
|
|
if (FCD_STAGE_3_ == NULL) {
|
2001-04-23 01:53:49 +00:00
|
|
|
FCD_STAGE_3_ = getFCHK_STAGE_3_(status);
|
2001-04-10 22:06:25 +00:00
|
|
|
}
|
2001-03-02 01:14:03 +00:00
|
|
|
|
2001-04-10 22:06:25 +00:00
|
|
|
result->errorCode = *status;
|
2001-03-02 00:19:43 +00:00
|
|
|
ucol_updateInternalState(result);
|
2001-04-10 22:06:25 +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) {
|
2001-01-15 07:28:54 +00:00
|
|
|
UCollator *newUCA = (UCollator *)uprv_malloc(sizeof(UCollator));
|
2001-01-31 07:20:56 +00:00
|
|
|
UDataMemory *result = udata_openChoice(NULL, UCA_DATA_TYPE, UCA_DATA_NAME, isAcceptableUCA, NULL, status);
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
udata_close(result);
|
|
|
|
uprv_free(newUCA);
|
|
|
|
}
|
|
|
|
|
2001-01-29 22:34:04 +00:00
|
|
|
if(result != NULL) { /* It looks like sometimes we can fail to find the data file */
|
|
|
|
newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), newUCA, status);
|
2001-04-05 01:40:36 +00:00
|
|
|
if(U_SUCCESS(*status)){
|
|
|
|
newUCA->rb = NULL;
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if(UCA == NULL) {
|
|
|
|
UCA = newUCA;
|
|
|
|
newUCA = NULL;
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
2001-01-29 22:34:04 +00:00
|
|
|
|
2001-04-05 01:40:36 +00:00
|
|
|
if(newUCA != NULL) {
|
|
|
|
udata_close(result);
|
|
|
|
uprv_free(newUCA);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
udata_close(result);
|
|
|
|
uprv_free(newUCA);
|
|
|
|
UCA= NULL;
|
2001-01-29 22:34:04 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-04-23 21:29:14 +00:00
|
|
|
/* collIterNormalize Incremental Normalization happens here. */
|
|
|
|
/* pick up the range of chars identifed by FCD, */
|
|
|
|
/* normalize it into the collIterate's writable buffer, */
|
|
|
|
/* switch the collIterate's state to use the writable buffer. */
|
|
|
|
/* */
|
|
|
|
void collIterNormalize(collIterate *collationSource)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar *srcP = collationSource->pos - 1; /* Start of chars to normalize */
|
|
|
|
UChar *endP = collationSource->fcdPosition; /* End of region to normalize+1 */
|
|
|
|
uint32_t normLen;
|
|
|
|
|
|
|
|
normLen = unorm_normalize(srcP, endP-srcP, UNORM_NFD, 0, collationSource->writableBuffer,
|
|
|
|
collationSource->writableBufSize, &status);
|
2001-04-24 03:18:54 +00:00
|
|
|
if (normLen == collationSource->writableBufSize) {
|
|
|
|
UChar *temp = (UChar *)uprv_malloc((normLen+1)*sizeof(UChar));
|
|
|
|
uprv_memcpy(temp, collationSource->writableBuffer, normLen * sizeof(UChar));
|
|
|
|
temp[normLen] = 0;
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(collationSource);
|
2001-04-24 03:18:54 +00:00
|
|
|
collationSource->writableBuffer = temp;
|
|
|
|
}
|
2001-04-23 21:29:14 +00:00
|
|
|
if (U_FAILURE(status)) { /* This would be buffer overflow */
|
|
|
|
if (status == U_BUFFER_OVERFLOW_ERROR) {
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(collationSource);
|
2001-04-23 21:29:14 +00:00
|
|
|
collationSource->writableBuffer = (UChar *)uprv_malloc((normLen+1)*sizeof(UChar));
|
2001-05-17 23:09:35 +00:00
|
|
|
collationSource->flags |= UCOL_ITER_ALLOCATED;
|
2001-04-23 21:29:14 +00:00
|
|
|
/* to enable null termination */
|
|
|
|
collationSource->writableBufSize = normLen + 1;
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
unorm_normalize(srcP, endP-srcP, UNORM_NFD, 0, collationSource->writableBuffer,
|
2001-05-17 23:09:35 +00:00
|
|
|
collationSource->writableBufSize, &status);
|
|
|
|
if (status != U_ZERO_ERROR) {
|
|
|
|
#ifdef UCOL_DEBUG
|
|
|
|
fprintf(stderr, "collIterNormalize(), normalize #2 failed, status = %d\n", status);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
collationSource->writableBuffer[normLen] = 0;
|
2001-04-23 21:29:14 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-05-17 23:09:35 +00:00
|
|
|
#ifdef UCOL_DEBUG
|
|
|
|
fprintf(stderr, "collIterNormalize(), normalize #1 failed, status = %d\n", status);
|
|
|
|
#endif
|
2001-04-23 21:29:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-04-24 03:18:54 +00:00
|
|
|
|
2001-04-23 21:29:14 +00:00
|
|
|
collationSource->pos = collationSource->writableBuffer;
|
|
|
|
collationSource->origFlags = collationSource->flags;
|
|
|
|
collationSource->flags |= UCOL_ITER_INNORMBUF;
|
|
|
|
collationSource->flags &= ~(UCOL_ITER_NORM | UCOL_ITER_HASLEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Incremental FCD check and normalize */
|
|
|
|
/* Called from getNextCE when normalization state is suspect. */
|
|
|
|
/* When entering, the state is known to be this: */
|
|
|
|
/* o We are working in the main buffer of the collIterate, not the side */
|
|
|
|
/* writable buffer. When in the side buffer, normalization mode is always off, */
|
|
|
|
/* so we won't get here. */
|
|
|
|
/* o The leading combining class from the current character is 0 or */
|
|
|
|
/* the trailing combining class of the previous char was zero. */
|
|
|
|
/* True because the previous call to this function will have always exited */
|
|
|
|
/* that way, and we get called for every char where cc might be non-zero. */
|
2001-04-24 03:18:54 +00:00
|
|
|
inline UBool collIterFCD(collIterate *collationSource) {
|
2001-04-23 21:29:14 +00:00
|
|
|
UChar32 codepoint;
|
|
|
|
UChar *srcP;
|
2001-06-03 23:40:41 +00:00
|
|
|
int32_t length;
|
|
|
|
int32_t count = 0;
|
2001-04-23 21:29:14 +00:00
|
|
|
uint8_t leadingCC;
|
|
|
|
uint8_t prevTrailingCC = 0;
|
|
|
|
uint16_t fcd;
|
|
|
|
UBool needNormalize = FALSE;
|
|
|
|
|
|
|
|
srcP = collationSource->pos-1;
|
|
|
|
|
|
|
|
// If the source string is null terminated, use a fake too-long string length
|
|
|
|
// (needed for UTF_NEXT_CHAR). null will stop everything OK.)
|
2001-06-03 23:40:41 +00:00
|
|
|
length = (collationSource->flags & UCOL_ITER_HASLEN) ? collationSource->endp - srcP : INT32_MAX;
|
2001-04-23 21:29:14 +00:00
|
|
|
|
|
|
|
// Get the trailing combining class of the current character. If it's zero,
|
|
|
|
// we are OK.
|
|
|
|
UTF_NEXT_CHAR(srcP, count, length, codepoint);
|
|
|
|
/* trie access */
|
|
|
|
fcd = FCD_STAGE_3_[
|
|
|
|
FCD_STAGE_2_[FCD_STAGE_1_[codepoint >> STAGE_1_SHIFT_] +
|
|
|
|
((codepoint >> STAGE_2_SHIFT_) & STAGE_2_MASK_AFTER_SHIFT_)] +
|
|
|
|
(codepoint & STAGE_3_MASK_)];
|
|
|
|
prevTrailingCC = (uint8_t)(fcd & LAST_BYTE_MASK_);
|
|
|
|
|
|
|
|
if (prevTrailingCC != 0) {
|
|
|
|
// The current char has a non-zero trailing CC. Scan forward until we find
|
|
|
|
// a char with a leading cc of zero.
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (count >= length) {
|
|
|
|
break;
|
|
|
|
}
|
2001-06-03 23:40:41 +00:00
|
|
|
int32_t savedCount = count;
|
2001-04-23 21:29:14 +00:00
|
|
|
UTF_NEXT_CHAR(srcP, count, length, codepoint);
|
|
|
|
|
|
|
|
/* trie access */
|
|
|
|
fcd = FCD_STAGE_3_[
|
|
|
|
FCD_STAGE_2_[FCD_STAGE_1_[codepoint >> STAGE_1_SHIFT_] +
|
|
|
|
((codepoint >> STAGE_2_SHIFT_) & STAGE_2_MASK_AFTER_SHIFT_)] +
|
|
|
|
(codepoint & STAGE_3_MASK_)];
|
|
|
|
leadingCC = (uint8_t)(fcd >> SECOND_LAST_BYTE_SHIFT_);
|
|
|
|
if (leadingCC == 0) {
|
2001-05-25 16:41:59 +00:00
|
|
|
count = savedCount; // Hit char that is not part of combining sequence.
|
|
|
|
// back up over it. (Could be surrogate pair!)
|
2001-04-23 21:29:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leadingCC < prevTrailingCC) {
|
|
|
|
needNormalize = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
prevTrailingCC = (uint8_t)(fcd & LAST_BYTE_MASK_);
|
|
|
|
}
|
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-25 23:28:55 +00:00
|
|
|
collationSource->fcdPosition = srcP + count;
|
2001-04-23 21:29:14 +00:00
|
|
|
|
2001-04-24 03:18:54 +00:00
|
|
|
return needNormalize;
|
2001-04-23 21:29:14 +00:00
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Following are the CE retrieval functions */
|
|
|
|
/* */
|
|
|
|
/****************************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* there should be a macro version of this function in the header file */
|
|
|
|
/* This is the first function that tries to fetch a collation element */
|
|
|
|
/* If it's not succesfull or it encounters a more difficult situation */
|
|
|
|
/* some more sofisticated and slower functions are invoked */
|
2001-04-18 19:31:05 +00:00
|
|
|
inline uint32_t ucol_IGetNextCE(const UCollator *coll, collIterate *collationSource, UErrorCode *status) {
|
2001-02-06 00:36:48 +00:00
|
|
|
uint32_t order;
|
|
|
|
if (collationSource->CEpos > collationSource->toReturn) { /* Are there any CEs from previous expansions? */
|
|
|
|
order = *(collationSource->toReturn++); /* if so, return them */
|
|
|
|
if(collationSource->CEpos == collationSource->toReturn) {
|
2001-04-23 01:53:49 +00:00
|
|
|
collationSource->CEpos = collationSource->toReturn = collationSource->CEs;
|
2001-02-06 00:36:48 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar ch;
|
|
|
|
|
2001-04-12 19:59:28 +00:00
|
|
|
for (;;) /* Loop handles case when incremental normalize switches */
|
|
|
|
{ /* to or from the side buffer / original string, and we */
|
|
|
|
/* need to start again to get the next character. */
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
if ((collationSource->flags & (UCOL_ITER_HASLEN | UCOL_ITER_INNORMBUF | UCOL_ITER_NORM )) == 0)
|
2001-04-23 01:53:49 +00:00
|
|
|
{
|
2001-04-06 23:37:48 +00:00
|
|
|
// The source string is null terminated and we're not working from the side buffer,
|
|
|
|
// and we're not normalizing. This is the fast path.
|
2001-04-23 21:29:14 +00:00
|
|
|
// (We can be in the side buffer for Thai pre-vowel reordering even when not normalizing.)
|
2001-04-06 23:37:48 +00:00
|
|
|
ch = *collationSource->pos++;
|
2001-04-12 19:59:28 +00:00
|
|
|
if (ch != 0) {
|
2001-04-06 23:37:48 +00:00
|
|
|
break;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-04-06 23:37:48 +00:00
|
|
|
return UCOL_NO_MORE_CES;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (collationSource->flags & UCOL_ITER_HASLEN) {
|
|
|
|
// Normal path for strings when length is specified.
|
|
|
|
// (We can't be in side buffer because it is always null terminated.)
|
|
|
|
if (collationSource->pos >= collationSource->endp) {
|
|
|
|
// Ran off of the end of the main source string. We're done.
|
|
|
|
return UCOL_NO_MORE_CES;
|
|
|
|
}
|
|
|
|
ch = *collationSource->pos++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-04-23 21:29:14 +00:00
|
|
|
// Null terminated string.
|
2001-04-06 23:37:48 +00:00
|
|
|
ch = *collationSource->pos++;
|
2001-04-23 21:29:14 +00:00
|
|
|
if (ch == 0) {
|
|
|
|
// Ran off end of buffer.
|
|
|
|
if ((collationSource->flags & UCOL_ITER_INNORMBUF) == 0) {
|
2001-05-11 01:13:08 +00:00
|
|
|
// Ran off end of main string.
|
2001-04-23 21:29:14 +00:00
|
|
|
return UCOL_NO_MORE_CES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-25 19:30:01 +00:00
|
|
|
// Hit null in the normalize side buffer.
|
|
|
|
// Usually this means the end of the normalized data,
|
|
|
|
// except for one odd case: a null followed by combining chars,
|
|
|
|
// which is the case if we are at the start of the buffer.
|
|
|
|
if (collationSource->pos == collationSource->writableBuffer+1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Null marked end of side buffer.
|
|
|
|
// Revert to the main string and
|
2001-04-23 21:29:14 +00:00
|
|
|
// loop back to top to try again to get a character.
|
|
|
|
collationSource->pos = collationSource->fcdPosition;
|
|
|
|
collationSource->flags = collationSource->origFlags;
|
|
|
|
continue;
|
|
|
|
}
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
// We've got a character. See if there's any fcd and/or normalization stuff to do.
|
2001-04-23 21:29:14 +00:00
|
|
|
// Note that UCOL_ITER_NORM flag is always zero when we are in the side buffer.
|
2001-04-12 19:59:28 +00:00
|
|
|
if ((collationSource->flags & UCOL_ITER_NORM) == 0) {
|
2001-04-06 23:37:48 +00:00
|
|
|
break;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
if (collationSource->fcdPosition >= collationSource->pos) {
|
|
|
|
// An earlier FCD check has already covered the current character.
|
|
|
|
// We can go ahead and process this char.
|
|
|
|
break;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
if (ch < ZERO_CC_LIMIT_ ) {
|
2001-04-06 23:37:48 +00:00
|
|
|
// Fast fcd safe path. Trailing combining class == 0. This char is OK.
|
|
|
|
break;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
if (ch < NFC_ZERO_CC_BLOCK_LIMIT_) {
|
|
|
|
// We need to peek at the next character in order to tell if we are FCD
|
2001-04-12 19:59:28 +00:00
|
|
|
if ((collationSource->flags & UCOL_ITER_HASLEN) && collationSource->pos >= collationSource->endp) {
|
2001-04-06 23:37:48 +00:00
|
|
|
// We are at the last char of source string.
|
|
|
|
// It is always OK for FCD check.
|
|
|
|
break;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
// Not at last char of source string (or we'll check against terminating null). Do the FCD fast test
|
2001-04-12 19:59:28 +00:00
|
|
|
if (*collationSource->pos < NFC_ZERO_CC_BLOCK_LIMIT_) {
|
2001-04-06 23:37:48 +00:00
|
|
|
break;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
// Need a more complete FCD check and possible normalization.
|
2001-04-24 03:18:54 +00:00
|
|
|
if (collIterFCD(collationSource)) {
|
|
|
|
collIterNormalize(collationSource);
|
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
if ((collationSource->flags & UCOL_ITER_INNORMBUF) == 0) {
|
|
|
|
// No normalization was needed. Go ahead and process the char we already had.
|
|
|
|
break;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
// Some normalization happened. Next loop iteration will pick up a char
|
|
|
|
// from the normalization buffer.
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
} // end for (;;)
|
|
|
|
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
if (ch <= 0xFF) {
|
|
|
|
/* For latin-1 characters we never need to fall back to the UCA table */
|
|
|
|
/* because all of the UCA data is replicated in the latinOneMapping array */
|
|
|
|
order = coll->latinOneMapping[ch];
|
|
|
|
if (order > UCOL_NOT_FOUND) {
|
|
|
|
order = getSpecialCE(coll, order, collationSource, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-04-23 01:53:49 +00:00
|
|
|
order = ucmp32_get(coll->mapping, ch); /* we'll go for slightly slower trie */
|
2001-04-18 19:31:05 +00:00
|
|
|
if(order > UCOL_NOT_FOUND) { /* if a CE is special */
|
2001-04-23 01:53:49 +00:00
|
|
|
order = getSpecialCE(coll, order, collationSource, status); /* and try to get the special CE */
|
2001-04-18 19:31:05 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
if(order == UCOL_NOT_FOUND) { /* We couldn't find a good CE in the tailoring */
|
|
|
|
order = ucol_getNextUCA(ch, collationSource, status);
|
|
|
|
}
|
|
|
|
}
|
2001-02-06 00:36:48 +00:00
|
|
|
return order; /* return the CE */
|
|
|
|
}
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
/* ucol_getNextCE, out-of-line version for use from other files. */
|
|
|
|
U_CAPI uint32_t ucol_getNextCE(const UCollator *coll, collIterate *collationSource, UErrorCode *status) {
|
|
|
|
return ucol_IGetNextCE(coll, collationSource, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/**
|
2001-04-23 01:53:49 +00:00
|
|
|
* Incremental previous normalization happens here. Pick up the range of chars
|
|
|
|
* identifed by FCD, normalize it into the collIterate's writable buffer,
|
|
|
|
* switch the collIterate's state to use the writable buffer.
|
2001-04-12 00:08:26 +00:00
|
|
|
* @param data collation iterator data
|
|
|
|
*/
|
|
|
|
void collPrevIterNormalize(collIterate *data)
|
|
|
|
{
|
2001-04-17 02:43:35 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-04-24 03:18:54 +00:00
|
|
|
UChar *pEnd = data->pos; /* End normalize + 1 */
|
2001-04-12 18:25:07 +00:00
|
|
|
UChar *pStart;
|
2001-04-12 00:08:26 +00:00
|
|
|
uint32_t normLen;
|
2001-04-20 22:29:53 +00:00
|
|
|
UChar *pStartNorm;
|
2001-04-12 00:08:26 +00:00
|
|
|
|
2001-04-12 18:25:07 +00:00
|
|
|
/* Start normalize */
|
|
|
|
if (data->fcdPosition == NULL) {
|
|
|
|
pStart = data->string;
|
|
|
|
}
|
|
|
|
else {
|
2001-04-23 01:53:49 +00:00
|
|
|
pStart = data->fcdPosition + 1;
|
2001-04-12 18:25:07 +00:00
|
|
|
}
|
|
|
|
|
2001-04-24 03:18:54 +00:00
|
|
|
normLen = unorm_normalize(pStart, (pEnd - pStart) + 1, UNORM_NFD, 0,
|
2001-04-20 22:29:53 +00:00
|
|
|
data->writableBuffer, 0, &status);
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
if (data->writableBufSize <= normLen) {
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(data);
|
2001-04-23 01:53:49 +00:00
|
|
|
data->writableBuffer = (UChar *)uprv_malloc((normLen + 1) *
|
|
|
|
sizeof(UChar));
|
|
|
|
/* to handle the zero termination */
|
|
|
|
data->writableBufSize = normLen + 1;
|
2001-04-12 00:08:26 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
status = U_ZERO_ERROR;
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-20 22:29:53 +00:00
|
|
|
this puts the null termination infront of the normalized string instead
|
|
|
|
of the end
|
|
|
|
*/
|
|
|
|
pStartNorm = data->writableBuffer + (data->writableBufSize - normLen);
|
|
|
|
*(pStartNorm - 1) = 0;
|
2001-05-11 01:13:08 +00:00
|
|
|
unorm_normalize(pStart, (pEnd - pStart) + 1, UNORM_NFD, 0, pStartNorm,
|
2001-04-24 03:18:54 +00:00
|
|
|
normLen, &status);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
data->pos = data->writableBuffer + data->writableBufSize;
|
2001-04-12 00:08:26 +00:00
|
|
|
data->origFlags = data->flags;
|
|
|
|
data->flags |= UCOL_ITER_INNORMBUF;
|
|
|
|
data->flags &= ~(UCOL_ITER_NORM | UCOL_ITER_HASLEN);
|
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/**
|
2001-04-23 01:53:49 +00:00
|
|
|
* Incremental FCD check for previous iteration and normalize. Called from
|
|
|
|
* getPrevCE when normalization state is suspect.
|
|
|
|
* When entering, the state is known to be this:
|
|
|
|
* o We are working in the main buffer of the collIterate, not the side
|
|
|
|
* writable buffer. When in the side buffer, normalization mode is always
|
|
|
|
* off, so we won't get here.
|
|
|
|
* o The leading combining class from the current character is 0 or the
|
|
|
|
* trailing combining class of the previous char was zero.
|
|
|
|
* True because the previous call to this function will have always exited
|
|
|
|
* that way, and we get called for every char where cc might be non-zero.
|
2001-04-12 00:08:26 +00:00
|
|
|
* @param data collation iterate struct
|
2001-05-11 01:13:08 +00:00
|
|
|
* @return normalization status, TRUE for normalization to be done, FALSE
|
2001-04-20 22:29:53 +00:00
|
|
|
* otherwise
|
2001-04-12 00:08:26 +00:00
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
inline UBool collPrevIterFCD(collIterate *data)
|
2001-04-12 00:08:26 +00:00
|
|
|
{
|
|
|
|
UChar32 codepoint;
|
|
|
|
uint8_t leadingCC;
|
|
|
|
uint8_t trailingCC = 0;
|
|
|
|
uint16_t fcd;
|
2001-04-20 22:29:53 +00:00
|
|
|
UBool result = FALSE;
|
2001-06-03 23:40:41 +00:00
|
|
|
int32_t length;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
length = (data->pos + 1) - data->string;
|
2001-04-06 23:37:48 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/* Get the trailing combining class of the current character. */
|
|
|
|
UTF_PREV_CHAR(data->string, 0, length, codepoint);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/* trie access */
|
|
|
|
fcd = FCD_STAGE_3_[
|
2001-04-23 01:53:49 +00:00
|
|
|
FCD_STAGE_2_[FCD_STAGE_1_[codepoint >> STAGE_1_SHIFT_] +
|
2001-04-12 00:08:26 +00:00
|
|
|
((codepoint >> STAGE_2_SHIFT_) & STAGE_2_MASK_AFTER_SHIFT_)] +
|
|
|
|
(codepoint & STAGE_3_MASK_)];
|
2001-04-06 23:37:48 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
leadingCC = (uint8_t)(fcd >> SECOND_LAST_BYTE_SHIFT_);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
if (leadingCC != 0) {
|
|
|
|
/*
|
2001-04-23 01:53:49 +00:00
|
|
|
The current char has a non-zero leading combining class.
|
2001-04-12 00:08:26 +00:00
|
|
|
Scan backward until we find a char with a trailing cc of zero.
|
|
|
|
*/
|
2001-05-02 23:36:22 +00:00
|
|
|
for (;;)
|
2001-04-12 00:08:26 +00:00
|
|
|
{
|
|
|
|
if (length <= 0) {
|
2001-04-25 23:28:55 +00:00
|
|
|
length = -1;
|
2001-04-12 00:08:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
UTF_PREV_CHAR(data->string, 0, length, codepoint);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/* trie access */
|
|
|
|
fcd = FCD_STAGE_3_[
|
2001-04-23 01:53:49 +00:00
|
|
|
FCD_STAGE_2_[FCD_STAGE_1_[codepoint >> STAGE_1_SHIFT_] +
|
2001-04-12 00:08:26 +00:00
|
|
|
((codepoint >> STAGE_2_SHIFT_) & STAGE_2_MASK_AFTER_SHIFT_)] +
|
|
|
|
(codepoint & STAGE_3_MASK_)];
|
|
|
|
|
|
|
|
trailingCC = (uint8_t)(fcd & LAST_BYTE_MASK_);
|
|
|
|
|
|
|
|
if (trailingCC == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
if (leadingCC < trailingCC) {
|
2001-04-20 22:29:53 +00:00
|
|
|
result = TRUE;
|
2001-04-12 00:08:26 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
leadingCC = (uint8_t)(fcd >> SECOND_LAST_BYTE_SHIFT_);
|
2001-04-12 00:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-25 23:28:55 +00:00
|
|
|
if (length < 0) {
|
2001-04-12 18:25:07 +00:00
|
|
|
data->fcdPosition = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data->fcdPosition = data->string + length;
|
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
return result;
|
2001-04-12 00:08:26 +00:00
|
|
|
}
|
|
|
|
|
2001-05-17 01:06:25 +00:00
|
|
|
/**
|
|
|
|
* Determines if we are at the start of the data string in the backwards
|
|
|
|
* collation iterator
|
|
|
|
* @param data collation iterator
|
|
|
|
* @return TRUE if we are at the start
|
|
|
|
*/
|
|
|
|
inline UBool isAtStartPrevIterate(collIterate *data) {
|
|
|
|
return (data->pos == data->string) ||
|
|
|
|
((data->flags & UCOL_ITER_INNORMBUF) &&
|
|
|
|
*(data->pos - 1) == 0 && data->fcdPosition == NULL);
|
|
|
|
}
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/**
|
|
|
|
* Inline function that gets a simple CE.
|
2001-04-23 01:53:49 +00:00
|
|
|
* So what it does is that it will first check the expansion buffer. If the
|
|
|
|
* expansion buffer is not empty, ie the end pointer to the expansion buffer
|
|
|
|
* is different from the string pointer, we return the collation element at the
|
2001-04-12 00:08:26 +00:00
|
|
|
* return pointer and decrement it.
|
|
|
|
* For more complicated CEs it resorts to getComplicatedCE.
|
|
|
|
* @param coll collator data
|
|
|
|
* @param data collation iterator struct
|
|
|
|
* @param status error status
|
|
|
|
*/
|
2001-04-18 19:31:05 +00:00
|
|
|
inline uint32_t ucol_IGetPrevCE(const UCollator *coll, collIterate *data,
|
2001-04-23 01:53:49 +00:00
|
|
|
UErrorCode *status)
|
2001-04-12 00:08:26 +00:00
|
|
|
{
|
|
|
|
uint32_t result = UCOL_NULLORDER;
|
2001-04-23 01:53:49 +00:00
|
|
|
if (data->CEpos > data->CEs) {
|
|
|
|
data->toReturn --;
|
|
|
|
result = *(data->toReturn);
|
|
|
|
if (data->CEs == data->toReturn) {
|
|
|
|
data->CEpos = data->toReturn = data->CEs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-04-12 00:08:26 +00:00
|
|
|
UChar ch;
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
|
|
|
Loop handles case when incremental normalize switches to or from the
|
|
|
|
side buffer / original string, and we need to start again to get the
|
2001-04-12 00:08:26 +00:00
|
|
|
next character.
|
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-05-02 23:36:22 +00:00
|
|
|
for (;;) {
|
2001-04-12 00:08:26 +00:00
|
|
|
if ((data->flags & UCOL_ITER_INNORMBUF) == 0) {
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
2001-04-12 00:08:26 +00:00
|
|
|
Normal path for strings when length is specified.
|
|
|
|
Not in side buffer because it is always null terminated.
|
|
|
|
*/
|
|
|
|
if (data->pos <= data->string) {
|
|
|
|
/* End of the main source string */
|
|
|
|
return UCOL_NO_MORE_CES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* we are in the side buffer. */
|
2001-04-20 22:29:53 +00:00
|
|
|
if (*(data->pos - 1) == 0) {
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
|
|
|
At the start of the normalize side buffer.
|
2001-04-12 00:08:26 +00:00
|
|
|
Go back to string.
|
2001-04-12 18:25:07 +00:00
|
|
|
Because pointer points to the last accessed character,
|
|
|
|
hence we have to increment it by one here.
|
2001-04-12 00:08:26 +00:00
|
|
|
*/
|
2001-04-12 18:25:07 +00:00
|
|
|
if (data->fcdPosition == NULL) {
|
|
|
|
data->pos = data->string;
|
|
|
|
return UCOL_NO_MORE_CES;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data->pos = data->fcdPosition + 1;
|
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
data->flags = data->origFlags;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data->pos --;
|
|
|
|
ch = *(data->pos);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if there's no fcd and/or normalization stuff to do.
|
2001-04-12 00:08:26 +00:00
|
|
|
* if the current character is not fcd.
|
2001-04-25 23:28:55 +00:00
|
|
|
* if current character is at the start of the string
|
2001-04-12 00:08:26 +00:00
|
|
|
* Trailing combining class == 0.
|
|
|
|
* Note if pos is in the writablebuffer, norm is always 0
|
|
|
|
*/
|
2001-04-23 01:53:49 +00:00
|
|
|
if ((data->flags & UCOL_ITER_NORM) == 0 ||
|
2001-04-12 00:08:26 +00:00
|
|
|
data->fcdPosition <= data->pos ||
|
2001-04-25 23:28:55 +00:00
|
|
|
data->string == data->pos ||
|
2001-04-20 22:29:53 +00:00
|
|
|
ch < ZERO_CC_LIMIT_) {
|
2001-04-12 00:08:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
if (ch < NFC_ZERO_CC_BLOCK_LIMIT_) {
|
|
|
|
/* if next character is FCD */
|
|
|
|
if (data->pos == data->string) {
|
|
|
|
/* First char of string is always OK for FCD check */
|
|
|
|
break;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/* Not first char of string, do the FCD fast test */
|
|
|
|
if (*(data->pos - 1) < NFC_ZERO_CC_BLOCK_LIMIT_) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
/* Need a more complete FCD check and possible normalization. */
|
2001-04-20 22:29:53 +00:00
|
|
|
if (collPrevIterFCD(data)) {
|
|
|
|
collPrevIterNormalize(data);
|
|
|
|
}
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
if ((data->flags & UCOL_ITER_INNORMBUF) == 0) {
|
|
|
|
/* No normalization. Go ahead and process the char. */
|
|
|
|
break;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Some normalization happened.
|
|
|
|
Next loop picks up a char from the normalization buffer.
|
2001-04-12 00:08:26 +00:00
|
|
|
*/
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
/* attempt to handle contractions, after removal of the backwards
|
2001-05-17 01:06:25 +00:00
|
|
|
contraction
|
|
|
|
*/
|
|
|
|
if (!isAtStartPrevIterate(data) && ucol_contractionEndCP(ch, coll)) {
|
|
|
|
result = UCOL_CONTRACTION;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-05-17 01:06:25 +00:00
|
|
|
if (ch <= 0xFF) {
|
|
|
|
result = coll->latinOneMapping[ch];
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-05-17 01:06:25 +00:00
|
|
|
if ((data->flags & UCOL_ITER_INNORMBUF) == 0 &&
|
|
|
|
UCOL_ISTHAIBASECONSONANT(ch) && data->pos > data->string &&
|
|
|
|
UCOL_ISTHAIPREVOWEL(*(data->pos -1)))
|
|
|
|
{
|
|
|
|
result = UCOL_THAI;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = ucmp32_get(coll->mapping, ch);
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result >= UCOL_NOT_FOUND) {
|
|
|
|
result = getSpecialPrevCE(coll, result, data, status);
|
|
|
|
if (result == UCOL_NOT_FOUND) {
|
|
|
|
result = ucol_getPrevUCA(ch, data, status);
|
2001-04-18 19:31:05 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-04-12 00:08:26 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
/* ucol_getPrevCE, out-of-line version for use from other files. */
|
|
|
|
U_CAPI uint32_t ucol_getPrevCE(const UCollator *coll, collIterate *data,
|
|
|
|
UErrorCode *status) {
|
|
|
|
return ucol_IGetPrevCE(coll, data, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-09 00:50:37 +00:00
|
|
|
/* this should be connected to special Jamo handling */
|
|
|
|
uint32_t ucol_getFirstCE(const UCollator *coll, UChar u, UErrorCode *status) {
|
|
|
|
collIterate colIt;
|
|
|
|
uint32_t order;
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(coll, &u, 1, &colIt);
|
2001-04-18 19:31:05 +00:00
|
|
|
order = ucol_IGetNextCE(coll, &colIt, status);
|
2001-04-06 23:37:48 +00:00
|
|
|
/*UCOL_GETNEXTCE(order, coll, colIt, status);*/
|
2001-03-09 00:50:37 +00:00
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* This function tries to get a CE from UCA, which should be always around */
|
|
|
|
/* UChar is passed in in order to speed things up */
|
|
|
|
/* here is also the generation of implicit CEs */
|
2001-03-09 00:50:37 +00:00
|
|
|
uint32_t ucol_getNextUCA(UChar ch, collIterate *collationSource, UErrorCode *status) {
|
2001-01-09 00:52:18 +00:00
|
|
|
uint32_t order;
|
2001-05-24 22:37:03 +00:00
|
|
|
|
|
|
|
/* if we got here, the codepoint MUST be over 0xFF - so we look directly in the trie */
|
|
|
|
order = ucmp32_get(UCA->mapping, ch);
|
|
|
|
|
|
|
|
if(order > UCOL_NOT_FOUND) { /* UCA also gives us a special CE */
|
2001-04-23 01:53:49 +00:00
|
|
|
order = getSpecialCE(UCA, order, collationSource, status);
|
|
|
|
}
|
2001-05-24 22:37:03 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
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;
|
2001-04-23 01:53:49 +00:00
|
|
|
const uint32_t
|
2001-05-24 22:37:03 +00:00
|
|
|
SBase = 0xAC00, LBase = 0x1100, VBase = 0x1161, TBase = 0x11A7,
|
|
|
|
LCount = 19, VCount = 21, TCount = 28,
|
|
|
|
NCount = VCount * TCount, // 588
|
|
|
|
SCount = LCount * NCount; // 11172
|
2001-02-12 08:37:21 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
// once we have failed to find a match for codepoint cp, and are in the implicit code.
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
uint32_t L = ch - SBase;
|
|
|
|
//if (ch < SLimit) { // since it is unsigned, catchs zero case too
|
|
|
|
if (L < SCount) { // since it is unsigned, catchs zero case too
|
2001-02-12 08:37:21 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
// divide into pieces
|
2001-02-12 08:37:21 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
uint32_t T = L % TCount; // we do it in this order since some compilers can do % and / in one operation
|
|
|
|
L /= TCount;
|
|
|
|
uint32_t V = L % VCount;
|
|
|
|
L /= VCount;
|
2001-02-12 08:37:21 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
// offset them
|
2001-02-12 08:37:21 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
L += LBase;
|
|
|
|
V += VBase;
|
|
|
|
T += TBase;
|
2001-02-12 08:37:21 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
// return the first CE, but first put the rest into the expansion buffer
|
|
|
|
if (!collationSource->coll->image->jamoSpecial) { // FAST PATH
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
*(collationSource->CEpos++) = ucmp32_get(UCA->mapping, V);
|
|
|
|
if (T != TBase) {
|
|
|
|
*(collationSource->CEpos++) = ucmp32_get(UCA->mapping, T);
|
|
|
|
}
|
2001-03-22 18:45:31 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
return ucmp32_get(UCA->mapping, L); // return first one
|
|
|
|
|
|
|
|
} else { // Jamo is Special
|
|
|
|
collIterate jamos;
|
|
|
|
UChar jamoString[3];
|
|
|
|
uint32_t CE = UCOL_NOT_FOUND;
|
|
|
|
const UCollator *collator = collationSource->coll;
|
|
|
|
jamoString[0] = (UChar)L;
|
|
|
|
jamoString[1] = (UChar)V;
|
|
|
|
if (T != TBase) {
|
|
|
|
jamoString[2] = (UChar)T;
|
|
|
|
IInit_collIterate(collator, jamoString, 3, &jamos);
|
|
|
|
} else {
|
|
|
|
IInit_collIterate(collator, jamoString, 2, &jamos);
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
CE = ucol_IGetNextCE(collator, &jamos, status);
|
2001-03-22 18:45:31 +00:00
|
|
|
|
2001-05-24 22:37:03 +00:00
|
|
|
while(CE != UCOL_NO_MORE_CES) {
|
|
|
|
*(collationSource->CEpos++) = CE;
|
|
|
|
CE = ucol_IGetNextCE(collator, &jamos, status);
|
2001-02-12 08:37:21 +00:00
|
|
|
}
|
2001-05-24 22:37:03 +00:00
|
|
|
return *(collationSource->toReturn++);
|
|
|
|
}
|
2001-02-12 08:37:21 +00:00
|
|
|
}
|
|
|
|
|
2001-04-19 23:49:03 +00:00
|
|
|
uint32_t cp = 0;
|
|
|
|
|
2001-01-22 23:48:48 +00:00
|
|
|
if(UTF_IS_FIRST_SURROGATE(ch)) {
|
2001-04-06 23:37:48 +00:00
|
|
|
if( (((collationSource->flags & UCOL_ITER_HASLEN) == 0 ) || (collationSource->pos<collationSource->endp)) &&
|
2001-02-07 00:57:39 +00:00
|
|
|
UTF_IS_SECOND_SURROGATE((nextChar=*collationSource->pos))) {
|
2001-05-16 18:23:26 +00:00
|
|
|
cp = ((((uint32_t)ch)<<10UL)+(nextChar)-(((uint32_t)0xd800<<10UL)+0xdc00-0x10000));
|
2001-01-22 23:48:48 +00:00
|
|
|
collationSource->pos++;
|
|
|
|
if ((cp & 0xFFFE) == 0xFFFE || (0xD800 <= cp && cp <= 0xDC00)) {
|
|
|
|
return 0; /* illegal code value, use completely ignoreable! */
|
|
|
|
}
|
|
|
|
/* This is a code point minus 0x10000, that's what algorithm requires */
|
2001-04-19 23:49:03 +00:00
|
|
|
//order = 0xE0010303 | (cp & 0xFFE00) << 8;
|
|
|
|
//*(collationSource->CEpos++) = 0x80200080 | (cp & 0x001FF) << 22;
|
2001-01-22 23:48:48 +00:00
|
|
|
} else {
|
|
|
|
return 0; /* completely ignorable */
|
|
|
|
}
|
2001-01-11 22:03:38 +00:00
|
|
|
} else {
|
|
|
|
/* otherwise */
|
2001-01-22 23:48:48 +00:00
|
|
|
if(UTF_IS_SECOND_SURROGATE((ch)) || (ch & 0xFFFE) == 0xFFFE) {
|
|
|
|
return 0; /* completely ignorable */
|
|
|
|
}
|
2001-04-19 23:49:03 +00:00
|
|
|
cp = ch;
|
2001-01-11 22:03:38 +00:00
|
|
|
/* Make up an artifical CE from code point as per UCA */
|
2001-04-19 23:49:03 +00:00
|
|
|
//order = 0xD0800303 | (ch & 0xF000) << 12 | (ch & 0x0FE0) << 11;
|
|
|
|
//*(collationSource->CEpos++) = 0x04000080 | (ch & 0x001F) << 27;
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-24 03:18:54 +00:00
|
|
|
we must skip all 00, 01, 02 bytes, so most bytes have 253 values
|
|
|
|
we must leave a gap of 01 between all values of the last byte, so the last byte has 126 values (3 byte case)
|
|
|
|
we shift so that HAN all has the same first primary, for compression.
|
|
|
|
for the 4 byte case, we make the gap as large as we can fit.
|
|
|
|
Three byte forms are EC xx xx, ED xx xx, EE xx xx (with a gap of 1)
|
|
|
|
Four byte forms (most supplementaries) are EF xx xx xx (with a gap of LAST2_MULTIPLIER == 14)
|
|
|
|
*/
|
2001-04-23 01:53:49 +00:00
|
|
|
int32_t last0 = cp - IMPLICIT_BOUNDARY_;
|
2001-04-19 23:49:03 +00:00
|
|
|
uint32_t r = 0;
|
2001-05-17 23:14:44 +00:00
|
|
|
uint32_t hanFixup = 0;
|
2001-04-19 23:49:03 +00:00
|
|
|
|
2001-05-17 23:14:44 +00:00
|
|
|
if ((0x3400 <= cp && cp <= 0x4DB5) || (0x4E00 <= cp && cp <= 0x9FA5) || (0xF900 <= cp && cp <= 0xFA2D)) {
|
2001-05-18 18:09:53 +00:00
|
|
|
hanFixup = 0x04000000;
|
2001-05-17 23:14:44 +00:00
|
|
|
}
|
2001-04-19 23:49:03 +00:00
|
|
|
if (last0 < 0) {
|
2001-04-23 01:53:49 +00:00
|
|
|
cp += IMPLICIT_HAN_SHIFT_; // shift so HAN shares single block
|
|
|
|
int32_t last1 = cp / IMPLICIT_LAST_COUNT_;
|
|
|
|
last0 = cp % IMPLICIT_LAST_COUNT_;
|
|
|
|
int32_t last2 = last1 / IMPLICIT_OTHER_COUNT_;
|
|
|
|
last1 %= IMPLICIT_OTHER_COUNT_;
|
2001-05-17 23:14:44 +00:00
|
|
|
r = 0xEC030300 - hanFixup + (last2 << 24) + (last1 << 16) + (last0 << 9);
|
2001-04-19 23:49:03 +00:00
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
int32_t last1 = last0 / IMPLICIT_LAST_COUNT2_;
|
|
|
|
last0 %= IMPLICIT_LAST_COUNT2_;
|
|
|
|
int32_t last2 = last1 / IMPLICIT_OTHER_COUNT_;
|
|
|
|
last1 %= IMPLICIT_OTHER_COUNT_;
|
2001-05-17 23:14:44 +00:00
|
|
|
r = 0xEF030303 - hanFixup + (last2 << 16) + (last1 << 8) + (last0 * IMPLICIT_LAST2_MULTIPLIER_);
|
2001-01-11 22:03:38 +00:00
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
order = (r & UCOL_PRIMARYMASK) | 0x00000505;
|
2001-05-10 22:33:50 +00:00
|
|
|
*(collationSource->CEpos++) = ((r & 0x0000FFFF)<<16) | 0x000000C0;
|
2001-04-19 23:49:03 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
}
|
|
|
|
return order; /* return the CE */
|
|
|
|
}
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
|
|
|
* This function tries to get a CE from UCA, which should be always around
|
|
|
|
* UChar is passed in in order to speed things up here is also the generation
|
|
|
|
* of implicit CEs
|
2001-02-20 00:26:50 +00:00
|
|
|
*/
|
2001-04-23 01:53:49 +00:00
|
|
|
uint32_t ucol_getPrevUCA(UChar ch, collIterate *collationSource,
|
|
|
|
UErrorCode *status)
|
2001-02-20 00:26:50 +00:00
|
|
|
{
|
|
|
|
uint32_t order;
|
2001-06-06 23:26:50 +00:00
|
|
|
if (!isAtStartPrevIterate(collationSource) &&
|
2001-05-17 01:06:25 +00:00
|
|
|
ucol_contractionEndCP(ch, collationSource->coll)) {
|
|
|
|
order = UCOL_CONTRACTION;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-05-25 16:54:06 +00:00
|
|
|
/* if (ch <= 0xFF) {
|
2001-05-17 01:06:25 +00:00
|
|
|
order = UCA->latinOneMapping[ch];
|
|
|
|
}
|
|
|
|
else {
|
2001-05-25 16:54:06 +00:00
|
|
|
*/
|
2001-05-17 01:06:25 +00:00
|
|
|
order = ucmp32_get(UCA->mapping, ch);
|
2001-05-25 16:54:06 +00:00
|
|
|
//}
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
if (order > UCOL_NOT_FOUND) {
|
2001-04-23 01:53:49 +00:00
|
|
|
order = getSpecialPrevCE(UCA, order, collationSource, status);
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
if (order == UCOL_NOT_FOUND)
|
|
|
|
{
|
2001-04-20 22:29:53 +00:00
|
|
|
uint32_t cp = 0;
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
2001-02-20 00:26:50 +00:00
|
|
|
This is where we have to resort to algorithmical generation.
|
2001-04-23 01:53:49 +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
|
2001-02-20 00:26:50 +00:00
|
|
|
*/
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_t
|
2001-02-20 00:26:50 +00:00
|
|
|
SBase = 0xAC00, LBase = 0x1100, VBase = 0x1161, TBase = 0x11A7,
|
|
|
|
LCount = 19, VCount = 21, TCount = 28,
|
2001-03-07 21:01:53 +00:00
|
|
|
NCount = VCount * TCount, /* 588 */
|
|
|
|
SCount = LCount * NCount; /* 11172 */
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
once we have failed to find a match for codepoint cp, and are in the
|
2001-02-20 00:26:50 +00:00
|
|
|
implicit code.
|
|
|
|
*/
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_t L = ch - SBase;
|
2001-04-23 01:53:49 +00:00
|
|
|
if (L < SCount)
|
2001-02-20 00:26:50 +00:00
|
|
|
{ /* since it is unsigned, catchs zero case too */
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
2001-02-20 00:26:50 +00:00
|
|
|
divide into pieces.
|
2001-04-23 01:53:49 +00:00
|
|
|
we do it in this order since some compilers can do % and / in one
|
2001-02-20 00:26:50 +00:00
|
|
|
operation
|
|
|
|
*/
|
2001-04-23 01:53:49 +00:00
|
|
|
uint32_t T = L % TCount;
|
2001-02-20 00:26:50 +00:00
|
|
|
L /= TCount;
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_t V = L % VCount;
|
2001-02-20 00:26:50 +00:00
|
|
|
L /= VCount;
|
|
|
|
|
|
|
|
/* offset them */
|
|
|
|
L += LBase;
|
|
|
|
V += VBase;
|
|
|
|
T += TBase;
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
2001-02-20 00:26:50 +00:00
|
|
|
return the first CE, but first put the rest into the expansion buffer
|
|
|
|
*/
|
2001-04-23 01:53:49 +00:00
|
|
|
if (!collationSource->coll->image->jamoSpecial)
|
|
|
|
{
|
|
|
|
*(collationSource->CEpos ++) = ucmp32_get(UCA->mapping, L);
|
2001-02-20 00:26:50 +00:00
|
|
|
*(collationSource->CEpos ++) = ucmp32_get(UCA->mapping, V);
|
|
|
|
if (T != TBase)
|
2001-02-23 23:36:42 +00:00
|
|
|
*(collationSource->CEpos ++) = ucmp32_get(UCA->mapping, T);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-02-23 23:36:42 +00:00
|
|
|
collationSource->toReturn = collationSource->CEpos - 1;
|
|
|
|
return *(collationSource->toReturn);
|
2001-04-23 01:53:49 +00:00
|
|
|
} else {
|
2001-03-22 18:45:31 +00:00
|
|
|
collIterate jamos;
|
|
|
|
UChar jamoString[3];
|
|
|
|
uint32_t CE = UCOL_NOT_FOUND;
|
|
|
|
const UCollator *collator = collationSource->coll;
|
2001-03-28 20:12:12 +00:00
|
|
|
jamoString[0] = (UChar)L;
|
|
|
|
jamoString[1] = (UChar)V;
|
2001-03-22 18:45:31 +00:00
|
|
|
if (T != TBase) {
|
2001-03-28 20:12:12 +00:00
|
|
|
jamoString[2] = (UChar)T;
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(collator, jamoString, 3, &jamos);
|
2001-03-22 18:45:31 +00:00
|
|
|
} else {
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(collator, jamoString, 2, &jamos);
|
2001-03-22 18:45:31 +00:00
|
|
|
}
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
CE = ucol_IGetNextCE(collator, &jamos, status);
|
2001-03-22 18:45:31 +00:00
|
|
|
|
|
|
|
while(CE != UCOL_NO_MORE_CES) {
|
|
|
|
*(collationSource->CEpos++) = CE;
|
2001-04-18 19:31:05 +00:00
|
|
|
CE = ucol_IGetNextCE(collator, &jamos, status);
|
2001-03-22 18:45:31 +00:00
|
|
|
}
|
|
|
|
collationSource->toReturn = collationSource->CEpos - 1;
|
|
|
|
return *(collationSource->toReturn);
|
2001-02-20 00:26:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
if (UTF_IS_SECOND_SURROGATE(ch))
|
2001-02-20 00:26:50 +00:00
|
|
|
{
|
2001-04-20 22:29:53 +00:00
|
|
|
UChar prevChar;
|
|
|
|
UChar *prev;
|
2001-05-25 16:54:06 +00:00
|
|
|
if (isAtStartPrevIterate(collationSource)) {
|
2001-04-20 22:29:53 +00:00
|
|
|
/* we are at the start of the string, wrong place to be at */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (collationSource->pos != collationSource->writableBuffer) {
|
|
|
|
prev = collationSource->pos - 1;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-04-20 22:29:53 +00:00
|
|
|
else {
|
|
|
|
prev = collationSource->fcdPosition;
|
|
|
|
}
|
|
|
|
prevChar = *prev;
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
/* Handles Han and Supplementary characters here.*/
|
2001-05-11 01:13:08 +00:00
|
|
|
if (UTF_IS_FIRST_SURROGATE(prevChar))
|
2001-04-23 01:53:49 +00:00
|
|
|
{
|
2001-05-16 18:23:26 +00:00
|
|
|
//cp = ((prevChar << 10UL) + ch - ((0xd800 << 10UL) + 0xdc00));
|
|
|
|
cp = ((((uint32_t)prevChar)<<10UL)+(ch)-(((uint32_t)0xd800<<10UL)+0xdc00-0x10000));
|
2001-04-20 22:29:53 +00:00
|
|
|
collationSource->pos = prev;
|
2001-04-23 01:53:49 +00:00
|
|
|
if ((cp & 0xFFFE) == 0xFFFE || (0xD800 <= cp && cp <= 0xDC00)) {
|
|
|
|
return 0; /* illegal code value, use completely ignoreable! */
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0; /* completely ignorable */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-02-20 00:26:50 +00:00
|
|
|
{
|
|
|
|
/* otherwise */
|
2001-03-07 21:01:53 +00:00
|
|
|
if (UTF_IS_FIRST_SURROGATE(ch) || (ch & 0xFFFE) == 0xFFFE) {
|
2001-02-20 00:26:50 +00:00
|
|
|
return 0; /* completely ignorable */
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
2001-04-20 22:29:53 +00:00
|
|
|
cp = ch;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
/* we must skip all 00, 01, 02 bytes, so most bytes have 253 values
|
|
|
|
we must leave a gap of 01 between all values of the last byte, so the last byte has 126 values (3 byte case)
|
|
|
|
we shift so that HAN all has the same first primary, for compression.
|
|
|
|
for the 4 byte case, we make the gap as large as we can fit.
|
|
|
|
Three byte forms are EC xx xx, ED xx xx, EE xx xx (with a gap of 1)
|
|
|
|
Four byte forms (most supplementaries) are EF xx xx xx (with a gap of LAST2_MULTIPLIER == 14)
|
2001-05-11 01:13:08 +00:00
|
|
|
*/
|
2001-04-20 22:29:53 +00:00
|
|
|
int32_t last0 = cp - IMPLICIT_BOUNDARY_;
|
|
|
|
uint32_t r = 0;
|
2001-05-17 23:14:44 +00:00
|
|
|
uint32_t hanFixup = 0;
|
|
|
|
|
|
|
|
if ((0x3400 <= cp && cp <= 0x4DB5) || (0x4E00 <= cp && cp <= 0x9FA5) || (0xF900 <= cp && cp <= 0xFA2D)) {
|
2001-05-18 18:09:53 +00:00
|
|
|
hanFixup = 0x04000000;
|
2001-05-17 23:14:44 +00:00
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
if (last0 < 0) {
|
|
|
|
cp += IMPLICIT_HAN_SHIFT_; // shift so HAN shares single block
|
|
|
|
int32_t last1 = cp / IMPLICIT_LAST_COUNT_;
|
|
|
|
last0 = cp % IMPLICIT_LAST_COUNT_;
|
|
|
|
int32_t last2 = last1 / IMPLICIT_OTHER_COUNT_;
|
|
|
|
last1 %= IMPLICIT_OTHER_COUNT_;
|
2001-05-17 23:14:44 +00:00
|
|
|
r = 0xEC030300 - hanFixup + (last2 << 24) + (last1 << 16) + (last0 << 9);
|
2001-04-20 22:29:53 +00:00
|
|
|
} else {
|
|
|
|
int32_t last1 = last0 / IMPLICIT_LAST_COUNT2_;
|
|
|
|
last0 %= IMPLICIT_LAST_COUNT2_;
|
|
|
|
int32_t last2 = last1 / IMPLICIT_OTHER_COUNT_;
|
|
|
|
last1 %= IMPLICIT_OTHER_COUNT_;
|
2001-05-17 23:14:44 +00:00
|
|
|
r = 0xEF030303 - hanFixup + (last2 << 16) + (last1 << 8) +
|
2001-04-20 22:29:53 +00:00
|
|
|
(last0 * IMPLICIT_LAST2_MULTIPLIER_);
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
*(collationSource->CEpos++) = (r & UCOL_PRIMARYMASK) | 0x00000505;
|
2001-02-23 23:36:42 +00:00
|
|
|
collationSource->toReturn = collationSource->CEpos;
|
2001-05-10 22:33:50 +00:00
|
|
|
order = ((r & 0x0000FFFF)<<16) | 0x000000C0;
|
2001-02-20 00:26:50 +00:00
|
|
|
}
|
|
|
|
return order; /* return the CE */
|
|
|
|
}
|
|
|
|
|
2001-04-24 03:18:54 +00:00
|
|
|
/**
|
2001-05-11 01:13:08 +00:00
|
|
|
* Inserts the argument character into the end of the buffer pushing back the
|
2001-04-24 03:18:54 +00:00
|
|
|
* null terminator.
|
2001-04-28 01:22:25 +00:00
|
|
|
* @param data collIterate struct data
|
|
|
|
* @param pNull pointer to the null termination
|
2001-04-24 03:18:54 +00:00
|
|
|
* @param ch character to be appended
|
2001-04-25 23:28:55 +00:00
|
|
|
* @return the position of the new addition
|
2001-04-24 03:18:54 +00:00
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
inline UChar * insertBufferEnd(collIterate *data, UChar *pNull, UChar ch)
|
2001-04-24 03:18:54 +00:00
|
|
|
{
|
|
|
|
uint32_t size = data->writableBufSize;
|
|
|
|
UChar *newbuffer;
|
|
|
|
const uint32_t incsize = 5;
|
|
|
|
|
2001-04-28 01:22:25 +00:00
|
|
|
if ((data->writableBuffer + size) > (pNull + 1)) {
|
|
|
|
*pNull = ch;
|
|
|
|
*(pNull + 1) = 0;
|
|
|
|
return pNull;
|
2001-04-24 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-24 03:18:54 +00:00
|
|
|
buffer will always be null terminated at the end.
|
|
|
|
giving extra space since it is likely that more characters will be added.
|
|
|
|
*/
|
|
|
|
size += incsize;
|
|
|
|
newbuffer = (UChar *)uprv_malloc(sizeof(UChar) * size);
|
2001-05-11 01:13:08 +00:00
|
|
|
uprv_memcpy(newbuffer, data->writableBuffer,
|
2001-04-24 03:18:54 +00:00
|
|
|
data->writableBufSize * sizeof(UChar));
|
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(data);
|
2001-04-24 03:18:54 +00:00
|
|
|
data->writableBufSize = size;
|
|
|
|
data->writableBuffer = newbuffer;
|
2001-04-25 23:28:55 +00:00
|
|
|
|
|
|
|
newbuffer = newbuffer + data->writableBufSize;
|
|
|
|
*newbuffer = ch;
|
|
|
|
*(newbuffer + 1) = 0;
|
|
|
|
return newbuffer;
|
2001-04-24 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
/**
|
2001-05-11 01:13:08 +00:00
|
|
|
* Inserts the argument string into the end of the buffer pushing back the
|
2001-05-10 17:49:24 +00:00
|
|
|
* null terminator.
|
|
|
|
* @param data collIterate struct data
|
|
|
|
* @param pNull pointer to the null termination
|
|
|
|
* @param string to be appended
|
|
|
|
* @param length of the string to be appended
|
|
|
|
* @return the position of the new addition
|
|
|
|
*/
|
|
|
|
inline UChar * insertBufferEnd(collIterate *data, UChar *pNull, UChar *str,
|
2001-06-03 23:40:41 +00:00
|
|
|
int32_t length)
|
2001-05-10 17:49:24 +00:00
|
|
|
{
|
|
|
|
uint32_t size = pNull - data->writableBuffer;
|
|
|
|
UChar *newbuffer;
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
if (data->writableBuffer + data->writableBufSize > pNull + length + 1) {
|
|
|
|
uprv_memcpy(pNull, str, length * sizeof(UChar));
|
|
|
|
*(pNull + length) = 0;
|
|
|
|
return pNull;
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-05-10 17:49:24 +00:00
|
|
|
buffer will always be null terminated at the end.
|
|
|
|
giving extra space since it is likely that more characters will be added.
|
|
|
|
*/
|
|
|
|
newbuffer = (UChar *)uprv_malloc(sizeof(UChar) * (size + length + 1));
|
|
|
|
uprv_memcpy(newbuffer, data->writableBuffer, size * sizeof(UChar));
|
|
|
|
uprv_memcpy(newbuffer + size, str, length * sizeof(UChar));
|
|
|
|
|
|
|
|
freeHeapWritableBuffer(data);
|
|
|
|
data->writableBufSize = size + length + 1;
|
|
|
|
data->writableBuffer = newbuffer;
|
|
|
|
|
|
|
|
return newbuffer;
|
|
|
|
}
|
|
|
|
|
2001-04-24 03:18:54 +00:00
|
|
|
/**
|
|
|
|
* Special normalization function for contraction in the forwards iterator.
|
|
|
|
* This normalization sequence will place the current character at source->pos
|
|
|
|
* and its following normalized sequence into the buffer.
|
2001-05-11 01:13:08 +00:00
|
|
|
* The fcd position, pos will be changed.
|
2001-04-24 03:18:54 +00:00
|
|
|
* pos will now point to positions in the buffer.
|
|
|
|
* Flags will be changed accordingly.
|
|
|
|
* @param data collation iterator data
|
|
|
|
*/
|
|
|
|
inline void normalizeNextContraction(collIterate *data)
|
2001-05-11 01:13:08 +00:00
|
|
|
{
|
2001-04-24 03:18:54 +00:00
|
|
|
UChar *buffer = data->writableBuffer;
|
|
|
|
uint32_t buffersize = data->writableBufSize;
|
|
|
|
uint32_t strsize;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-04-25 23:28:55 +00:00
|
|
|
/* because the pointer points to the next character */
|
2001-05-11 01:13:08 +00:00
|
|
|
UChar *pStart = data->pos - 1;
|
2001-04-24 03:18:54 +00:00
|
|
|
UChar *pEnd;
|
|
|
|
uint32_t normLen;
|
|
|
|
UChar *pStartNorm;
|
|
|
|
|
2001-04-25 23:28:55 +00:00
|
|
|
if ((data->flags & UCOL_ITER_INNORMBUF) == 0) {
|
2001-04-24 03:18:54 +00:00
|
|
|
*data->writableBuffer = *(pStart - 1);
|
|
|
|
strsize = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strsize = u_strlen(data->writableBuffer);
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
pEnd = data->fcdPosition;
|
|
|
|
|
|
|
|
normLen = unorm_normalize(pStart, pEnd - pStart, UNORM_NFD, 0, buffer, 0,
|
2001-04-24 03:18:54 +00:00
|
|
|
&status);
|
|
|
|
|
|
|
|
if (buffersize <= normLen + strsize) {
|
|
|
|
uint32_t size = strsize + normLen + 1;
|
|
|
|
UChar *temp = (UChar *)uprv_malloc(size * sizeof(UChar));
|
|
|
|
uprv_memcpy(temp, buffer, sizeof(UChar) * strsize);
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(data);
|
2001-04-24 03:18:54 +00:00
|
|
|
data->writableBuffer = temp;
|
|
|
|
data->writableBufSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
pStartNorm = buffer + strsize;
|
|
|
|
/* null-termination will be added here */
|
2001-05-11 01:13:08 +00:00
|
|
|
unorm_normalize(pStart, pEnd - pStart, UNORM_NFD, 0, pStartNorm,
|
2001-04-25 23:28:55 +00:00
|
|
|
normLen + 1, &status);
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-24 03:18:54 +00:00
|
|
|
data->pos = data->writableBuffer + strsize;
|
|
|
|
data->origFlags = data->flags;
|
|
|
|
data->flags |= UCOL_ITER_INNORMBUF;
|
|
|
|
data->flags &= ~(UCOL_ITER_NORM | UCOL_ITER_HASLEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contraction character management function that returns the next character
|
|
|
|
* for the forwards iterator.
|
2001-05-11 01:13:08 +00:00
|
|
|
* Does nothing if the next character is in buffer and not the first character
|
2001-04-24 03:18:54 +00:00
|
|
|
* in it.
|
|
|
|
* Else it checks next character in data string to see if it is normalizable.
|
|
|
|
* If it is not, the character is simply copied into the buffer, else
|
2001-05-11 01:13:08 +00:00
|
|
|
* the whole normalized substring is copied into the buffer, including the
|
2001-04-24 03:18:54 +00:00
|
|
|
* current character.
|
|
|
|
* @param data collation element iterator data
|
|
|
|
* @return next character
|
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
inline UChar getNextNormalizedChar(collIterate *data)
|
2001-04-24 03:18:54 +00:00
|
|
|
{
|
2001-04-25 23:28:55 +00:00
|
|
|
UChar nextch;
|
2001-04-24 03:18:54 +00:00
|
|
|
UChar ch;
|
2001-06-06 23:26:50 +00:00
|
|
|
if ((data->flags & (UCOL_ITER_NORM | UCOL_ITER_INNORMBUF)) == 0 ) {
|
|
|
|
/* if no normalization and not in buffer. */
|
|
|
|
return *(data->pos ++);
|
|
|
|
}
|
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
UChar *pEndWritableBuffer = NULL;
|
2001-06-06 23:26:50 +00:00
|
|
|
UBool innormbuf = (UBool)(data->flags & UCOL_ITER_INNORMBUF);
|
|
|
|
if ((innormbuf && *data->pos != 0) ||
|
2001-05-11 01:13:08 +00:00
|
|
|
(data->fcdPosition != NULL && !innormbuf &&
|
2001-05-10 17:49:24 +00:00
|
|
|
data->pos < data->fcdPosition)) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-24 03:18:54 +00:00
|
|
|
if next character is in normalized buffer, no further normalization
|
|
|
|
is required
|
|
|
|
*/
|
|
|
|
return *(data->pos ++);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->flags & UCOL_ITER_HASLEN) {
|
|
|
|
/* in data string */
|
|
|
|
if (data->pos + 1 == data->endp) {
|
2001-04-25 23:28:55 +00:00
|
|
|
return *(data->pos ++);
|
2001-04-24 03:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-04-26 01:15:34 +00:00
|
|
|
if (innormbuf) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
|
|
|
in writable buffer, at this point fcdPosition can not be
|
2001-04-24 03:18:54 +00:00
|
|
|
pointing to the end of the data string. see contracting tag.
|
|
|
|
*/
|
2001-04-25 23:28:55 +00:00
|
|
|
if (*(data->fcdPosition + 1) == 0 ||
|
|
|
|
data->fcdPosition + 1 == data->endp) {
|
|
|
|
/* at the end of the string, dump it into the normalizer */
|
2001-05-11 01:13:08 +00:00
|
|
|
data->pos = insertBufferEnd(data, data->pos,
|
2001-04-28 01:22:25 +00:00
|
|
|
*(data->fcdPosition)) + 1;
|
2001-04-25 23:28:55 +00:00
|
|
|
return *(data->fcdPosition ++);
|
2001-04-24 03:18:54 +00:00
|
|
|
}
|
2001-05-10 17:49:24 +00:00
|
|
|
pEndWritableBuffer = data->pos;
|
2001-04-24 03:18:54 +00:00
|
|
|
data->pos = data->fcdPosition;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (*(data->pos + 1) == 0) {
|
|
|
|
return *(data->pos ++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-25 23:28:55 +00:00
|
|
|
ch = *data->pos ++;
|
|
|
|
nextch = *data->pos;
|
2001-05-11 01:13:08 +00:00
|
|
|
|
|
|
|
/*
|
2001-04-24 03:18:54 +00:00
|
|
|
* if the current character is not fcd.
|
|
|
|
* Trailing combining class == 0.
|
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
if ((data->fcdPosition == NULL || data->fcdPosition < data->pos) &&
|
2001-04-24 03:18:54 +00:00
|
|
|
(nextch >= NFC_ZERO_CC_BLOCK_LIMIT_ ||
|
2001-04-25 23:28:55 +00:00
|
|
|
ch >= NFC_ZERO_CC_BLOCK_LIMIT_)) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
|
|
|
Need a more complete FCD check and possible normalization.
|
|
|
|
normalize substring will be appended to buffer
|
2001-04-24 03:18:54 +00:00
|
|
|
*/
|
2001-04-25 23:28:55 +00:00
|
|
|
if (collIterFCD(data)) {
|
2001-04-24 03:18:54 +00:00
|
|
|
normalizeNextContraction(data);
|
2001-04-25 23:28:55 +00:00
|
|
|
return *(data->pos ++);
|
|
|
|
}
|
2001-05-10 17:49:24 +00:00
|
|
|
else if (innormbuf) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/* fcdposition shifted even when there's no normalization, if we
|
|
|
|
don't input the rest into this, we'll get the wrong position when
|
2001-05-10 17:49:24 +00:00
|
|
|
we reach the end of the writableBuffer */
|
2001-06-03 23:40:41 +00:00
|
|
|
int32_t length = data->fcdPosition - data->pos + 1;
|
2001-05-11 01:13:08 +00:00
|
|
|
data->pos = insertBufferEnd(data, pEndWritableBuffer,
|
2001-05-10 17:49:24 +00:00
|
|
|
data->pos - 1, length);
|
|
|
|
return *(data->pos ++);
|
|
|
|
}
|
2001-04-24 03:18:54 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-26 01:15:34 +00:00
|
|
|
if (innormbuf) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
|
|
|
no normalization is to be done hence only one character will be
|
2001-04-24 03:18:54 +00:00
|
|
|
appended to the buffer.
|
|
|
|
*/
|
2001-05-10 17:49:24 +00:00
|
|
|
data->pos = insertBufferEnd(data, pEndWritableBuffer, ch) + 1;
|
2001-04-24 03:18:54 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-24 03:18:54 +00:00
|
|
|
/* points back to the pos in string */
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
/**
|
|
|
|
* Function to copy the buffer into writableBuffer and sets the fcd position to
|
2001-05-14 18:57:54 +00:00
|
|
|
* the correct position
|
|
|
|
* @param source data string source
|
|
|
|
* @param buffer character buffer
|
|
|
|
* @param tempdb current position in buffer that has been used up
|
|
|
|
*/
|
2001-06-06 23:26:50 +00:00
|
|
|
inline void setDiscontiguosAttribute(collIterate *source, UChar *buffer,
|
2001-05-14 18:57:54 +00:00
|
|
|
UChar *tempdb)
|
|
|
|
{
|
2001-06-06 23:26:50 +00:00
|
|
|
/* okay confusing part here. to ensure that the skipped characters are
|
|
|
|
considered later, we need to place it in the appropriate position in the
|
|
|
|
normalization buffer and reassign the pos pointer. simple case if pos
|
|
|
|
reside in string, simply copy to normalization buffer and
|
|
|
|
fcdposition = pos, pos = start of normalization buffer. if pos in
|
|
|
|
normalization buffer, we'll insert the copy infront of pos and point pos
|
|
|
|
to the start of the normalization buffer. why am i doing these copies?
|
|
|
|
well, so that the whole chunk of codes in the getNextCE, getSpecialCE does
|
2001-05-14 18:57:54 +00:00
|
|
|
not require any changes, which be really painful. */
|
|
|
|
uint32_t length = u_strlen(buffer);;
|
|
|
|
if (source->flags & UCOL_ITER_INNORMBUF) {
|
|
|
|
u_strcpy(tempdb, source->pos);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
source->fcdPosition = source->pos;
|
|
|
|
source->origFlags = source->flags;
|
|
|
|
source->flags |= UCOL_ITER_INNORMBUF;
|
|
|
|
source->flags &= ~(UCOL_ITER_NORM | UCOL_ITER_HASLEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length >= source->writableBufSize) {
|
|
|
|
freeHeapWritableBuffer(source);
|
|
|
|
source->writableBuffer =
|
|
|
|
(UChar *)uprv_malloc((length + 1) * sizeof(UChar));
|
|
|
|
source->writableBufSize = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_strcpy(source->writableBuffer, buffer);
|
|
|
|
source->pos = source->writableBuffer;
|
|
|
|
}
|
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
/**
|
|
|
|
* Function to get the discontiguos collation element within the source.
|
|
|
|
* Note this function will set the position to the appropriate places.
|
|
|
|
* @param coll current collator used
|
|
|
|
* @param source data string source
|
|
|
|
* @param constart index to the start character in the contraction table
|
|
|
|
* @return discontiguos collation element offset
|
|
|
|
*/
|
2001-06-06 23:26:50 +00:00
|
|
|
uint32_t getDiscontiguous(const UCollator *coll, collIterate *source,
|
2001-05-10 17:49:24 +00:00
|
|
|
const UChar *constart)
|
|
|
|
{
|
|
|
|
/* source->pos currently points to the second combining character after
|
|
|
|
the start character */
|
|
|
|
UChar *temppos = source->pos;
|
2001-05-14 18:57:54 +00:00
|
|
|
UChar buffer[UCOL_MAX_BUFFER];
|
2001-05-10 17:49:24 +00:00
|
|
|
UChar *tempdb = buffer;
|
|
|
|
const UChar *tempconstart = constart;
|
|
|
|
uint8_t tempflags = source->flags;
|
2001-05-14 18:57:54 +00:00
|
|
|
UBool multicontraction = FALSE;
|
|
|
|
UChar *tempbufferpos = 0;
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
*tempdb = *(source->pos - 1);
|
|
|
|
tempdb ++;
|
|
|
|
while (TRUE) {
|
|
|
|
UChar *UCharOffset;
|
|
|
|
UChar schar,
|
|
|
|
tchar;
|
|
|
|
uint32_t result;
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
if (((source->flags & UCOL_ITER_HASLEN) && source->pos >= source->endp)
|
|
|
|
|| (*source->pos == 0 &&
|
2001-05-10 17:49:24 +00:00
|
|
|
((source->flags & UCOL_ITER_INNORMBUF) == 0 ||
|
2001-05-11 01:13:08 +00:00
|
|
|
source->fcdPosition == NULL ||
|
2001-05-10 17:49:24 +00:00
|
|
|
source->fcdPosition == source->endp ||
|
|
|
|
*(source->fcdPosition) == 0 ||
|
|
|
|
u_getCombiningClass(*(source->fcdPosition)) == 0)) ||
|
2001-05-11 01:13:08 +00:00
|
|
|
/* end of string in null terminated string or stopped by a
|
|
|
|
null character, note fcd does not always point to a base
|
2001-05-10 17:49:24 +00:00
|
|
|
character after the discontiguos change */
|
|
|
|
u_getCombiningClass(*(source->pos)) == 0) {
|
2001-05-12 00:12:55 +00:00
|
|
|
//constart = (UChar *)coll->image + getContractOffset(CE);
|
2001-05-14 18:57:54 +00:00
|
|
|
if (multicontraction) {
|
|
|
|
*tempbufferpos = 0;
|
|
|
|
source->pos = temppos - 1;
|
|
|
|
setDiscontiguosAttribute(source, buffer, tempdb);
|
2001-06-06 23:26:50 +00:00
|
|
|
return *(coll->contractionCEs +
|
2001-05-14 18:57:54 +00:00
|
|
|
(tempconstart - coll->contractionIndex));
|
|
|
|
}
|
2001-05-12 00:12:55 +00:00
|
|
|
constart = tempconstart;
|
2001-05-10 17:49:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UCharOffset = (UChar *)(tempconstart + 1); /* skip the backward offset*/
|
|
|
|
schar = getNextNormalizedChar(source);
|
2001-05-11 01:13:08 +00:00
|
|
|
|
|
|
|
while (schar > (tchar = *UCharOffset)) {
|
2001-05-10 17:49:24 +00:00
|
|
|
UCharOffset++;
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
if (schar != tchar) {
|
|
|
|
/* not the correct codepoint. we stuff the current codepoint into
|
2001-05-10 17:49:24 +00:00
|
|
|
the discontiguos buffer and try the next character */
|
|
|
|
*tempdb = schar;
|
|
|
|
tempdb ++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
2001-05-11 01:13:08 +00:00
|
|
|
if (u_getCombiningClass(schar) ==
|
2001-05-10 17:49:24 +00:00
|
|
|
u_getCombiningClass(*(source->pos - 2))) {
|
|
|
|
*tempdb = schar;
|
|
|
|
tempdb ++;
|
|
|
|
continue;
|
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
result = *(coll->contractionCEs +
|
2001-05-10 17:49:24 +00:00
|
|
|
(UCharOffset - coll->contractionIndex));
|
|
|
|
}
|
|
|
|
*tempdb = 0;
|
|
|
|
|
|
|
|
if (result == UCOL_NOT_FOUND) {
|
|
|
|
break;
|
2001-05-11 01:13:08 +00:00
|
|
|
} else if (isContraction(result)) {
|
2001-05-10 17:49:24 +00:00
|
|
|
/* this is a multi-contraction*/
|
|
|
|
tempconstart = (UChar *)coll->image + getContractOffset(result);
|
2001-05-14 18:57:54 +00:00
|
|
|
if (*(coll->contractionCEs + (constart - coll->contractionIndex))
|
|
|
|
!= UCOL_NOT_FOUND) {
|
|
|
|
multicontraction = TRUE;
|
|
|
|
temppos = source->pos + 1;
|
|
|
|
tempbufferpos = buffer + u_strlen(buffer);
|
2001-05-10 17:49:24 +00:00
|
|
|
}
|
2001-05-14 18:57:54 +00:00
|
|
|
} else {
|
|
|
|
setDiscontiguosAttribute(source, buffer, tempdb);
|
2001-05-10 17:49:24 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
|
|
|
/* no problems simply reverting just like that,
|
|
|
|
if we are in string before getting into this function, points back to
|
2001-05-10 17:49:24 +00:00
|
|
|
string hence no problem.
|
2001-05-11 01:13:08 +00:00
|
|
|
if we are in normalization buffer before getting into this function,
|
|
|
|
since we'll never use another normalization within this function, we
|
|
|
|
know that fcdposition points to a base character. the normalization buffer
|
2001-05-10 17:49:24 +00:00
|
|
|
never change, hence this revert works. */
|
|
|
|
source->pos = temppos - 1;
|
|
|
|
source->flags = tempflags;
|
|
|
|
return *(coll->contractionCEs + (constart - coll->contractionIndex));
|
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* This function handles the special CEs like contractions, expansions, surrogates, Thai */
|
|
|
|
/* It is called by both getNextCE and getNextUCA */
|
2001-02-06 06:50:16 +00:00
|
|
|
uint32_t getSpecialCE(const UCollator *coll, uint32_t CE, collIterate *source, UErrorCode *status) {
|
2001-01-15 23:18:06 +00:00
|
|
|
for (;;) {
|
2001-06-06 23:26:50 +00:00
|
|
|
// This loop will repeat only in the case of contractions, and only when a contraction
|
|
|
|
// is found and the first CE resulting from that contraction is itself a special
|
|
|
|
// (an expansion, for example.) All other special CE types are fully handled the
|
|
|
|
// first time through, and the loop exits.
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
const uint32_t *CEOffset = NULL;
|
|
|
|
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;
|
|
|
|
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
|
|
|
case THAI_TAG:
|
2001-01-05 06:36:10 +00:00
|
|
|
/* Thai/Lao reordering */
|
2001-04-06 23:37:48 +00:00
|
|
|
if (((source->flags) & UCOL_ITER_INNORMBUF) || /* Already Swapped || */
|
|
|
|
source->endp == source->pos || /* At end of string. No swap possible || */
|
|
|
|
UCOL_ISTHAIBASECONSONANT(*(source->pos)) == 0) /* next char not Thai base cons. */
|
|
|
|
{
|
|
|
|
// Treat Thai as a length one expansion */
|
|
|
|
CEOffset = (uint32_t *)coll->image+getExpansionOffset(CE); /* find the offset to expansion table */
|
|
|
|
CE = *CEOffset++;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Move the prevowel and the following base Consonant into the normalization buffer
|
|
|
|
// with their order swapped
|
|
|
|
source->writableBuffer[0] = *source->pos;
|
|
|
|
source->writableBuffer[1] = *(source->pos - 1);
|
|
|
|
source->writableBuffer[2] = 0;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
source->fcdPosition = source->pos+1; // Indicate where to continue in main input string
|
|
|
|
// after exhausting the writableBuffer
|
2001-03-12 20:05:46 +00:00
|
|
|
source->pos = source->writableBuffer;
|
2001-04-06 23:37:48 +00:00
|
|
|
source->origFlags = source->flags;
|
|
|
|
source->flags |= UCOL_ITER_INNORMBUF;
|
|
|
|
source->flags &= ~(UCOL_ITER_NORM | UCOL_ITER_HASLEN);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
CE = UCOL_IGNORABLE;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
2001-04-06 23:37:48 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
case CONTRACTION_TAG:
|
2001-06-06 23:26:50 +00:00
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
/* This should handle contractions */
|
2001-06-06 23:26:50 +00:00
|
|
|
collIterateState state;
|
|
|
|
backupState(source, &state);
|
|
|
|
uint32_t firstCE = UCOL_NOT_FOUND;
|
|
|
|
const UChar *UCharOffset;
|
|
|
|
UChar schar, tchar;
|
|
|
|
|
2001-01-15 23:18:06 +00:00
|
|
|
for (;;) {
|
2001-06-06 23:26:50 +00:00
|
|
|
/* This loop will run once per source string character, for as long as we */
|
|
|
|
/* are matching a potential contraction sequence */
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
/* 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
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
if (collIter_eos(source)) {
|
|
|
|
// Ran off the end of the source string.
|
2001-05-11 01:13:08 +00:00
|
|
|
CE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex));
|
2001-05-10 17:49:24 +00:00
|
|
|
// So we'll pick whatever we have at the point...
|
2001-03-21 00:22:54 +00:00
|
|
|
if (CE == UCOL_NOT_FOUND) {
|
2001-06-06 23:26:50 +00:00
|
|
|
// back up the source over all the chars we scanned going into this contraction.
|
|
|
|
CE = firstCE;
|
|
|
|
loadState(source, &state, TRUE);
|
2001-03-09 21:35:31 +00:00
|
|
|
}
|
2001-06-06 23:26:50 +00:00
|
|
|
break;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-05-15 23:00:04 +00:00
|
|
|
uint8_t maxCC = *(UCharOffset)&0xFF; /*get the discontiguos stuff */ /* skip the backward offset, see above */
|
|
|
|
uint8_t allSame = *(UCharOffset++)>>8;
|
2001-03-03 09:27:42 +00:00
|
|
|
|
2001-04-24 03:18:54 +00:00
|
|
|
schar = getNextNormalizedChar(source);
|
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-06-06 23:26:50 +00:00
|
|
|
|
|
|
|
if (schar == tchar) {
|
|
|
|
// Found the source string char in the contraction table.
|
|
|
|
// Pick up the corresponding CE from the table.
|
2001-05-15 23:00:04 +00:00
|
|
|
CE = *(coll->contractionCEs +
|
2001-06-06 23:26:50 +00:00
|
|
|
(UCharOffset - coll->contractionIndex));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Source string char was not in contraction table.
|
|
|
|
// Unless we have a discontiguous contraction, we have finished
|
|
|
|
// with this contraction.
|
|
|
|
uint8_t sCC;
|
|
|
|
if (schar < 0x300 ||
|
|
|
|
maxCC == 0 ||
|
|
|
|
(sCC = i_getCombiningClass(schar, coll)) == 0 ||
|
|
|
|
sCC>maxCC ||
|
|
|
|
(allSame != 0 && sCC == maxCC) ||
|
|
|
|
collIter_eos(source)) {
|
|
|
|
// Contraction can not be discontiguous.
|
|
|
|
source->pos --; // back up the source string pointer by one,
|
|
|
|
// because the character we just looked at was
|
|
|
|
// not part of the contraction. */
|
|
|
|
CE = *(coll->contractionCEs +
|
|
|
|
(ContractionStart - coll->contractionIndex));
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Contraction is possibly discontiguous.
|
|
|
|
// Scan more of source string looking for a match
|
|
|
|
//
|
|
|
|
UChar tempchar;
|
2001-05-16 18:23:26 +00:00
|
|
|
/* find the next character if schar is not a base character
|
2001-06-06 23:26:50 +00:00
|
|
|
and we are not yet at the end of the string */
|
2001-05-16 18:23:26 +00:00
|
|
|
tempchar = getNextNormalizedChar(source);
|
|
|
|
source->pos --;
|
2001-06-06 23:26:50 +00:00
|
|
|
if (i_getCombiningClass(tempchar, coll) == 0) {
|
|
|
|
source->pos --;
|
|
|
|
/* Spit out the last char of the string, wasn't tasty enough */
|
|
|
|
CE = *(coll->contractionCEs +
|
|
|
|
(ContractionStart - coll->contractionIndex));
|
|
|
|
} else {
|
|
|
|
CE = getDiscontiguous(coll, source, ContractionStart);
|
|
|
|
}
|
2001-05-16 18:23:26 +00:00
|
|
|
}
|
2001-04-18 01:34:26 +00:00
|
|
|
}
|
2001-03-21 00:22:54 +00:00
|
|
|
|
2001-03-09 07:18:33 +00:00
|
|
|
if(CE == UCOL_NOT_FOUND) {
|
2001-06-06 23:26:50 +00:00
|
|
|
/* The Source string did not match the contraction that we were checking. */
|
|
|
|
/* Back up the source position to undo the effects of having partially */
|
|
|
|
/* scanned through what ultimately proved to not be a contraction. */
|
2001-05-02 01:36:29 +00:00
|
|
|
loadState(source, &state, TRUE);
|
2001-05-10 17:49:24 +00:00
|
|
|
CE = firstCE;
|
2001-03-16 02:14:37 +00:00
|
|
|
break;
|
2001-06-06 23:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!isContraction(CE)) {
|
|
|
|
// The source string char was in the contraction table, and the corresponding
|
|
|
|
// CE is not a contraction CE. We completed the contraction, break
|
|
|
|
// out of loop, this CE will end up being returned. This is the normal
|
|
|
|
// way out of contraction handling when the source actually contained
|
|
|
|
// the contraction.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The source string char was in the contraction table, and the corresponding
|
|
|
|
// CE is IS a contraction CE. We will continue looping to check the source
|
|
|
|
// string for the remaining chars in the contraction.
|
|
|
|
uint32_t tempCE = *(coll->contractionCEs + (ContractionStart - coll->contractionIndex));
|
|
|
|
if(tempCE != UCOL_NOT_FOUND) {
|
|
|
|
// We have scanned a a section of source string for which there is a
|
|
|
|
// CE from the contraction table. Remember the CE and scan position, so
|
|
|
|
// that we can return to this point if further scanning fails to
|
|
|
|
// match a longer contraction sequence.
|
2001-04-25 23:28:55 +00:00
|
|
|
firstCE = tempCE;
|
2001-04-24 03:18:54 +00:00
|
|
|
backupState(source, &state);
|
2001-04-25 23:28:55 +00:00
|
|
|
state.pos --;
|
2001-03-09 07:18:33 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-06-06 23:26:50 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
case EXPANSION_TAG:
|
2001-06-06 23:26:50 +00:00
|
|
|
{
|
2001-01-05 00:47:25 +00:00
|
|
|
/* 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-06-06 23:26:50 +00:00
|
|
|
uint32_t size;
|
|
|
|
uint32_t i; /* general counter */
|
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
|
|
|
return CE;
|
2001-06-06 23:26:50 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
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
|
|
|
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-04-18 19:31:05 +00:00
|
|
|
/**
|
2001-05-11 01:13:08 +00:00
|
|
|
* Inserts the argument character into the front of the buffer replacing the
|
2001-04-20 22:29:53 +00:00
|
|
|
* front null terminator.
|
|
|
|
* @param data collation element iterator data
|
2001-04-28 01:22:25 +00:00
|
|
|
* @param pNull pointer to the null terminator
|
2001-04-20 22:29:53 +00:00
|
|
|
* @param ch character to be appended
|
2001-04-25 23:28:55 +00:00
|
|
|
* @return positon of added character
|
2001-04-20 22:29:53 +00:00
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
inline UChar * insertBufferFront(collIterate *data, UChar *pNull, UChar ch)
|
2001-04-20 22:29:53 +00:00
|
|
|
{
|
|
|
|
uint32_t size = data->writableBufSize;
|
2001-04-28 01:22:25 +00:00
|
|
|
UChar *end;
|
2001-04-20 22:29:53 +00:00
|
|
|
UChar *newbuffer;
|
|
|
|
const uint32_t incsize = 5;
|
|
|
|
|
2001-04-28 01:22:25 +00:00
|
|
|
if (pNull > data->writableBuffer + 1) {
|
|
|
|
*pNull = ch;
|
|
|
|
*(pNull - 1) = 0;
|
|
|
|
return pNull;
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-20 22:29:53 +00:00
|
|
|
buffer will always be null terminated infront.
|
|
|
|
giving extra space since it is likely that more characters will be added.
|
|
|
|
*/
|
|
|
|
size += incsize;
|
|
|
|
newbuffer = (UChar *)uprv_malloc(sizeof(UChar) * size);
|
|
|
|
end = newbuffer + incsize;
|
2001-05-11 01:13:08 +00:00
|
|
|
uprv_memcpy(end, data->writableBuffer,
|
2001-04-20 22:29:53 +00:00
|
|
|
data->writableBufSize * sizeof(UChar));
|
|
|
|
*end = ch;
|
|
|
|
*(end - 1) = 0;
|
|
|
|
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(data);
|
2001-04-20 22:29:53 +00:00
|
|
|
|
|
|
|
data->writableBufSize = size;
|
|
|
|
data->writableBuffer = newbuffer;
|
2001-04-25 23:28:55 +00:00
|
|
|
return end;
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Special normalization function for contraction in the previous iterator.
|
|
|
|
* This normalization sequence will place the current character at source->pos
|
|
|
|
* and its following normalized sequence into the buffer.
|
2001-05-11 01:13:08 +00:00
|
|
|
* The fcd position, pos will be changed.
|
2001-04-20 22:29:53 +00:00
|
|
|
* pos will now point to positions in the buffer.
|
|
|
|
* Flags will be changed accordingly.
|
|
|
|
* @param data collation iterator data
|
|
|
|
*/
|
|
|
|
inline void normalizePrevContraction(collIterate *data)
|
2001-05-11 01:13:08 +00:00
|
|
|
{
|
2001-04-20 22:29:53 +00:00
|
|
|
UChar *buffer = data->writableBuffer;
|
|
|
|
uint32_t buffersize = data->writableBufSize;
|
|
|
|
uint32_t nulltermsize;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar *pEnd = data->pos + 1; /* End normalize + 1 */
|
|
|
|
UChar *pStart;
|
|
|
|
uint32_t normLen;
|
|
|
|
UChar *pStartNorm;
|
|
|
|
|
|
|
|
if (data->flags & UCOL_ITER_HASLEN) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
|
|
|
normalization buffer not used yet, we'll pull down the next
|
2001-04-20 22:29:53 +00:00
|
|
|
character into the end of the buffer
|
|
|
|
*/
|
2001-04-25 23:28:55 +00:00
|
|
|
*(buffer + (buffersize - 1)) = *(data->pos + 1);
|
2001-04-20 22:29:53 +00:00
|
|
|
nulltermsize = buffersize - 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nulltermsize = buffersize;
|
|
|
|
UChar *temp = buffer + (nulltermsize - 1);
|
|
|
|
while (*(temp --) != 0) {
|
|
|
|
nulltermsize --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start normalize */
|
|
|
|
if (data->fcdPosition == NULL) {
|
|
|
|
pStart = data->string;
|
|
|
|
}
|
|
|
|
else {
|
2001-05-11 01:13:08 +00:00
|
|
|
pStart = data->fcdPosition + 1;
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
normLen = unorm_normalize(pStart, pEnd - pStart, UNORM_NFD, 0, buffer, 0,
|
2001-04-20 22:29:53 +00:00
|
|
|
&status);
|
|
|
|
|
|
|
|
if (nulltermsize <= normLen) {
|
|
|
|
uint32_t size = buffersize - nulltermsize + normLen + 1;
|
|
|
|
UChar *temp = (UChar *)uprv_malloc(size * sizeof(UChar));
|
|
|
|
nulltermsize = normLen + 1;
|
2001-05-11 01:13:08 +00:00
|
|
|
uprv_memcpy(temp + normLen, buffer,
|
2001-04-20 22:29:53 +00:00
|
|
|
sizeof(UChar) * (buffersize - nulltermsize));
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(data);
|
2001-04-20 22:29:53 +00:00
|
|
|
data->writableBuffer = temp;
|
|
|
|
data->writableBufSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = U_ZERO_ERROR;
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-20 22:29:53 +00:00
|
|
|
this puts the null termination infront of the normalized string instead
|
|
|
|
of the end
|
|
|
|
*/
|
|
|
|
pStartNorm = buffer + (nulltermsize - normLen);
|
|
|
|
*(pStartNorm - 1) = 0;
|
2001-05-11 01:13:08 +00:00
|
|
|
unorm_normalize(pStart, pEnd - pStart, UNORM_NFD, 0, pStartNorm, normLen,
|
2001-04-20 22:29:53 +00:00
|
|
|
&status);
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
data->pos = data->writableBuffer + nulltermsize;
|
|
|
|
data->origFlags = data->flags;
|
|
|
|
data->flags |= UCOL_ITER_INNORMBUF;
|
|
|
|
data->flags &= ~(UCOL_ITER_NORM | UCOL_ITER_HASLEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contraction character management function that returns the previous character
|
|
|
|
* for the backwards iterator.
|
2001-05-11 01:13:08 +00:00
|
|
|
* Does nothing if the previous character is in buffer and not the first
|
2001-04-20 22:29:53 +00:00
|
|
|
* character in it.
|
2001-05-11 01:13:08 +00:00
|
|
|
* Else it checks previous character in data string to see if it is
|
2001-04-20 22:29:53 +00:00
|
|
|
* normalizable.
|
|
|
|
* If it is not, the character is simply copied into the buffer, else
|
2001-05-11 01:13:08 +00:00
|
|
|
* the whole normalized substring is copied into the buffer, including the
|
2001-04-20 22:29:53 +00:00
|
|
|
* current character.
|
|
|
|
* @param data collation element iterator data
|
|
|
|
* @return previous character
|
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
inline UChar getPrevNormalizedChar(collIterate *data)
|
2001-04-20 22:29:53 +00:00
|
|
|
{
|
|
|
|
UChar prevch;
|
|
|
|
UChar ch;
|
|
|
|
UChar *start;
|
2001-05-02 23:36:22 +00:00
|
|
|
UBool innormbuf = (UBool)(data->flags & UCOL_ITER_INNORMBUF);
|
2001-04-28 01:22:25 +00:00
|
|
|
UChar *pNull = NULL;
|
2001-05-11 01:13:08 +00:00
|
|
|
if ((data->flags & (UCOL_ITER_NORM | UCOL_ITER_INNORMBUF)) == 0 ||
|
2001-04-26 01:15:34 +00:00
|
|
|
(innormbuf && *(data->pos - 1) != 0)) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-20 22:29:53 +00:00
|
|
|
if no normalization.
|
|
|
|
if previous character is in normalized buffer, no further normalization
|
|
|
|
is required
|
|
|
|
*/
|
|
|
|
return *(data->pos - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
start = data->pos;
|
|
|
|
if (data->flags & UCOL_ITER_HASLEN) {
|
|
|
|
/* in data string */
|
|
|
|
if ((start - 1) == data->string) {
|
|
|
|
return *(start - 1);
|
|
|
|
}
|
2001-04-25 23:28:55 +00:00
|
|
|
start --;
|
|
|
|
ch = *start;
|
|
|
|
prevch = *(start - 1);
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-20 22:29:53 +00:00
|
|
|
in writable buffer, at this point fcdPosition can not be NULL.
|
|
|
|
see contracting tag.
|
|
|
|
*/
|
|
|
|
if (data->fcdPosition == data->string) {
|
|
|
|
/* at the start of the string, just dump it into the normalizer */
|
2001-04-28 01:22:25 +00:00
|
|
|
insertBufferFront(data, data->pos - 1, *(data->fcdPosition));
|
2001-04-25 23:28:55 +00:00
|
|
|
data->fcdPosition = NULL;
|
|
|
|
return *(data->pos - 1);
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
2001-04-28 01:22:25 +00:00
|
|
|
pNull = data->pos - 1;
|
2001-04-25 23:28:55 +00:00
|
|
|
start = data->fcdPosition;
|
|
|
|
ch = *start;
|
|
|
|
prevch = *(start - 1);
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
2001-04-20 22:29:53 +00:00
|
|
|
* if the current character is not fcd.
|
|
|
|
* Trailing combining class == 0.
|
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
if (data->fcdPosition > start &&
|
|
|
|
(ch >= NFC_ZERO_CC_BLOCK_LIMIT_ || prevch >= NFC_ZERO_CC_BLOCK_LIMIT_))
|
2001-04-25 23:28:55 +00:00
|
|
|
{
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
|
|
|
Need a more complete FCD check and possible normalization.
|
|
|
|
normalize substring will be appended to buffer
|
2001-04-25 23:28:55 +00:00
|
|
|
*/
|
|
|
|
UChar *backuppos = data->pos;
|
|
|
|
data->pos = start;
|
|
|
|
if (collPrevIterFCD(data)) {
|
2001-04-20 22:29:53 +00:00
|
|
|
normalizePrevContraction(data);
|
2001-04-25 23:28:55 +00:00
|
|
|
return *(data->pos - 1);
|
|
|
|
}
|
|
|
|
data->pos = backuppos;
|
|
|
|
data->fcdPosition ++;
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-26 01:15:34 +00:00
|
|
|
if (innormbuf) {
|
2001-05-11 01:13:08 +00:00
|
|
|
/*
|
|
|
|
no normalization is to be done hence only one character will be
|
2001-04-25 23:28:55 +00:00
|
|
|
appended to the buffer.
|
|
|
|
*/
|
2001-04-28 01:22:25 +00:00
|
|
|
insertBufferFront(data, pNull, ch);
|
2001-04-25 23:28:55 +00:00
|
|
|
data->fcdPosition --;
|
2001-04-20 22:29:53 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-04-20 22:29:53 +00:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:13:08 +00:00
|
|
|
/**
|
2001-04-23 01:53:49 +00:00
|
|
|
* This function handles the special CEs like contractions, expansions,
|
2001-02-20 00:26:50 +00:00
|
|
|
* surrogates, Thai.
|
2001-04-23 01:53:49 +00:00
|
|
|
* It is called by both getPrevCE and getPrevUCA
|
2001-02-20 00:26:50 +00:00
|
|
|
*/
|
2001-04-23 01:53:49 +00:00
|
|
|
uint32_t getSpecialPrevCE(const UCollator *coll, uint32_t CE,
|
|
|
|
collIterate *source,
|
|
|
|
UErrorCode *status)
|
2001-02-20 00:26:50 +00:00
|
|
|
{
|
|
|
|
const uint32_t *CEOffset = NULL;
|
2001-05-10 17:49:24 +00:00
|
|
|
UChar *UCharOffset = NULL;
|
|
|
|
UChar schar;
|
2001-02-20 00:26:50 +00:00
|
|
|
const UChar *constart = NULL;
|
|
|
|
uint32_t size;
|
2001-05-11 16:23:29 +00:00
|
|
|
UChar buffer[UCOL_MAX_BUFFER];
|
2001-05-17 21:34:04 +00:00
|
|
|
uint32_t *endCEBuffer;
|
2001-05-17 01:06:25 +00:00
|
|
|
UChar *strbuffer;
|
2001-04-20 22:29:53 +00:00
|
|
|
|
2001-02-28 19:30:41 +00:00
|
|
|
for(;;)
|
2001-02-20 00:26:50 +00:00
|
|
|
{
|
2001-03-09 23:09:21 +00:00
|
|
|
/* the only ces that loops are thai and contractions */
|
2001-04-23 01:53:49 +00:00
|
|
|
switch (getCETag(CE))
|
2001-02-20 00:26:50 +00:00
|
|
|
{
|
2001-03-09 23:09:21 +00:00
|
|
|
case NOT_FOUND_TAG: /* this tag always returns */
|
2001-02-20 00:26:50 +00:00
|
|
|
return CE;
|
2001-03-09 23:09:21 +00:00
|
|
|
case SURROGATE_TAG: /* this tag always returns */
|
2001-02-20 00:26:50 +00:00
|
|
|
/* pending surrogate discussion with Markus and Mark */
|
|
|
|
return UCOL_NOT_FOUND;
|
|
|
|
case THAI_TAG:
|
2001-04-12 00:08:26 +00:00
|
|
|
if ((source->flags & UCOL_ITER_INNORMBUF) || /* Already Swapped || */
|
|
|
|
source->string == source->pos || /* At start of string.|| */
|
2001-04-23 01:53:49 +00:00
|
|
|
/* previous char not Thai prevowel */
|
2001-04-12 00:08:26 +00:00
|
|
|
UCOL_ISTHAIBASECONSONANT(*(source->pos)) == FALSE ||
|
2001-04-23 01:53:49 +00:00
|
|
|
UCOL_ISTHAIPREVOWEL(*(source->pos - 1)) == FALSE)
|
2001-04-12 00:08:26 +00:00
|
|
|
{
|
|
|
|
/* Treat Thai as a length one expansion */
|
|
|
|
/* find the offset to expansion table */
|
2001-04-23 01:53:49 +00:00
|
|
|
CEOffset = (uint32_t *)coll->image+getExpansionOffset(CE);
|
2001-04-12 00:08:26 +00:00
|
|
|
CE = *CEOffset ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
|
|
|
Move the prevowel and the following base Consonant into the
|
2001-04-12 00:08:26 +00:00
|
|
|
normalization buffer with their order swapped
|
2001-02-20 00:26:50 +00:00
|
|
|
*/
|
2001-05-11 01:13:08 +00:00
|
|
|
UChar *tempbuffer = source->writableBuffer +
|
2001-04-20 22:29:53 +00:00
|
|
|
(source->writableBufSize - 1);
|
|
|
|
*(tempbuffer - 2) = 0;
|
|
|
|
*(tempbuffer - 1) = *source->pos;
|
|
|
|
*(tempbuffer) = *(source->pos - 1);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Indicate where to continue in main input string after exhausting
|
|
|
|
the writableBuffer
|
2001-04-12 00:08:26 +00:00
|
|
|
*/
|
2001-04-12 18:25:07 +00:00
|
|
|
if (source->pos - 1 == source->string) {
|
|
|
|
source->fcdPosition = NULL;
|
|
|
|
}
|
|
|
|
else {
|
2001-04-23 01:53:49 +00:00
|
|
|
source->fcdPosition = source->pos - 2;
|
2001-04-12 18:25:07 +00:00
|
|
|
}
|
2001-04-20 22:29:53 +00:00
|
|
|
|
|
|
|
source->pos = tempbuffer;
|
2001-04-12 00:08:26 +00:00
|
|
|
source->origFlags = source->flags;
|
|
|
|
source->flags |= UCOL_ITER_INNORMBUF;
|
|
|
|
source->flags &= ~(UCOL_ITER_NORM | UCOL_ITER_HASLEN);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
CE = UCOL_IGNORABLE;
|
2001-02-20 00:26:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONTRACTION_TAG:
|
2001-05-11 01:13:08 +00:00
|
|
|
/* to ensure that the backwards and forwards iteration matches, we
|
2001-05-10 17:49:24 +00:00
|
|
|
take the current region of most possible match and pass it through
|
|
|
|
the forward iteration. this will ensure that the obstinate problem of
|
|
|
|
overlapping contractions will not occur.
|
|
|
|
*/
|
|
|
|
schar = *(source->pos);
|
|
|
|
constart = (UChar *)coll->image + getContractOffset(CE);
|
2001-05-17 01:06:25 +00:00
|
|
|
if (isAtStartPrevIterate(source)
|
|
|
|
/* commented away contraction end checks after adding the checks
|
2001-05-25 16:54:06 +00:00
|
|
|
in getPrevCE and getPrevUCA */) {
|
2001-05-10 17:49:24 +00:00
|
|
|
/* start of string or this is not the end of any contraction */
|
2001-06-06 23:26:50 +00:00
|
|
|
CE = *(coll->contractionCEs +
|
2001-05-17 01:06:25 +00:00
|
|
|
(constart - coll->contractionIndex));
|
2001-05-10 23:05:23 +00:00
|
|
|
break;
|
2001-05-10 17:49:24 +00:00
|
|
|
}
|
2001-05-17 01:06:25 +00:00
|
|
|
strbuffer = buffer;
|
|
|
|
UCharOffset = strbuffer + (UCOL_MAX_BUFFER - 1);
|
2001-05-10 17:49:24 +00:00
|
|
|
*(UCharOffset --) = 0;
|
|
|
|
while (ucol_unsafeCP(schar, coll)) {
|
|
|
|
*(UCharOffset) = schar;
|
|
|
|
UCharOffset --;
|
2001-04-20 22:29:53 +00:00
|
|
|
schar = getPrevNormalizedChar(source);
|
2001-05-10 17:49:24 +00:00
|
|
|
source->pos --;
|
2001-05-17 01:06:25 +00:00
|
|
|
if (UCharOffset + 1 == buffer) {
|
|
|
|
/* we have exhausted the buffer */
|
2001-06-03 23:40:41 +00:00
|
|
|
int32_t newsize = source->pos - source->string + 1;
|
2001-06-06 23:26:50 +00:00
|
|
|
strbuffer = (UChar *)uprv_malloc(sizeof(UChar) *
|
2001-05-17 01:06:25 +00:00
|
|
|
(newsize + UCOL_MAX_BUFFER));
|
|
|
|
UCharOffset = strbuffer + newsize;
|
2001-06-06 23:26:50 +00:00
|
|
|
uprv_memcpy(UCharOffset, buffer,
|
2001-05-17 01:06:25 +00:00
|
|
|
UCOL_MAX_BUFFER * sizeof(UChar));
|
|
|
|
UCharOffset --;
|
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
if (source->pos == source->string ||
|
|
|
|
((source->flags & UCOL_ITER_INNORMBUF) &&
|
2001-05-10 17:49:24 +00:00
|
|
|
*(source->pos - 1) == 0 && source->fcdPosition == NULL)) {
|
|
|
|
break;
|
2001-04-18 01:34:26 +00:00
|
|
|
}
|
2001-05-10 17:49:24 +00:00
|
|
|
}
|
|
|
|
/* adds the initial base character to the string */
|
|
|
|
*(UCharOffset) = schar;
|
|
|
|
|
|
|
|
/* a new collIterate is used to simply things, since using the current
|
2001-05-11 01:13:08 +00:00
|
|
|
collIterate will mean that the forward and backwards iteration will
|
2001-05-10 17:49:24 +00:00
|
|
|
share and change the same buffers. we don't want to get into that. */
|
|
|
|
collIterate temp;
|
|
|
|
IInit_collIterate(coll, UCharOffset, -1, &temp);
|
|
|
|
temp.flags &= ~UCOL_ITER_NORM;
|
|
|
|
|
|
|
|
CE = ucol_IGetNextCE(coll, &temp, status);
|
2001-05-17 21:34:04 +00:00
|
|
|
endCEBuffer = source->CEs + UCOL_EXPAND_CE_BUFFER_SIZE;
|
2001-05-10 17:49:24 +00:00
|
|
|
while (CE != UCOL_NO_MORE_CES) {
|
2001-05-11 01:13:08 +00:00
|
|
|
*(source->CEpos ++) = CE;
|
2001-05-17 21:34:04 +00:00
|
|
|
if (source->CEpos == endCEBuffer) {
|
|
|
|
/* ran out of CE space, bail.
|
2001-06-06 23:26:50 +00:00
|
|
|
there's no guarantee of the right character position after
|
2001-05-17 21:34:04 +00:00
|
|
|
this bail*/
|
|
|
|
*status = U_BUFFER_OVERFLOW_ERROR;
|
2001-05-17 23:09:35 +00:00
|
|
|
source->CEpos = source->CEs;
|
2001-05-17 21:34:04 +00:00
|
|
|
return UCOL_NULLORDER;
|
|
|
|
}
|
2001-05-10 17:49:24 +00:00
|
|
|
CE = ucol_IGetNextCE(coll, &temp, status);
|
|
|
|
}
|
|
|
|
freeHeapWritableBuffer(&temp);
|
2001-05-17 01:06:25 +00:00
|
|
|
if (strbuffer != buffer) {
|
|
|
|
uprv_free(strbuffer);
|
|
|
|
}
|
2001-05-10 17:49:24 +00:00
|
|
|
source->toReturn = source->CEpos - 1;
|
|
|
|
if (source->toReturn == source->CEs) {
|
|
|
|
source->CEpos = source->CEs;
|
|
|
|
}
|
|
|
|
return *(source->toReturn);
|
2001-03-09 23:09:21 +00:00
|
|
|
case EXPANSION_TAG: /* this tag always returns */
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
2001-02-20 00:26:50 +00:00
|
|
|
This should handle expansion.
|
2001-04-23 01:53:49 +00:00
|
|
|
NOTE: we can encounter both continuations and expansions in an expansion!
|
|
|
|
I have to decide where continuations are going to be dealt with
|
2001-02-20 00:26:50 +00:00
|
|
|
*/
|
|
|
|
/* find the offset to expansion table */
|
2001-04-23 01:53:49 +00:00
|
|
|
CEOffset = (uint32_t *)coll->image + getExpansionOffset(CE);
|
2001-02-20 00:26:50 +00:00
|
|
|
size = getExpansionCount(CE);
|
2001-03-07 21:01:53 +00:00
|
|
|
if (size != 0) {
|
2001-04-23 01:53:49 +00:00
|
|
|
/*
|
|
|
|
if there are less than 16 elements in expansion, we don't terminate
|
2001-02-20 00:26:50 +00:00
|
|
|
*/
|
2001-05-10 17:49:24 +00:00
|
|
|
uint32_t count;
|
2001-03-07 21:01:53 +00:00
|
|
|
for (count = 0; count < size; count++) {
|
2001-02-20 00:26:50 +00:00
|
|
|
*(source->CEpos ++) = *CEOffset++;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-02-20 00:26:50 +00:00
|
|
|
/* else, we do */
|
2001-03-07 21:01:53 +00:00
|
|
|
while (*CEOffset != 0) {
|
2001-02-20 00:26:50 +00:00
|
|
|
*(source->CEpos ++) = *CEOffset ++;
|
2001-03-07 21:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
source->toReturn = source->CEpos - 1;
|
2001-02-23 23:36:42 +00:00
|
|
|
return *(source->toReturn);
|
2001-03-09 23:09:21 +00:00
|
|
|
case CHARSET_TAG: /* this tag always returns */
|
2001-02-20 00:26:50 +00:00
|
|
|
/* probably after 1.8 */
|
|
|
|
return UCOL_NOT_FOUND;
|
2001-03-09 23:09:21 +00:00
|
|
|
default: /* this tag always returns */
|
2001-02-20 00:26:50 +00:00
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
CE=0;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-07 21:01:53 +00:00
|
|
|
if (CE <= UCOL_NOT_FOUND) {
|
|
|
|
break;
|
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
}
|
|
|
|
return CE;
|
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* This should really be a macro */
|
|
|
|
/* However, it is used only when stack buffers are not sufficiently big, and then we're messed up performance wise */
|
|
|
|
/* anyway */
|
2001-03-14 07:49:03 +00:00
|
|
|
uint8_t *reallocateBuffer(uint8_t **secondaries, uint8_t *secStart, uint8_t *second, uint32_t *secSize, uint32_t newSize, UErrorCode *status) {
|
2001-05-17 23:09:35 +00:00
|
|
|
#ifdef UCOL_DEBUG
|
2001-03-14 07:49:03 +00:00
|
|
|
fprintf(stderr, ".");
|
2001-05-17 18:19:42 +00:00
|
|
|
#endif
|
2001-01-09 00:52:18 +00:00
|
|
|
uint8_t *newStart = NULL;
|
|
|
|
|
|
|
|
if(secStart==second) {
|
2001-03-14 07:49:03 +00:00
|
|
|
newStart=(uint8_t*)uprv_malloc(newSize);
|
2001-01-09 00:52:18 +00:00
|
|
|
if(newStart==NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uprv_memcpy(newStart, secStart, *secondaries-secStart);
|
|
|
|
} else {
|
2001-03-14 07:49:03 +00:00
|
|
|
newStart=(uint8_t*)uprv_realloc(secStart, newSize);
|
2001-01-09 00:52:18 +00:00
|
|
|
if(newStart==NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*secondaries=newStart+(*secondaries-secStart);
|
2001-03-14 07:49:03 +00:00
|
|
|
*secSize=newSize;
|
2001-01-09 00:52:18 +00:00
|
|
|
return newStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* This should really be a macro */
|
|
|
|
/* This function is used to reverse parts of a buffer. We need this operation when doing continuation */
|
|
|
|
/* secondaries in French */
|
|
|
|
/*
|
2001-01-09 00:52:18 +00:00
|
|
|
void uprv_ucol_reverse_buffer(uint8_t *start, uint8_t *end) {
|
|
|
|
uint8_t temp;
|
|
|
|
while(start<end) {
|
|
|
|
temp = *start;
|
|
|
|
*start++ = *end;
|
|
|
|
*end-- = temp;
|
|
|
|
}
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
*/
|
2001-01-09 00:52:18 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
#define uprv_ucol_reverse_buffer(TYPE, start, end) { \
|
|
|
|
TYPE tempA; \
|
|
|
|
while((start)<(end)) { \
|
|
|
|
tempA = *(start); \
|
|
|
|
*(start)++ = *(end); \
|
|
|
|
*(end)-- = tempA; \
|
|
|
|
} \
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-15 07:28:54 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Following are the sortkey generation functions */
|
|
|
|
/* */
|
|
|
|
/****************************************************************************/
|
2001-01-15 07:28:54 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* sortkey API */
|
|
|
|
U_CAPI int32_t
|
|
|
|
ucol_getSortKey(const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t *result,
|
|
|
|
int32_t resultLength)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-03-14 07:49:03 +00:00
|
|
|
/* this uses the function pointer that is set in updateinternalstate */
|
|
|
|
/* currently, there are two funcs: */
|
|
|
|
/*ucol_calcSortKey(...);*/
|
|
|
|
/*ucol_calcSortKeySimpleTertiary(...);*/
|
|
|
|
|
|
|
|
int32_t keySize = coll->sortKeyGen(coll, source, sourceLength, &result, resultLength, FALSE, &status);
|
|
|
|
((UCollator *)coll)->errorCode = status; /*semantically const */
|
|
|
|
return keySize;
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called by the C++ API for sortkey generation */
|
2001-04-23 01:53:49 +00:00
|
|
|
U_CFUNC uint8_t *ucol_getSortKeyWithAllocation(const UCollator *coll,
|
2001-01-15 07:28:54 +00:00
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
int32_t *resultLen) {
|
|
|
|
uint8_t *result = NULL;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-03-15 02:49:35 +00:00
|
|
|
*resultLen = coll->sortKeyGen(coll, source, sourceLength, &result, 0, TRUE, &status);
|
2001-01-15 07:28:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
|
|
|
|
/* This function tries to get the size of a sortkey. It will be invoked if the size of resulting buffer is 0 */
|
|
|
|
/* or if we run out of space while making a sortkey and want to return ASAP */
|
2001-01-15 07:28:54 +00:00
|
|
|
int32_t ucol_getSortKeySize(const UCollator *coll, collIterate *s, int32_t currentSize, UColAttributeValue strength, int32_t len) {
|
2001-01-05 00:47:25 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-02-28 19:30:41 +00:00
|
|
|
uint8_t compareSec = (uint8_t)((strength >= UCOL_SECONDARY)?0:0xFF);
|
|
|
|
uint8_t compareTer = (uint8_t)((strength >= UCOL_TERTIARY)?0:0xFF);
|
|
|
|
uint8_t compareQuad = (uint8_t)((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);
|
2001-03-15 02:49:35 +00:00
|
|
|
UBool shifted = (coll->alternateHandling == UCOL_SHIFTED);
|
|
|
|
UBool qShifted = shifted && (compareQuad == 0);
|
2001-01-26 00:12:23 +00:00
|
|
|
UBool isFrenchSec = (coll->frenchCollation == UCOL_ON) && (compareSec == 0);
|
2001-01-09 00:52:18 +00:00
|
|
|
|
2001-01-25 06:51:18 +00:00
|
|
|
uint8_t variableMax1 = coll->variableMax1;
|
|
|
|
uint8_t variableMax2 = coll->variableMax2;
|
2001-02-28 19:30:41 +00:00
|
|
|
uint8_t UCOL_COMMON_BOT4 = (uint8_t)(variableMax1+1);
|
|
|
|
uint8_t UCOL_BOT_COUNT4 = (uint8_t)(0xFF - UCOL_COMMON_BOT4);
|
2001-01-09 00:52:18 +00:00
|
|
|
|
2001-03-22 21:16:20 +00:00
|
|
|
uint32_t order = UCOL_NO_MORE_CES;
|
2001-01-09 00:52:18 +00:00
|
|
|
uint8_t primary1 = 0;
|
|
|
|
uint8_t primary2 = 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-18 00:46:19 +00:00
|
|
|
uint32_t c2 = 0, c3 = 0, c4 = 0; /* variables for compression */
|
2001-03-02 00:19:43 +00:00
|
|
|
|
|
|
|
uint8_t caseSwitch = coll->caseSwitch;
|
|
|
|
uint8_t tertiaryMask = coll->tertiaryMask;
|
2001-05-10 22:33:50 +00:00
|
|
|
uint8_t tertiaryCommon = coll->tertiaryCommon;
|
2001-03-02 00:19:43 +00:00
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
UBool wasShifted = FALSE;
|
|
|
|
UBool notIsContinuation = FALSE;
|
2001-05-03 23:33:29 +00:00
|
|
|
uint8_t leadPrimary = 0;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
for(;;) {
|
2001-04-18 19:31:05 +00:00
|
|
|
order = ucol_IGetNextCE(coll, s, &status);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-24 16:18:48 +00:00
|
|
|
if(order == UCOL_NO_MORE_CES) {
|
2001-01-09 00:52:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-05-29 04:59:29 +00:00
|
|
|
|
|
|
|
if(order == 0) {
|
2001-03-15 02:49:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
notIsContinuation = !isContinuation(order);
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
|
2001-03-16 19:06:07 +00:00
|
|
|
if(notIsContinuation) {
|
2001-05-10 22:33:50 +00:00
|
|
|
tertiary = (uint8_t)((order & UCOL_BYTE_SIZE_MASK));
|
2001-03-16 19:06:07 +00:00
|
|
|
} else {
|
2001-05-10 22:33:50 +00:00
|
|
|
tertiary = (uint8_t)((order & UCOL_REMOVE_CONTINUATION));
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-02-28 19:30:41 +00:00
|
|
|
secondary = (uint8_t)((order >>= 8) & 0xFF);
|
|
|
|
primary2 = (uint8_t)((order >>= 8) & 0xFF);
|
2001-05-29 04:59:29 +00:00
|
|
|
primary1 = (uint8_t)(order >> 8);
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
if(shifted && ((notIsContinuation && primary1 <= variableMax1 && primary1 > 0
|
|
|
|
&& (primary1 < variableMax1 || primary1 == variableMax1 && primary2 < variableMax2))
|
2001-03-15 02:49:35 +00:00
|
|
|
|| (!notIsContinuation && wasShifted))) {
|
|
|
|
if(compareQuad == 0) {
|
|
|
|
if(c4 > 0) {
|
|
|
|
currentSize += (c2/UCOL_BOT_COUNT4)+1;
|
|
|
|
c4 = 0;
|
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
currentSize++;
|
2001-03-15 02:49:35 +00:00
|
|
|
if(primary2 != 0) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-02-26 10:28:56 +00:00
|
|
|
wasShifted = TRUE;
|
2001-01-09 00:52:18 +00:00
|
|
|
} else {
|
2001-02-26 10:28:56 +00:00
|
|
|
wasShifted = FALSE;
|
2001-01-09 00:52:18 +00:00
|
|
|
/* 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 */
|
2001-04-25 18:00:41 +00:00
|
|
|
/* calculate sortkey size */
|
2001-04-23 23:41:46 +00:00
|
|
|
if(primary1 != UCOL_IGNORABLE) {
|
|
|
|
if(notIsContinuation) {
|
2001-04-25 18:00:41 +00:00
|
|
|
if(leadPrimary == primary1) {
|
2001-04-24 23:32:40 +00:00
|
|
|
currentSize++;
|
2001-04-25 18:00:41 +00:00
|
|
|
} else {
|
|
|
|
if(leadPrimary != 0) {
|
2001-04-23 23:41:46 +00:00
|
|
|
currentSize++;
|
|
|
|
}
|
2001-04-25 18:00:41 +00:00
|
|
|
if(primary2 == UCOL_IGNORABLE) {
|
|
|
|
/* one byter, not compressed */
|
|
|
|
currentSize++;
|
|
|
|
leadPrimary = 0;
|
|
|
|
} else if(primary1<UCOL_BYTE_FIRST_NON_LATIN_PRIMARY ||
|
2001-05-11 01:13:08 +00:00
|
|
|
(primary1 > (UCOL_RESET_TOP_VALUE>>24) && primary1 < (UCOL_NEXT_TOP_VALUE>>24))) {
|
2001-04-25 18:00:41 +00:00
|
|
|
/* not compressible */
|
|
|
|
leadPrimary = 0;
|
|
|
|
currentSize+=2;
|
|
|
|
} else { /* compress */
|
2001-05-11 01:13:08 +00:00
|
|
|
leadPrimary = primary1;
|
2001-04-25 18:00:41 +00:00
|
|
|
currentSize+=2;
|
2001-05-11 01:13:08 +00:00
|
|
|
}
|
2001-04-23 23:41:46 +00:00
|
|
|
}
|
2001-04-24 23:32:40 +00:00
|
|
|
} else { /* we are in continuation, so we're gonna add primary to the key don't care about compression */
|
2001-04-23 23:41:46 +00:00
|
|
|
currentSize++;
|
2001-04-24 23:32:40 +00:00
|
|
|
if(primary2 != UCOL_IGNORABLE) {
|
|
|
|
currentSize++;
|
|
|
|
}
|
2001-04-23 23:41:46 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
|
|
|
|
if(secondary > compareSec) { /* I think that != 0 test should be != IGNORABLE */
|
2001-01-26 00:12:23 +00:00
|
|
|
if(!isFrenchSec){
|
2001-02-26 10:28:56 +00:00
|
|
|
if (secondary == UCOL_COMMON2 && notIsContinuation) {
|
2001-01-26 00:12:23 +00:00
|
|
|
c2++;
|
|
|
|
} else {
|
|
|
|
if(c2 > 0) {
|
2001-03-03 03:35:17 +00:00
|
|
|
if (secondary > UCOL_COMMON2) { // not necessary for 4th level.
|
2001-05-02 23:36:22 +00:00
|
|
|
currentSize += (c2/(uint32_t)UCOL_TOP_COUNT2)+1;
|
2001-01-26 00:12:23 +00:00
|
|
|
} else {
|
2001-05-02 23:36:22 +00:00
|
|
|
currentSize += (c2/(uint32_t)UCOL_BOT_COUNT2)+1;
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
|
|
|
c2 = 0;
|
2001-01-18 00:46:19 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
currentSize++;
|
2001-01-18 00:46:19 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
} else {
|
2001-01-18 00:46:19 +00:00
|
|
|
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-03-16 19:06:07 +00:00
|
|
|
caseShift = UCOL_CASE_SHIFT_START;
|
2001-01-09 00:52:18 +00:00
|
|
|
}
|
2001-05-10 22:33:50 +00:00
|
|
|
if((tertiary&0x3F) > 0 && notIsContinuation) {
|
2001-01-26 00:12:23 +00:00
|
|
|
caseShift--;
|
2001-05-10 22:33:50 +00:00
|
|
|
if((tertiary &0xC0) != 0) {
|
|
|
|
if (caseShift == 0) {
|
|
|
|
currentSize++;
|
|
|
|
caseShift = UCOL_CASE_SHIFT_START;
|
|
|
|
}
|
|
|
|
caseShift--;
|
2001-05-11 01:13:08 +00:00
|
|
|
}
|
2001-05-10 22:33:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(notIsContinuation) {
|
|
|
|
tertiary ^= caseSwitch;
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
|
2001-05-10 22:33:50 +00:00
|
|
|
tertiary &= tertiaryMask;
|
2001-01-09 00:52:18 +00:00
|
|
|
if(tertiary > compareTer) { /* I think that != 0 test should be != IGNORABLE */
|
2001-05-10 22:33:50 +00:00
|
|
|
if (tertiary == tertiaryCommon && notIsContinuation) {
|
2001-01-18 00:46:19 +00:00
|
|
|
c3++;
|
|
|
|
} else {
|
|
|
|
if(c3 > 0) {
|
2001-05-11 01:13:08 +00:00
|
|
|
if((tertiary > tertiaryCommon && tertiaryCommon == UCOL_COMMON3_NORMAL)
|
2001-05-10 22:33:50 +00:00
|
|
|
|| (tertiary <= tertiaryCommon && tertiaryCommon == UCOL_COMMON3_UPPERFIRST)) {
|
|
|
|
currentSize += (c3/(uint32_t)coll->tertiaryTopCount)+1;
|
2001-01-18 00:46:19 +00:00
|
|
|
} else {
|
2001-05-10 22:33:50 +00:00
|
|
|
currentSize += (c3/(uint32_t)coll->tertiaryBottomCount)+1;
|
2001-01-18 00:46:19 +00:00
|
|
|
}
|
|
|
|
c3 = 0;
|
|
|
|
}
|
|
|
|
currentSize++;
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-09 00:52:18 +00:00
|
|
|
|
2001-03-15 02:49:35 +00:00
|
|
|
if(qShifted && notIsContinuation) {
|
2001-01-23 06:58:22 +00:00
|
|
|
c4++;
|
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-23 06:58:22 +00:00
|
|
|
if(c2 > 0) {
|
2001-05-02 23:36:22 +00:00
|
|
|
currentSize += (c2/(uint32_t)UCOL_BOT_COUNT2)+1;
|
2001-01-23 06:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(c3 > 0) {
|
2001-05-10 22:33:50 +00:00
|
|
|
currentSize += (c3/(uint32_t)coll->tertiaryBottomCount)+1;
|
2001-01-23 06:58:22 +00:00
|
|
|
}
|
|
|
|
|
2001-03-15 02:49:35 +00:00
|
|
|
if(c4 > 0 && compareQuad == 0) {
|
2001-01-23 06:58:22 +00:00
|
|
|
currentSize += (c4/UCOL_BOT_COUNT4)+1;
|
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
if(compareIdent) {
|
2001-05-18 19:49:04 +00:00
|
|
|
currentSize += u_lengthOfIdenticalLevelRun(s->string, len);
|
2001-04-19 19:02:01 +00:00
|
|
|
}
|
|
|
|
return currentSize;
|
2001-04-06 23:37:48 +00:00
|
|
|
|
2001-04-19 19:02:01 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-10 22:33:50 +00:00
|
|
|
inline void doCaseShift(uint8_t **cases, uint32_t &caseShift) {
|
|
|
|
if (caseShift == 0) {
|
|
|
|
*(*cases)++ = UCOL_CASE_BYTE_START;
|
|
|
|
caseShift = UCOL_CASE_SHIFT_START;
|
|
|
|
}
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* This is the sortkey work horse function */
|
2001-01-05 00:47:25 +00:00
|
|
|
int32_t
|
2001-01-15 07:28:54 +00:00
|
|
|
ucol_calcSortKey(const UCollator *coll,
|
2001-01-05 00:47:25 +00:00
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t **result,
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_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 */
|
2001-03-14 07:49:03 +00:00
|
|
|
uint8_t prim[UCOL_PRIMARY_MAX_BUFFER], second[UCOL_SECONDARY_MAX_BUFFER], tert[UCOL_TERTIARY_MAX_BUFFER], caseB[UCOL_CASE_MAX_BUFFER], quad[UCOL_QUAD_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) {
|
2001-03-14 07:49:03 +00:00
|
|
|
primaries = *result = prim;
|
|
|
|
resultLength = UCOL_PRIMARY_MAX_BUFFER;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
uint32_t secSize = UCOL_SECONDARY_MAX_BUFFER, terSize = UCOL_TERTIARY_MAX_BUFFER,
|
2001-03-14 07:49:03 +00:00
|
|
|
caseSize = UCOL_CASE_MAX_BUFFER, quadSize = UCOL_QUAD_MAX_BUFFER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_t sortKeySize = 1; /* it is always \0 terminated */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-14 07:49:03 +00:00
|
|
|
UChar normBuffer[UCOL_NORMALIZATION_MAX_BUFFER];
|
2001-01-05 00:47:25 +00:00
|
|
|
UChar *normSource = normBuffer;
|
2001-03-14 07:49:03 +00:00
|
|
|
int32_t normSourceLen = UCOL_NORMALIZATION_MAX_BUFFER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-03 03:35:17 +00:00
|
|
|
int32_t len = (sourceLength == -1 ? u_strlen(source) : sourceLength);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
uint32_t variableMax = (coll->variableMax1<<8) | coll->variableMax2;
|
|
|
|
uint8_t UCOL_COMMON_BOT4 = (uint8_t)(coll->variableMax1+1);
|
2001-02-28 19:30:41 +00:00
|
|
|
uint8_t UCOL_BOT_COUNT4 = (uint8_t)(0xFF - UCOL_COMMON_BOT4);
|
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-02-28 19:30:41 +00:00
|
|
|
uint8_t compareSec = (uint8_t)((strength >= UCOL_SECONDARY)?0:0xFF);
|
|
|
|
uint8_t compareTer = (uint8_t)((strength >= UCOL_TERTIARY)?0:0xFF);
|
|
|
|
uint8_t compareQuad = (uint8_t)((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);
|
2001-01-16 00:28:40 +00:00
|
|
|
UBool isFrenchSec = (coll->frenchCollation == UCOL_ON) && (compareSec == 0);
|
2001-03-15 02:49:35 +00:00
|
|
|
UBool shifted = (coll->alternateHandling == UCOL_SHIFTED);
|
|
|
|
UBool qShifted = shifted && (compareQuad == 0);
|
2001-01-18 00:46:19 +00:00
|
|
|
const uint8_t *scriptOrder = coll->scriptOrder;
|
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-03-20 00:56:37 +00:00
|
|
|
sortKeySize += ((compareSec?0:1) + (compareTer?0:1) + (doCase?1:0) + (qShifted?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;
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(coll, (UChar *)source, len, &s);
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-01-16 00:28:40 +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-03-14 02:45:39 +00:00
|
|
|
if(compareIdent) {
|
|
|
|
if(unorm_quickCheck(source, len, UNORM_NFD, status) != UNORM_YES) {
|
|
|
|
normSourceLen = unorm_normalize(source, sourceLength, UNORM_NFD, 0, normSource, normSourceLen, status);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
*status=U_ZERO_ERROR;
|
2001-05-29 04:59:29 +00:00
|
|
|
normSource = (UChar *) uprv_malloc(normSourceLen*sizeof(UChar));
|
|
|
|
normSourceLen = unorm_normalize(source, sourceLength, UNORM_NFD, 0, normSource, normSourceLen, status);
|
2001-03-14 02:45:39 +00:00
|
|
|
}
|
2001-05-25 19:30:01 +00:00
|
|
|
IInit_collIterate(coll, normSource, normSourceLen, &s);
|
2001-04-06 23:37:48 +00:00
|
|
|
s.flags &= ~UCOL_ITER_NORM;
|
|
|
|
len = normSourceLen;
|
2001-03-14 02:45:39 +00:00
|
|
|
}
|
|
|
|
} else if((normMode != UCOL_OFF)
|
2001-02-15 19:30:25 +00:00
|
|
|
/* changed by synwee */
|
|
|
|
&& !checkFCD(source, len, status))
|
|
|
|
{
|
2001-02-15 20:21:21 +00:00
|
|
|
normSourceLen = unorm_normalize(source, sourceLength, UNORM_NFD, 0, normSource, normSourceLen, status);
|
2001-01-05 06:36:10 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
*status=U_ZERO_ERROR;
|
2001-05-29 04:59:29 +00:00
|
|
|
normSource = (UChar *) uprv_malloc(normSourceLen*sizeof(UChar));
|
|
|
|
normSourceLen = unorm_normalize(source, sourceLength, UNORM_NFD, 0, normSource, normSourceLen, status);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-05-25 19:30:01 +00:00
|
|
|
IInit_collIterate(coll, normSource, normSourceLen, &s);
|
2001-04-06 23:37:48 +00:00
|
|
|
s.flags &= ~UCOL_ITER_NORM;
|
|
|
|
len = normSourceLen;
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-03-23 07:48:40 +00:00
|
|
|
if(resultLength == 0 || primaries == NULL) {
|
2001-01-15 07:28:54 +00:00
|
|
|
return ucol_getSortKeySize(coll, &s, sortKeySize, strength, len);
|
2000-12-07 07:22:55 +00:00
|
|
|
}
|
2001-03-23 07:48:40 +00:00
|
|
|
uint8_t *primarySafeEnd = primaries + resultLength - 2;
|
2000-12-07 07:22:55 +00:00
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_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;
|
2000-11-22 00:04:03 +00:00
|
|
|
|
2001-01-08 06:51:18 +00:00
|
|
|
uint8_t primary1 = 0;
|
|
|
|
uint8_t primary2 = 0;
|
2001-01-05 00:47:25 +00:00
|
|
|
uint8_t secondary = 0;
|
|
|
|
uint8_t tertiary = 0;
|
2001-03-02 00:19:43 +00:00
|
|
|
uint8_t caseSwitch = coll->caseSwitch;
|
|
|
|
uint8_t tertiaryMask = coll->tertiaryMask;
|
2001-05-10 22:33:50 +00:00
|
|
|
int32_t tertiaryAddition = coll->tertiaryAddition;
|
|
|
|
uint8_t tertiaryTop = coll->tertiaryTop;
|
2001-05-17 23:14:44 +00:00
|
|
|
uint8_t tertiaryBottom = coll->tertiaryBottom;
|
2001-05-10 22:33:50 +00:00
|
|
|
uint8_t tertiaryCommon = coll->tertiaryCommon;
|
|
|
|
uint8_t caseBits = 0;
|
2000-11-22 00:04:03 +00:00
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
UBool finished = FALSE;
|
|
|
|
UBool resultOverflow = FALSE;
|
2001-01-24 16:18:48 +00:00
|
|
|
UBool wasShifted = FALSE;
|
2001-02-06 00:36:48 +00:00
|
|
|
UBool notIsContinuation = FALSE;
|
2000-11-22 23:52:43 +00:00
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_t prevBuffSize = 0;
|
2001-01-15 07:28:54 +00:00
|
|
|
|
2001-01-23 06:58:22 +00:00
|
|
|
uint32_t count2 = 0, count3 = 0, count4 = 0;
|
2001-05-03 23:33:29 +00:00
|
|
|
uint8_t leadPrimary = 0;
|
2001-01-18 00:46:19 +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-04-18 19:31:05 +00:00
|
|
|
order = ucol_IGetNextCE(coll, &s, status);
|
2000-11-29 00:16:15 +00:00
|
|
|
|
2001-01-24 16:18:48 +00:00
|
|
|
if(order == UCOL_NO_MORE_CES) {
|
2001-01-05 00:47:25 +00:00
|
|
|
finished = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
if(order == 0) {
|
2001-03-15 02:49:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
notIsContinuation = !isContinuation(order);
|
2001-01-08 06:51:18 +00:00
|
|
|
|
2001-05-10 22:33:50 +00:00
|
|
|
if(notIsContinuation) {
|
|
|
|
tertiary = (uint8_t)(order & UCOL_BYTE_SIZE_MASK);
|
|
|
|
} else {
|
|
|
|
tertiary = (uint8_t)((order & UCOL_REMOVE_CONTINUATION));
|
2001-03-16 19:06:07 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-03-14 07:49:03 +00:00
|
|
|
secondary = (uint8_t)((order >>= 8) & UCOL_BYTE_SIZE_MASK);
|
|
|
|
primary2 = (uint8_t)((order >>= 8) & UCOL_BYTE_SIZE_MASK);
|
2001-05-29 04:59:29 +00:00
|
|
|
primary1 = (uint8_t)(order >> 8);
|
2001-01-12 08:18:12 +00:00
|
|
|
|
2001-02-06 00:36:48 +00:00
|
|
|
if(notIsContinuation) {
|
2001-01-18 00:46:19 +00:00
|
|
|
if(scriptOrder != NULL) {
|
|
|
|
primary1 = scriptOrder[primary1];
|
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
}
|
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
if(shifted && ((notIsContinuation && order < variableMax && primary1 > 0)
|
2001-04-23 01:53:49 +00:00
|
|
|
|| (!notIsContinuation && wasShifted))) {
|
2001-01-23 06:58:22 +00:00
|
|
|
if(count4 > 0) {
|
2001-03-03 03:35:17 +00:00
|
|
|
while (count4 >= UCOL_BOT_COUNT4) {
|
|
|
|
*quads++ = (uint8_t)(UCOL_COMMON_BOT4 + UCOL_BOT_COUNT4);
|
|
|
|
count4 -= UCOL_BOT_COUNT4;
|
|
|
|
}
|
|
|
|
*quads++ = (uint8_t)(UCOL_COMMON_BOT4 + count4);
|
2001-01-23 06:58:22 +00:00
|
|
|
count4 = 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 */
|
2001-05-29 04:59:29 +00:00
|
|
|
if(primary1 != 0) { /* we need to check this since we could be in continuation */
|
2001-01-24 16:18:48 +00:00
|
|
|
*quads++ = primary1;
|
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
if(primary2 != 0) {
|
|
|
|
*quads++ = primary2;
|
|
|
|
}
|
2001-01-24 16:18:48 +00:00
|
|
|
wasShifted = TRUE;
|
2001-01-08 06:51:18 +00:00
|
|
|
} else {
|
2001-01-24 16:18:48 +00:00
|
|
|
wasShifted = FALSE;
|
2001-01-08 06:51:18 +00:00
|
|
|
/* 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 */
|
2001-05-29 04:59:29 +00:00
|
|
|
/* regular and simple sortkey calc */
|
2001-04-25 18:00:41 +00:00
|
|
|
if(primary1 != UCOL_IGNORABLE) {
|
|
|
|
if(notIsContinuation) {
|
|
|
|
if(leadPrimary == primary1) {
|
|
|
|
*primaries++ = primary2;
|
|
|
|
} else {
|
2001-04-24 23:32:40 +00:00
|
|
|
if(leadPrimary != 0) {
|
|
|
|
*primaries++ = (primary1 > leadPrimary) ? UCOL_BYTE_UNSHIFTED_MAX : UCOL_BYTE_UNSHIFTED_MIN;
|
|
|
|
}
|
2001-04-25 18:00:41 +00:00
|
|
|
if(primary2 == UCOL_IGNORABLE) {
|
|
|
|
/* one byter, not compressed */
|
|
|
|
*primaries++ = primary1;
|
|
|
|
leadPrimary = 0;
|
|
|
|
} else if(primary1<UCOL_BYTE_FIRST_NON_LATIN_PRIMARY ||
|
2001-05-11 01:13:08 +00:00
|
|
|
(primary1 > (UCOL_RESET_TOP_VALUE>>24) && primary1 < (UCOL_NEXT_TOP_VALUE>>24))) {
|
2001-04-25 18:00:41 +00:00
|
|
|
/* not compressible */
|
|
|
|
leadPrimary = 0;
|
|
|
|
*primaries++ = primary1;
|
|
|
|
*primaries++ = primary2;
|
|
|
|
} else { /* compress */
|
2001-05-11 01:13:08 +00:00
|
|
|
*primaries++ = leadPrimary = primary1;
|
2001-04-25 18:00:41 +00:00
|
|
|
*primaries++ = primary2;
|
2001-05-11 01:13:08 +00:00
|
|
|
}
|
2001-04-23 23:41:46 +00:00
|
|
|
}
|
2001-04-25 18:00:41 +00:00
|
|
|
} else { /* we are in continuation, so we're gonna add primary to the key don't care about compression */
|
2001-05-11 01:13:08 +00:00
|
|
|
*primaries++ = primary1;
|
2001-04-25 18:00:41 +00:00
|
|
|
if(primary2 != UCOL_IGNORABLE) {
|
|
|
|
*primaries++ = primary2; /* second part */
|
2001-04-24 23:32:40 +00:00
|
|
|
}
|
2001-04-23 23:41:46 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
if(secondary > compareSec) {
|
2001-01-26 00:12:23 +00:00
|
|
|
if(!isFrenchSec) {
|
2001-01-18 00:46:19 +00:00
|
|
|
/* This is compression code. */
|
2001-02-06 00:36:48 +00:00
|
|
|
if (secondary == UCOL_COMMON2 && notIsContinuation) {
|
2001-03-03 03:35:17 +00:00
|
|
|
++count2;
|
2001-01-12 08:18:12 +00:00
|
|
|
} else {
|
2001-03-03 03:35:17 +00:00
|
|
|
if (count2 > 0) {
|
|
|
|
if (secondary > UCOL_COMMON2) { // not necessary for 4th level.
|
|
|
|
while (count2 >= UCOL_TOP_COUNT2) {
|
2001-05-02 23:36:22 +00:00
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_TOP2 - UCOL_TOP_COUNT2);
|
|
|
|
count2 -= (uint32_t)UCOL_TOP_COUNT2;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_TOP2 - count2);
|
|
|
|
} else {
|
|
|
|
while (count2 >= UCOL_BOT_COUNT2) {
|
2001-05-02 23:36:22 +00:00
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + UCOL_BOT_COUNT2);
|
|
|
|
count2 -= (uint32_t)UCOL_BOT_COUNT2;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + count2);
|
|
|
|
}
|
|
|
|
count2 = 0;
|
|
|
|
}
|
2001-01-12 08:18:12 +00:00
|
|
|
*secondaries++ = secondary;
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*secondaries++ = secondary;
|
|
|
|
/* 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 */
|
2001-06-06 23:26:50 +00:00
|
|
|
if(notIsContinuation) {
|
2001-05-29 04:59:29 +00:00
|
|
|
if (frenchStartPtr != NULL) {
|
|
|
|
/* reverse secondaries from frenchStartPtr up to frenchEndPtr */
|
|
|
|
uprv_ucol_reverse_buffer(uint8_t, frenchStartPtr, frenchEndPtr);
|
|
|
|
frenchStartPtr = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2001-01-26 00:12:23 +00:00
|
|
|
if (frenchStartPtr == NULL) {
|
|
|
|
frenchStartPtr = secondaries - 2;
|
2001-01-08 06:51:18 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
frenchEndPtr = secondaries-1;
|
2001-06-06 23:26:50 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(doCase) {
|
2001-05-10 22:33:50 +00:00
|
|
|
doCaseShift(&cases, caseShift);
|
2001-03-16 19:06:07 +00:00
|
|
|
if(notIsContinuation) {
|
2001-05-10 22:33:50 +00:00
|
|
|
caseBits = (tertiary & 0xC0);
|
|
|
|
|
2001-03-16 19:06:07 +00:00
|
|
|
if(tertiary != 0) {
|
2001-05-10 22:33:50 +00:00
|
|
|
if(coll->caseFirst == UCOL_UPPER_FIRST) {
|
|
|
|
if((caseBits & 0xC0) == 0) {
|
|
|
|
*(cases-1) |= 1 << (--caseShift);
|
|
|
|
} else {
|
|
|
|
*(cases-1) |= 0 << (--caseShift);
|
|
|
|
/* second bit */
|
|
|
|
doCaseShift(&cases, caseShift);
|
|
|
|
*(cases-1) |= ((caseBits>>6)&1) << (--caseShift);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if((caseBits & 0xC0) == 0) {
|
|
|
|
*(cases-1) |= 0 << (--caseShift);
|
|
|
|
} else {
|
|
|
|
*(cases-1) |= 1 << (--caseShift);
|
|
|
|
/* second bit */
|
|
|
|
doCaseShift(&cases, caseShift);
|
|
|
|
*(cases-1) |= ((caseBits>>7)&1) << (--caseShift);
|
|
|
|
}
|
|
|
|
}
|
2001-03-16 19:06:07 +00:00
|
|
|
}
|
2001-05-10 22:33:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(notIsContinuation) {
|
|
|
|
tertiary ^= caseSwitch;
|
2001-01-08 06:51:18 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
|
2001-05-10 22:33:50 +00:00
|
|
|
tertiary &= tertiaryMask;
|
2001-04-23 01:53:49 +00:00
|
|
|
if(tertiary > compareTer) {
|
2001-01-25 06:51:18 +00:00
|
|
|
/* This is compression code. */
|
|
|
|
/* sequence size check is included in the if clause */
|
2001-05-10 22:33:50 +00:00
|
|
|
if (tertiary == tertiaryCommon && notIsContinuation) {
|
2001-03-03 03:35:17 +00:00
|
|
|
++count3;
|
2001-01-25 06:51:18 +00:00
|
|
|
} else {
|
2001-05-11 01:13:08 +00:00
|
|
|
if((tertiary > tertiaryCommon && tertiaryCommon == UCOL_COMMON3_NORMAL)
|
2001-05-10 22:33:50 +00:00
|
|
|
|| (tertiary <= tertiaryCommon && tertiaryCommon == UCOL_COMMON3_UPPERFIRST)) {
|
|
|
|
tertiary += tertiaryAddition;
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
2001-03-03 03:35:17 +00:00
|
|
|
if (count3 > 0) {
|
2001-05-17 23:14:44 +00:00
|
|
|
if ((tertiary > tertiaryCommon)) {
|
2001-05-10 22:33:50 +00:00
|
|
|
while (count3 >= coll->tertiaryTopCount) {
|
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - coll->tertiaryTopCount);
|
|
|
|
count3 -= (uint32_t)coll->tertiaryTopCount;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-05-10 22:33:50 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - count3);
|
2001-03-03 03:35:17 +00:00
|
|
|
} else {
|
2001-05-10 22:33:50 +00:00
|
|
|
while (count3 >= coll->tertiaryBottomCount) {
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + coll->tertiaryBottomCount);
|
2001-05-10 22:33:50 +00:00
|
|
|
count3 -= (uint32_t)coll->tertiaryBottomCount;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + count3);
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
|
|
|
count3 = 0;
|
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
*tertiaries++ = tertiary;
|
2001-01-12 08:18:12 +00:00
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-03-15 02:49:35 +00:00
|
|
|
if(qShifted && notIsContinuation) {
|
2001-01-25 06:51:18 +00:00
|
|
|
count4++;
|
|
|
|
}
|
2001-01-08 06:51:18 +00:00
|
|
|
}
|
|
|
|
|
2001-02-06 00:36:48 +00:00
|
|
|
if(primaries > primarySafeEnd) { /* We have stepped over the primary buffer */
|
2001-02-06 06:50:16 +00:00
|
|
|
int32_t sks = sortKeySize+(primaries - primStart)+(secondaries - secStart)+(tertiaries - terStart)+(cases-caseStart)+(quads-quadStart);
|
2001-01-08 06:51:18 +00:00
|
|
|
if(allocatePrimary == FALSE) { /* need to save our butts if we cannot reallocate */
|
|
|
|
resultOverflow = TRUE;
|
2001-02-06 06:50:16 +00:00
|
|
|
sortKeySize = ucol_getSortKeySize(coll, &s, sks, strength, len);
|
2001-01-08 06:51:18 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
finished = TRUE;
|
|
|
|
break;
|
|
|
|
} else { /* It's much nicer if we can actually reallocate */
|
2001-03-14 07:49:03 +00:00
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sks, status);
|
|
|
|
*result = primStart;
|
2001-02-06 06:50:16 +00:00
|
|
|
primarySafeEnd = primStart + resultLength - 2;
|
2001-01-08 06:51:18 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(finished) {
|
|
|
|
break;
|
|
|
|
} else {
|
2001-01-05 06:36:10 +00:00
|
|
|
prevBuffSize = minBufferSize;
|
2001-03-14 07:49:03 +00:00
|
|
|
secStart = reallocateBuffer(&secondaries, secStart, second, &secSize, 2*secSize, status);
|
|
|
|
terStart = reallocateBuffer(&tertiaries, terStart, tert, &terSize, 2*terSize, status);
|
|
|
|
caseStart = reallocateBuffer(&cases, caseStart, caseB, &caseSize, 2*caseSize, status);
|
|
|
|
quadStart = reallocateBuffer(&quads, quadStart, quad, &quadSize, 2*quadSize, status);
|
2001-01-05 06:36:10 +00:00
|
|
|
minBufferSize *= 2;
|
2000-11-30 23:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-14 01:11:11 +00:00
|
|
|
|
2001-03-14 07:49:03 +00:00
|
|
|
/* Here, we are generally done with processing */
|
|
|
|
/* bailing out would not be too productive */
|
|
|
|
|
2001-02-06 00:36:48 +00:00
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
2001-02-06 06:50:16 +00:00
|
|
|
sortKeySize += (primaries - primStart);
|
2001-01-05 06:36:10 +00:00
|
|
|
/* 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-03-03 03:35:17 +00:00
|
|
|
if (count2 > 0) {
|
|
|
|
while (count2 >= UCOL_BOT_COUNT2) {
|
2001-05-02 23:36:22 +00:00
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + UCOL_BOT_COUNT2);
|
|
|
|
count2 -= (uint32_t)UCOL_BOT_COUNT2;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + count2);
|
|
|
|
}
|
2001-03-14 07:49:03 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
2001-01-05 06:36:10 +00:00
|
|
|
uint32_t secsize = secondaries-secStart;
|
2001-02-06 06:50:16 +00:00
|
|
|
sortKeySize += secsize;
|
2001-03-14 07:49:03 +00:00
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
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 */
|
2001-04-23 01:53:49 +00:00
|
|
|
if(frenchStartPtr != NULL) {
|
2001-03-14 07:49:03 +00:00
|
|
|
uprv_ucol_reverse_buffer(uint8_t, frenchStartPtr, frenchEndPtr);
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-14 07:49:03 +00:00
|
|
|
for(i = 0; i<secsize; i++) {
|
|
|
|
*(primaries++) = *(secondaries-i-1);
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
} else {
|
|
|
|
uprv_memcpy(primaries, secStart, secsize);
|
2001-03-14 07:49:03 +00:00
|
|
|
primaries += secsize;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(allocatePrimary == TRUE) { /* need to save our butts if we cannot reallocate */
|
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sortKeySize, status);
|
|
|
|
*result = primStart;
|
|
|
|
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 */
|
2001-04-23 01:53:49 +00:00
|
|
|
if(frenchStartPtr != NULL) {
|
2001-03-14 07:49:03 +00:00
|
|
|
uprv_ucol_reverse_buffer(uint8_t, frenchStartPtr, frenchEndPtr);
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-14 07:49:03 +00:00
|
|
|
for(i = 0; i<secsize; i++) {
|
|
|
|
*(primaries++) = *(secondaries-i-1);
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
} else {
|
|
|
|
uprv_memcpy(primaries, secStart, secsize);
|
2001-03-14 07:49:03 +00:00
|
|
|
primaries += secsize;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
2001-01-08 06:51:18 +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) {
|
|
|
|
uint32_t casesize = cases - caseStart;
|
2001-02-06 06:50:16 +00:00
|
|
|
sortKeySize += casesize;
|
2001-03-14 07:49:03 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
uprv_memcpy(primaries, caseStart, casesize);
|
|
|
|
primaries += casesize;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
if(allocatePrimary == TRUE) {
|
2001-03-14 07:49:03 +00:00
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sortKeySize, status);
|
|
|
|
*result = primStart;
|
|
|
|
uprv_memcpy(primaries, caseStart, casesize);
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2001-01-05 06:36:10 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-01-09 00:52:18 +00:00
|
|
|
if(compareTer == 0) {
|
2001-03-03 03:35:17 +00:00
|
|
|
if (count3 > 0) {
|
2001-05-10 22:33:50 +00:00
|
|
|
if (coll->tertiaryCommon != UCOL_COMMON_BOT3) {
|
|
|
|
while (count3 >= coll->tertiaryTopCount) {
|
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - coll->tertiaryTopCount);
|
|
|
|
count3 -= (uint32_t)coll->tertiaryTopCount;
|
|
|
|
}
|
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - count3);
|
|
|
|
} else {
|
|
|
|
while (count3 >= coll->tertiaryBottomCount) {
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + coll->tertiaryBottomCount);
|
2001-05-10 22:33:50 +00:00
|
|
|
count3 -= (uint32_t)coll->tertiaryBottomCount;
|
|
|
|
}
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + count3);
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-05 06:36:10 +00:00
|
|
|
uint32_t tersize = tertiaries - terStart;
|
2001-02-06 06:50:16 +00:00
|
|
|
sortKeySize += tersize;
|
2001-03-14 07:49:03 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
uprv_memcpy(primaries, terStart, tersize);
|
|
|
|
primaries += tersize;
|
2001-03-20 00:56:37 +00:00
|
|
|
if(/*compareQuad == 0*/qShifted == TRUE) {
|
2001-03-14 07:49:03 +00:00
|
|
|
if(count4 > 0) {
|
|
|
|
while (count4 >= UCOL_BOT_COUNT4) {
|
|
|
|
*quads++ = (uint8_t)(UCOL_COMMON_BOT4 + UCOL_BOT_COUNT4);
|
|
|
|
count4 -= UCOL_BOT_COUNT4;
|
|
|
|
}
|
|
|
|
*quads++ = (uint8_t)(UCOL_COMMON_BOT4 + count4);
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-03-14 07:49:03 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
uint32_t quadsize = quads - quadStart;
|
|
|
|
sortKeySize += quadsize;
|
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
uprv_memcpy(primaries, quadStart, quadsize);
|
|
|
|
primaries += quadsize;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
if(allocatePrimary == TRUE) {
|
2001-03-14 07:49:03 +00:00
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sortKeySize, status);
|
|
|
|
*result = primStart;
|
|
|
|
uprv_memcpy(primaries, quadStart, quadsize);
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
if(allocatePrimary == TRUE) {
|
2001-03-14 07:49:03 +00:00
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sortKeySize, status);
|
|
|
|
*result = primStart;
|
|
|
|
uprv_memcpy(primaries, terStart, tersize);
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2001-01-18 00:46:19 +00:00
|
|
|
}
|
2001-01-05 06:36:10 +00:00
|
|
|
|
2001-01-18 00:46:19 +00:00
|
|
|
if(compareIdent) {
|
2001-04-19 19:02:01 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
2001-05-29 04:59:29 +00:00
|
|
|
sortKeySize += u_lengthOfIdenticalLevelRun(s.string, len);
|
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
primaries += u_writeIdenticalLevelRun(s.string, len, primaries);
|
|
|
|
} else {
|
|
|
|
if(allocatePrimary == TRUE) {
|
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, sortKeySize, status);
|
|
|
|
*result = primStart;
|
|
|
|
u_writeIdenticalLevelRun(s.string, len, primaries);
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2001-02-06 06:50:16 +00:00
|
|
|
}
|
2001-04-19 19:02:01 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 06:36:10 +00:00
|
|
|
}
|
|
|
|
*(primaries++) = '\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);
|
|
|
|
}
|
|
|
|
|
2001-03-14 07:49:03 +00:00
|
|
|
if(allocatePrimary == TRUE) {
|
|
|
|
*result = (uint8_t*)uprv_malloc(sortKeySize);
|
|
|
|
uprv_memcpy(*result, primStart, sortKeySize);
|
|
|
|
if(primStart != prim) {
|
|
|
|
uprv_free(primStart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-05 00:47:25 +00:00
|
|
|
return sortKeySize;
|
|
|
|
}
|
|
|
|
|
2001-05-10 22:12:53 +00:00
|
|
|
|
2001-02-07 00:57:39 +00:00
|
|
|
int32_t
|
|
|
|
ucol_calcSortKeySimpleTertiary(const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t **result,
|
2001-03-14 02:45:39 +00:00
|
|
|
uint32_t resultLength,
|
2001-02-07 00:57:39 +00:00
|
|
|
UBool allocatePrimary,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-05-10 22:12:53 +00:00
|
|
|
U_ALIGN_CODE(16);
|
2001-02-07 00:57:39 +00:00
|
|
|
uint32_t i = 0; /* general purpose counter */
|
|
|
|
|
|
|
|
/* Stack allocated buffers for buffers we use */
|
2001-03-14 07:49:03 +00:00
|
|
|
uint8_t prim[UCOL_PRIMARY_MAX_BUFFER], second[UCOL_SECONDARY_MAX_BUFFER], tert[UCOL_TERTIARY_MAX_BUFFER];
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
uint8_t *primaries = *result, *secondaries = second, *tertiaries = tert;
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(primaries == NULL && allocatePrimary == TRUE) {
|
2001-03-14 07:49:03 +00:00
|
|
|
primaries = *result = prim;
|
|
|
|
resultLength = UCOL_PRIMARY_MAX_BUFFER;
|
2001-02-07 00:57:39 +00:00
|
|
|
}
|
|
|
|
|
2001-03-14 07:49:03 +00:00
|
|
|
uint32_t secSize = UCOL_SECONDARY_MAX_BUFFER, terSize = UCOL_TERTIARY_MAX_BUFFER;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-03-22 21:16:20 +00:00
|
|
|
uint32_t sortKeySize = 3; /* it is always \0 terminated plus separators for secondary and tertiary */
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-03-14 07:49:03 +00:00
|
|
|
UChar normBuffer[UCOL_NORMALIZATION_MAX_BUFFER];
|
2001-02-07 00:57:39 +00:00
|
|
|
UChar *normSource = normBuffer;
|
2001-03-14 07:49:03 +00:00
|
|
|
int32_t normSourceLen = UCOL_NORMALIZATION_MAX_BUFFER;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-05-10 22:12:53 +00:00
|
|
|
int32_t len = sourceLength;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
collIterate s;
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(coll, (UChar *)source, len, &s);
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
/* If we need to normalize, we'll do it all at once at the beggining! */
|
|
|
|
UColAttributeValue normMode = coll->normalizationMode;
|
2001-05-10 22:12:53 +00:00
|
|
|
if(normMode != UCOL_OFF) {
|
|
|
|
if (!checkFCD(source, len, status))
|
|
|
|
{
|
|
|
|
normSourceLen = unorm_normalize(source, sourceLength, UNORM_NFD, 0, normSource, normSourceLen, status);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
*status=U_ZERO_ERROR;
|
|
|
|
normSource = (UChar *) uprv_malloc((normSourceLen+1)*sizeof(UChar));
|
|
|
|
normSourceLen = unorm_normalize(source, sourceLength, UNORM_NFD, 0, normSource, (normSourceLen+1), status);
|
|
|
|
}
|
2001-05-25 19:30:01 +00:00
|
|
|
IInit_collIterate(coll, normSource, normSourceLen, &s);
|
2001-05-10 22:12:53 +00:00
|
|
|
s.flags &= ~(UCOL_ITER_NORM);
|
|
|
|
len = normSourceLen;
|
2001-02-07 00:57:39 +00:00
|
|
|
}
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-03-23 07:48:40 +00:00
|
|
|
if(resultLength == 0 || primaries == NULL) {
|
2001-05-17 23:09:35 +00:00
|
|
|
int32_t t = ucol_getSortKeySize(coll, &s, sortKeySize, coll->strength, len);
|
|
|
|
if(normSource != normBuffer) {
|
|
|
|
uprv_free(normSource);
|
2001-02-07 00:57:39 +00:00
|
|
|
}
|
2001-05-17 23:09:35 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2001-03-23 07:48:40 +00:00
|
|
|
uint8_t *primarySafeEnd = primaries + resultLength - 2;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_t minBufferSize = UCOL_MAX_BUFFER;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
uint8_t *primStart = primaries;
|
|
|
|
uint8_t *secStart = secondaries;
|
|
|
|
uint8_t *terStart = tertiaries;
|
|
|
|
|
|
|
|
uint32_t order = 0;
|
|
|
|
|
|
|
|
uint8_t primary1 = 0;
|
|
|
|
uint8_t primary2 = 0;
|
|
|
|
uint8_t secondary = 0;
|
|
|
|
uint8_t tertiary = 0;
|
2001-03-02 00:19:43 +00:00
|
|
|
uint8_t caseSwitch = coll->caseSwitch;
|
|
|
|
uint8_t tertiaryMask = coll->tertiaryMask;
|
2001-05-10 22:33:50 +00:00
|
|
|
int8_t tertiaryAddition = coll->tertiaryAddition;
|
|
|
|
uint8_t tertiaryTop = coll->tertiaryTop;
|
2001-05-17 23:14:44 +00:00
|
|
|
uint8_t tertiaryBottom = coll->tertiaryBottom;
|
2001-05-10 22:33:50 +00:00
|
|
|
uint8_t tertiaryCommon = coll->tertiaryCommon;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
uint32_t prevBuffSize = 0;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
UBool finished = FALSE;
|
|
|
|
UBool resultOverflow = FALSE;
|
|
|
|
UBool notIsContinuation = FALSE;
|
|
|
|
|
|
|
|
uint32_t count2 = 0, count3 = 0;
|
2001-05-03 23:33:29 +00:00
|
|
|
uint8_t leadPrimary = 0;
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
for(i=prevBuffSize; i<minBufferSize; ++i) {
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
order = ucol_IGetNextCE(coll, &s, status);
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
if(order == 0) {
|
2001-02-07 00:57:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(order == UCOL_NO_MORE_CES) {
|
|
|
|
finished = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
notIsContinuation = !isContinuation(order);
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-03-16 19:06:07 +00:00
|
|
|
if(notIsContinuation) {
|
2001-04-23 01:53:49 +00:00
|
|
|
tertiary = (uint8_t)((order & tertiaryMask));
|
2001-03-16 19:06:07 +00:00
|
|
|
} else {
|
2001-05-10 22:33:50 +00:00
|
|
|
tertiary = (uint8_t)((order & UCOL_REMOVE_CONTINUATION));
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-14 07:49:03 +00:00
|
|
|
secondary = (uint8_t)((order >>= 8) & UCOL_BYTE_SIZE_MASK);
|
|
|
|
primary2 = (uint8_t)((order >>= 8) & UCOL_BYTE_SIZE_MASK);
|
2001-05-29 04:59:29 +00:00
|
|
|
primary1 = (uint8_t)(order >> 8);
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
/* 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-05-29 04:59:29 +00:00
|
|
|
/* regular and simple sortkey calc */
|
2001-04-19 23:49:03 +00:00
|
|
|
if(primary1 != UCOL_IGNORABLE) {
|
|
|
|
if(notIsContinuation) {
|
2001-04-25 18:00:41 +00:00
|
|
|
if(leadPrimary == primary1) {
|
|
|
|
*primaries++ = primary2;
|
|
|
|
} else {
|
|
|
|
if(leadPrimary != 0) {
|
2001-04-24 23:32:40 +00:00
|
|
|
*primaries++ = (primary1 > leadPrimary) ? UCOL_BYTE_UNSHIFTED_MAX : UCOL_BYTE_UNSHIFTED_MIN;
|
2001-04-23 23:41:46 +00:00
|
|
|
}
|
2001-04-25 18:00:41 +00:00
|
|
|
if(primary2 == UCOL_IGNORABLE) {
|
|
|
|
/* one byter, not compressed */
|
|
|
|
*primaries++ = primary1;
|
|
|
|
leadPrimary = 0;
|
|
|
|
} else if(primary1<UCOL_BYTE_FIRST_NON_LATIN_PRIMARY ||
|
2001-05-11 01:13:08 +00:00
|
|
|
(primary1 > (UCOL_RESET_TOP_VALUE>>24) && primary1 < (UCOL_NEXT_TOP_VALUE>>24))) {
|
2001-04-25 18:00:41 +00:00
|
|
|
/* not compressible */
|
|
|
|
leadPrimary = 0;
|
|
|
|
*primaries++ = primary1;
|
|
|
|
*primaries++ = primary2;
|
|
|
|
} else { /* compress */
|
2001-05-11 01:13:08 +00:00
|
|
|
*primaries++ = leadPrimary = primary1;
|
2001-04-25 18:00:41 +00:00
|
|
|
*primaries++ = primary2;
|
2001-05-11 01:13:08 +00:00
|
|
|
}
|
2001-04-24 23:32:40 +00:00
|
|
|
}
|
|
|
|
} else { /* we are in continuation, so we're gonna add primary to the key don't care about compression */
|
2001-05-11 01:13:08 +00:00
|
|
|
*primaries++ = primary1;
|
2001-04-24 23:32:40 +00:00
|
|
|
if(primary2 != UCOL_IGNORABLE) {
|
|
|
|
*primaries++ = primary2; /* second part */
|
2001-04-23 23:41:46 +00:00
|
|
|
}
|
2001-04-19 23:49:03 +00:00
|
|
|
}
|
2001-05-11 01:13:08 +00:00
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-05-29 04:59:29 +00:00
|
|
|
if(secondary > 0) { /* I think that != 0 test should be != IGNORABLE */
|
2001-03-14 02:45:39 +00:00
|
|
|
/* This is compression code. */
|
|
|
|
if (secondary == UCOL_COMMON2 && notIsContinuation) {
|
|
|
|
++count2;
|
|
|
|
} else {
|
|
|
|
if (count2 > 0) {
|
|
|
|
if (secondary > UCOL_COMMON2) { // not necessary for 4th level.
|
|
|
|
while (count2 >= UCOL_TOP_COUNT2) {
|
2001-05-02 23:36:22 +00:00
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_TOP2 - UCOL_TOP_COUNT2);
|
|
|
|
count2 -= (uint32_t)UCOL_TOP_COUNT2;
|
2001-03-14 02:45:39 +00:00
|
|
|
}
|
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_TOP2 - count2);
|
|
|
|
} else {
|
|
|
|
while (count2 >= UCOL_BOT_COUNT2) {
|
2001-05-02 23:36:22 +00:00
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + UCOL_BOT_COUNT2);
|
|
|
|
count2 -= (uint32_t)UCOL_BOT_COUNT2;
|
2001-03-14 02:45:39 +00:00
|
|
|
}
|
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + count2);
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-03-14 02:45:39 +00:00
|
|
|
count2 = 0;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-03-14 02:45:39 +00:00
|
|
|
*secondaries++ = secondary;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
}
|
|
|
|
|
2001-05-10 22:33:50 +00:00
|
|
|
if(notIsContinuation) {
|
|
|
|
tertiary ^= caseSwitch;
|
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-05-10 22:12:53 +00:00
|
|
|
if(tertiary > 0) {
|
2001-03-14 02:45:39 +00:00
|
|
|
/* This is compression code. */
|
|
|
|
/* sequence size check is included in the if clause */
|
2001-05-10 22:33:50 +00:00
|
|
|
if (tertiary == tertiaryCommon && notIsContinuation) {
|
2001-03-14 02:45:39 +00:00
|
|
|
++count3;
|
|
|
|
} else {
|
2001-05-17 23:14:44 +00:00
|
|
|
if(tertiary > tertiaryCommon && tertiaryCommon == UCOL_COMMON3_NORMAL) {
|
2001-05-10 22:33:50 +00:00
|
|
|
tertiary += tertiaryAddition;
|
2001-05-17 23:14:44 +00:00
|
|
|
} else if (tertiary <= tertiaryCommon && tertiaryCommon == UCOL_COMMON3_UPPERFIRST) {
|
|
|
|
tertiary -= tertiaryAddition;
|
2001-03-14 02:45:39 +00:00
|
|
|
}
|
|
|
|
if (count3 > 0) {
|
2001-05-17 23:14:44 +00:00
|
|
|
if ((tertiary > tertiaryCommon)) {
|
2001-05-10 22:33:50 +00:00
|
|
|
while (count3 >= coll->tertiaryTopCount) {
|
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - coll->tertiaryTopCount);
|
|
|
|
count3 -= (uint32_t)coll->tertiaryTopCount;
|
2001-03-14 02:45:39 +00:00
|
|
|
}
|
2001-05-10 22:33:50 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - count3);
|
2001-03-14 02:45:39 +00:00
|
|
|
} else {
|
2001-05-10 22:33:50 +00:00
|
|
|
while (count3 >= coll->tertiaryBottomCount) {
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + coll->tertiaryBottomCount);
|
2001-05-10 22:33:50 +00:00
|
|
|
count3 -= (uint32_t)coll->tertiaryBottomCount;
|
2001-03-14 02:45:39 +00:00
|
|
|
}
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + count3);
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-03-14 02:45:39 +00:00
|
|
|
count3 = 0;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-03-14 02:45:39 +00:00
|
|
|
*tertiaries++ = tertiary;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(primaries > primarySafeEnd) { /* We have stepped over the primary buffer */
|
|
|
|
int32_t sks = sortKeySize+(primaries - primStart)+(secondaries - secStart)+(tertiaries - terStart);
|
|
|
|
if(allocatePrimary == FALSE) { /* need to save our butts if we cannot reallocate */
|
|
|
|
resultOverflow = TRUE;
|
|
|
|
sortKeySize = ucol_getSortKeySize(coll, &s, sks, coll->strength, len);
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
finished = TRUE;
|
|
|
|
break;
|
|
|
|
} else { /* It's much nicer if we can actually reallocate */
|
2001-03-14 07:49:03 +00:00
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sks, status);
|
|
|
|
*result = primStart;
|
2001-02-07 00:57:39 +00:00
|
|
|
primarySafeEnd = primStart + resultLength - 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(finished) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
prevBuffSize = minBufferSize;
|
2001-03-14 07:49:03 +00:00
|
|
|
secStart = reallocateBuffer(&secondaries, secStart, second, &secSize, 2*secSize, status);
|
|
|
|
terStart = reallocateBuffer(&tertiaries, terStart, tert, &terSize, 2*terSize, status);
|
2001-02-07 00:57:39 +00:00
|
|
|
minBufferSize *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
sortKeySize += (primaries - primStart);
|
|
|
|
/* we have done all the CE's, now let's put them together to form a key */
|
2001-03-03 03:35:17 +00:00
|
|
|
if (count2 > 0) {
|
|
|
|
while (count2 >= UCOL_BOT_COUNT2) {
|
2001-05-02 23:36:22 +00:00
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + UCOL_BOT_COUNT2);
|
|
|
|
count2 -= (uint32_t)UCOL_BOT_COUNT2;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
|
|
|
*secondaries++ = (uint8_t)(UCOL_COMMON_BOT2 + count2);
|
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
uint32_t secsize = secondaries-secStart;
|
|
|
|
sortKeySize += secsize;
|
2001-03-14 07:49:03 +00:00
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
2001-04-23 01:53:49 +00:00
|
|
|
uprv_memcpy(primaries, secStart, secsize);
|
2001-03-14 07:49:03 +00:00
|
|
|
primaries += secsize;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
if(allocatePrimary == TRUE) {
|
2001-03-14 07:49:03 +00:00
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sortKeySize, status);
|
|
|
|
*result = primStart;
|
2001-04-23 01:53:49 +00:00
|
|
|
uprv_memcpy(primaries, secStart, secsize);
|
2001-03-14 07:49:03 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
|
2001-03-03 03:35:17 +00:00
|
|
|
if (count3 > 0) {
|
2001-05-17 23:14:44 +00:00
|
|
|
if (coll->tertiaryCommon != UCOL_COMMON3_NORMAL) {
|
2001-05-10 22:33:50 +00:00
|
|
|
while (count3 >= coll->tertiaryTopCount) {
|
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - coll->tertiaryTopCount);
|
|
|
|
count3 -= (uint32_t)coll->tertiaryTopCount;
|
|
|
|
}
|
|
|
|
*tertiaries++ = (uint8_t)(tertiaryTop - count3);
|
|
|
|
} else {
|
|
|
|
while (count3 >= coll->tertiaryBottomCount) {
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + coll->tertiaryBottomCount);
|
2001-05-10 22:33:50 +00:00
|
|
|
count3 -= (uint32_t)coll->tertiaryBottomCount;
|
|
|
|
}
|
2001-05-17 23:14:44 +00:00
|
|
|
*tertiaries++ = (uint8_t)(tertiaryBottom + count3);
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
uint32_t tersize = tertiaries - terStart;
|
|
|
|
sortKeySize += tersize;
|
2001-03-14 07:49:03 +00:00
|
|
|
if(sortKeySize <= resultLength) {
|
|
|
|
uprv_memcpy(primaries, terStart, tersize);
|
|
|
|
primaries += tersize;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
if(allocatePrimary == TRUE) {
|
2001-03-14 07:49:03 +00:00
|
|
|
primStart = reallocateBuffer(&primaries, *result, prim, &resultLength, 2*sortKeySize, status);
|
|
|
|
*result = primStart;
|
|
|
|
uprv_memcpy(primaries, terStart, tersize);
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2001-02-07 00:57:39 +00:00
|
|
|
|
|
|
|
*(primaries++) = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(terStart != tert) {
|
|
|
|
uprv_free(terStart);
|
|
|
|
uprv_free(secStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(normSource != normBuffer) {
|
|
|
|
uprv_free(normSource);
|
|
|
|
}
|
|
|
|
|
2001-03-14 07:49:03 +00:00
|
|
|
if(allocatePrimary == TRUE) {
|
|
|
|
*result = (uint8_t*)uprv_malloc(sortKeySize);
|
|
|
|
uprv_memcpy(*result, primStart, sortKeySize);
|
|
|
|
if(primStart != prim) {
|
|
|
|
uprv_free(primStart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-07 00:57:39 +00:00
|
|
|
return sortKeySize;
|
|
|
|
}
|
|
|
|
|
2001-06-03 23:40:41 +00:00
|
|
|
inline void uprv_appendByteToHexString(char *dst, uint8_t val) {
|
|
|
|
uint32_t len = uprv_strlen(dst);
|
|
|
|
*(dst+len) = T_CString_itosOffset((val >> 4));
|
|
|
|
*(dst+len+1) = T_CString_itosOffset((val & 0xF));
|
|
|
|
*(dst+len+2) = 0;
|
|
|
|
}
|
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
/* this function makes a string with representation of a sortkey */
|
|
|
|
U_CAPI char U_EXPORT2 *ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t *len) {
|
2001-03-22 21:16:20 +00:00
|
|
|
int32_t strength = UCOL_PRIMARY;
|
2001-03-20 00:56:37 +00:00
|
|
|
uint32_t res_size = 0;
|
|
|
|
UBool doneCase = FALSE;
|
|
|
|
|
|
|
|
char *current = buffer;
|
|
|
|
const uint8_t *currentSk = sortkey;
|
|
|
|
|
2001-06-03 23:40:41 +00:00
|
|
|
uprv_strcpy(current, "[");
|
2001-03-20 00:56:37 +00:00
|
|
|
|
|
|
|
while(strength <= UCOL_QUATERNARY && strength <= coll->strength) {
|
|
|
|
if(strength > UCOL_PRIMARY) {
|
2001-06-03 23:40:41 +00:00
|
|
|
strcat(current, " . ");
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
while(*currentSk != 0x01 && *currentSk != 0x00) { /* print a level */
|
2001-06-03 23:40:41 +00:00
|
|
|
uprv_appendByteToHexString(current, *currentSk++);
|
|
|
|
uprv_strcat(current, " ");
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
if(coll->caseLevel == UCOL_ON && strength == UCOL_SECONDARY && doneCase == FALSE) {
|
|
|
|
doneCase = TRUE;
|
|
|
|
} else if(coll->caseLevel == UCOL_OFF || doneCase == TRUE || strength != UCOL_SECONDARY) {
|
|
|
|
strength ++;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-06-03 23:40:41 +00:00
|
|
|
uprv_appendByteToHexString(current, *currentSk++); /* This should print '01' */
|
2001-03-20 00:56:37 +00:00
|
|
|
if(strength == UCOL_QUATERNARY && coll->alternateHandling == UCOL_NON_IGNORABLE) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(coll->strength == UCOL_IDENTICAL) {
|
2001-06-03 23:40:41 +00:00
|
|
|
uprv_strcat(current, " . ");
|
2001-03-20 00:56:37 +00:00
|
|
|
while(*currentSk != 0) {
|
2001-06-03 23:40:41 +00:00
|
|
|
uprv_appendByteToHexString(current, *currentSk++);
|
|
|
|
uprv_strcat(current, " ");
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
|
2001-06-03 23:40:41 +00:00
|
|
|
uprv_appendByteToHexString(current, *currentSk++);
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
2001-06-03 23:40:41 +00:00
|
|
|
uprv_strcat(current, "]");
|
2001-03-20 00:56:37 +00:00
|
|
|
|
2001-03-22 21:16:20 +00:00
|
|
|
if(res_size > *len) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Following are the functions that deal with the properties of a collator */
|
|
|
|
/* there are new APIs and some compatibility APIs */
|
|
|
|
/****************************************************************************/
|
2001-03-02 00:19:43 +00:00
|
|
|
void ucol_updateInternalState(UCollator *coll) {
|
2001-04-19 17:08:07 +00:00
|
|
|
/*
|
2001-04-05 22:48:23 +00:00
|
|
|
uint32_t variableMaxCE = ucmp32_get(coll->mapping, coll->variableTopValue);
|
|
|
|
coll->variableMax1 = (uint8_t)((variableMaxCE & 0xFF000000) >> 24);
|
|
|
|
coll->variableMax2 = (uint8_t)((variableMaxCE & 0x00FF0000) >> 16);
|
2001-04-19 17:08:07 +00:00
|
|
|
*/
|
|
|
|
coll->variableMax1 = (uint8_t)((coll->variableTopValue & 0xFF00) >> 8);
|
|
|
|
coll->variableMax2 = (uint8_t)((coll->variableTopValue & 0x00FF));
|
2001-04-05 22:48:23 +00:00
|
|
|
|
2001-05-10 22:33:50 +00:00
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
if(coll->caseFirst == UCOL_UPPER_FIRST) {
|
|
|
|
coll->caseSwitch = UCOL_CASE_SWITCH;
|
|
|
|
} else {
|
|
|
|
coll->caseSwitch = UCOL_NO_CASE_SWITCH;
|
|
|
|
}
|
2001-05-10 22:33:50 +00:00
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
if(coll->caseLevel == UCOL_ON || coll->caseFirst == UCOL_OFF) {
|
|
|
|
coll->tertiaryMask = UCOL_REMOVE_CASE;
|
2001-05-10 22:33:50 +00:00
|
|
|
coll->tertiaryCommon = UCOL_COMMON3_NORMAL;
|
|
|
|
coll->tertiaryAddition = UCOL_FLAG_BIT_MASK_CASE_SW_OFF;
|
|
|
|
coll->tertiaryTop = UCOL_COMMON_TOP3_CASE_SW_OFF;
|
2001-05-17 23:14:44 +00:00
|
|
|
coll->tertiaryBottom = UCOL_COMMON_BOT3;
|
2001-03-02 00:19:43 +00:00
|
|
|
} else {
|
|
|
|
coll->tertiaryMask = UCOL_KEEP_CASE;
|
2001-05-17 23:14:44 +00:00
|
|
|
coll->tertiaryAddition = UCOL_FLAG_BIT_MASK_CASE_SW_ON;
|
2001-05-10 22:33:50 +00:00
|
|
|
if(coll->caseFirst == UCOL_UPPER_FIRST) {
|
|
|
|
coll->tertiaryCommon = UCOL_COMMON3_UPPERFIRST;
|
2001-05-17 23:14:44 +00:00
|
|
|
coll->tertiaryTop = UCOL_COMMON_TOP3_CASE_SW_UPPER;
|
|
|
|
coll->tertiaryBottom = UCOL_COMMON_BOTTOM3_CASE_SW_UPPER;
|
2001-05-10 22:33:50 +00:00
|
|
|
} else {
|
|
|
|
coll->tertiaryCommon = UCOL_COMMON3_NORMAL;
|
2001-05-17 23:14:44 +00:00
|
|
|
coll->tertiaryTop = UCOL_COMMON_TOP3_CASE_SW_LOWER;
|
|
|
|
coll->tertiaryBottom = UCOL_COMMON_BOTTOM3_CASE_SW_LOWER;
|
2001-05-10 22:33:50 +00:00
|
|
|
}
|
2001-03-02 00:19:43 +00:00
|
|
|
}
|
2001-05-15 17:38:18 +00:00
|
|
|
|
|
|
|
/* Set the compression values */
|
|
|
|
uint8_t tertiaryTotal = coll->tertiaryTop - UCOL_COMMON_BOT3-1;
|
2001-05-28 20:57:59 +00:00
|
|
|
coll->tertiaryTopCount = (uint8_t)(UCOL_PROPORTION3*tertiaryTotal); /* we multilply double with int, but need only int */
|
2001-05-15 17:38:18 +00:00
|
|
|
coll->tertiaryBottomCount = tertiaryTotal - coll->tertiaryTopCount;
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
if(coll->caseLevel == UCOL_OFF && coll->strength == UCOL_TERTIARY
|
2001-03-15 02:49:35 +00:00
|
|
|
&& coll->frenchCollation == UCOL_OFF && coll->alternateHandling == UCOL_NON_IGNORABLE) {
|
2001-03-14 02:45:39 +00:00
|
|
|
coll->sortKeyGen = ucol_calcSortKeySimpleTertiary;
|
|
|
|
} else {
|
|
|
|
coll->sortKeyGen = ucol_calcSortKey;
|
|
|
|
}
|
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
|
|
|
|
/* Attribute setter API */
|
|
|
|
U_CAPI void ucol_setAttribute(UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status) {
|
2001-03-03 03:35:17 +00:00
|
|
|
switch(attr) {
|
|
|
|
case UCOL_FRENCH_COLLATION: /* attribute for direction of secondary weights*/
|
|
|
|
if(value == UCOL_ON) {
|
|
|
|
coll->frenchCollation = UCOL_ON;
|
2001-01-16 00:28:40 +00:00
|
|
|
coll->frenchCollationisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_OFF) {
|
|
|
|
coll->frenchCollation = UCOL_OFF;
|
2001-01-16 00:28:40 +00:00
|
|
|
coll->frenchCollationisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-16 00:28:40 +00:00
|
|
|
coll->frenchCollationisDefault = TRUE;
|
2001-03-30 00:23:46 +00:00
|
|
|
coll->frenchCollation = coll->options->frenchCollation;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
2001-01-05 00:47:25 +00:00
|
|
|
case UCOL_ALTERNATE_HANDLING: /* attribute for handling variable elements*/
|
2001-03-03 03:35:17 +00:00
|
|
|
if(value == UCOL_SHIFTED) {
|
|
|
|
coll->alternateHandling = UCOL_SHIFTED;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->alternateHandlingisDefault = FALSE;
|
2001-03-03 03:35:17 +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-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->alternateHandlingisDefault = TRUE;
|
2001-03-30 00:23:46 +00:00
|
|
|
coll->alternateHandling = coll->options->alternateHandling ;
|
2001-03-03 03:35:17 +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-03-03 03:35:17 +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-03-02 00:19:43 +00:00
|
|
|
} else if (value == UCOL_OFF) {
|
|
|
|
coll->caseFirst = UCOL_OFF;
|
|
|
|
coll->caseFirstisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-03-30 00:23:46 +00:00
|
|
|
coll->caseFirst = coll->options->caseFirst;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseFirstisDefault = TRUE;
|
2001-03-03 03:35:17 +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-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_OFF) {
|
|
|
|
coll->caseLevel = UCOL_OFF;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseLevelisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-03-30 00:23:46 +00:00
|
|
|
coll->caseLevel = coll->options->caseLevel;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->caseLevelisDefault = TRUE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_NORMALIZATION_MODE: /* attribute for normalization */
|
|
|
|
if(value == UCOL_ON) {
|
2001-01-05 00:47:25 +00:00
|
|
|
coll->normalizationMode = UCOL_ON;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_OFF) {
|
2001-01-05 00:47:25 +00:00
|
|
|
coll->normalizationMode = UCOL_OFF;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_ON_WITHOUT_HANGUL) {
|
2001-01-05 00:47:25 +00:00
|
|
|
coll->normalizationMode = UCOL_ON_WITHOUT_HANGUL ;
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->normalizationModeisDefault = TRUE;
|
2001-03-30 00:23:46 +00:00
|
|
|
coll->normalizationMode = coll->options->normalizationMode;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_STRENGTH: /* attribute for strength */
|
2001-01-05 00:47:25 +00:00
|
|
|
if (value == UCOL_DEFAULT) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->strengthisDefault = TRUE;
|
2001-03-30 00:23:46 +00:00
|
|
|
coll->strength = coll->options->strength;
|
2001-03-03 03:35:17 +00:00
|
|
|
} else if (value <= UCOL_IDENTICAL) {
|
2001-01-09 00:52:18 +00:00
|
|
|
coll->strengthisDefault = FALSE;
|
2001-03-03 03:35:17 +00:00
|
|
|
coll->strength = value;
|
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UCOL_ATTRIBUTE_COUNT:
|
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-02 00:19:43 +00:00
|
|
|
ucol_updateInternalState(coll);
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
U_CAPI UColAttributeValue ucol_getAttribute(const UCollator *coll, UColAttribute attr, UErrorCode *status) {
|
2001-03-03 03:35:17 +00:00
|
|
|
switch(attr) {
|
|
|
|
case UCOL_FRENCH_COLLATION: /* attribute for direction of secondary weights*/
|
2001-03-23 23:48:26 +00:00
|
|
|
return coll->frenchCollation;
|
2001-01-05 00:47:25 +00:00
|
|
|
case UCOL_ALTERNATE_HANDLING: /* attribute for handling variable elements*/
|
2001-03-23 23:48:26 +00:00
|
|
|
return coll->alternateHandling;
|
2001-03-03 03:35:17 +00:00
|
|
|
case UCOL_CASE_FIRST: /* who goes first, lower case or uppercase */
|
2001-03-23 23:48:26 +00:00
|
|
|
return coll->caseFirst;
|
2001-03-03 03:35:17 +00:00
|
|
|
case UCOL_CASE_LEVEL: /* do we have an extra case level */
|
2001-03-23 23:48:26 +00:00
|
|
|
return coll->caseLevel;
|
2001-03-03 03:35:17 +00:00
|
|
|
case UCOL_NORMALIZATION_MODE: /* attribute for normalization */
|
2001-03-23 23:48:26 +00:00
|
|
|
return coll->normalizationMode;
|
2001-03-03 03:35:17 +00:00
|
|
|
case UCOL_STRENGTH: /* attribute for strength */
|
2001-03-23 23:48:26 +00:00
|
|
|
return coll->strength;
|
2001-03-03 03:35:17 +00:00
|
|
|
case UCOL_ATTRIBUTE_COUNT:
|
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return UCOL_DEFAULT;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
U_CAPI void
|
|
|
|
ucol_setNormalization( UCollator *coll,
|
|
|
|
UNormalizationMode mode)
|
2001-01-05 00:47:25 +00:00
|
|
|
{
|
2001-01-15 07:28:54 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-01-05 00:47:25 +00:00
|
|
|
switch(mode) {
|
|
|
|
case UCOL_NO_NORMALIZATION:
|
2001-01-15 07:28:54 +00:00
|
|
|
ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_OFF, &status);
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN:
|
2001-01-15 07:28:54 +00:00
|
|
|
ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-01-15 07:28:54 +00:00
|
|
|
/* Shouldn't get here. */
|
|
|
|
/* This is quite a bad API */
|
|
|
|
/* deprecate */
|
|
|
|
/* *status = U_ILLEGAL_ARGUMENT_ERROR; */
|
|
|
|
return;
|
2001-01-05 00:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
U_CAPI UNormalizationMode
|
|
|
|
ucol_getNormalization(const UCollator* coll)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
if(ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &status) == UCOL_ON) {
|
2001-04-23 01:53:49 +00:00
|
|
|
return UNORM_NFD;
|
2001-01-16 00:28:40 +00:00
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
return UNORM_NONE;
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
ucol_setStrength( UCollator *coll,
|
|
|
|
UCollationStrength strength)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollationStrength
|
|
|
|
ucol_getStrength(const UCollator *coll)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
return ucol_getAttribute(coll, UCOL_STRENGTH, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Following are misc functions */
|
|
|
|
/* there are new APIs and some compatibility APIs */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2001-02-22 16:32:40 +00:00
|
|
|
U_CAPI UCollator *
|
2001-04-23 01:53:49 +00:00
|
|
|
ucol_safeClone(const UCollator *coll, void *stackBuffer, int32_t * pBufferSize, UErrorCode *status)
|
2001-02-22 16:32:40 +00:00
|
|
|
{
|
|
|
|
UCollator * localCollator;
|
|
|
|
int32_t bufferSizeNeeded = sizeof(UCollator);
|
|
|
|
|
|
|
|
if (status == NULL || U_FAILURE(*status)){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!pBufferSize || !coll){
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (*pBufferSize == 0){ /* 'preflighting' request - set needed size into *pBufferSize */
|
2001-03-03 03:35:17 +00:00
|
|
|
*pBufferSize = bufferSizeNeeded;
|
|
|
|
return 0;
|
2001-02-22 16:32:40 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
if (*pBufferSize < bufferSizeNeeded || stackBuffer == NULL) {
|
2001-02-22 16:32:40 +00:00
|
|
|
/* allocate one here...*/
|
|
|
|
int32_t length;
|
|
|
|
const UChar * rules = ucol_getRules(coll, &length);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
localCollator = ucol_openRules(rules,
|
|
|
|
length,
|
2001-02-22 16:32:40 +00:00
|
|
|
ucol_getNormalization(coll),
|
2001-04-23 01:53:49 +00:00
|
|
|
ucol_getStrength(coll),
|
2001-02-22 16:32:40 +00:00
|
|
|
status);
|
2001-03-03 03:35:17 +00:00
|
|
|
if (U_SUCCESS(*status))
|
|
|
|
{
|
|
|
|
*status = U_SAFECLONE_ALLOCATED_ERROR;
|
|
|
|
}
|
2001-02-22 16:32:40 +00:00
|
|
|
} else {
|
2001-03-03 03:35:17 +00:00
|
|
|
localCollator = (UCollator *)stackBuffer;
|
|
|
|
memcpy(localCollator, coll, sizeof(UCollator));
|
|
|
|
localCollator->freeOnClose = FALSE;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
return localCollator;
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
U_CAPI int32_t
|
2001-02-22 16:32:40 +00:00
|
|
|
ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen) {
|
2001-02-28 19:01:23 +00:00
|
|
|
int32_t len = 0;
|
|
|
|
int32_t UCAlen = 0;
|
2001-03-22 21:16:20 +00:00
|
|
|
const UChar* ucaRules = 0;
|
2001-02-28 19:01:23 +00:00
|
|
|
const UChar *rules = ucol_getRules(coll, &len);
|
|
|
|
if(delta == UCOL_FULL_RULES) {
|
2001-03-01 20:12:12 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-02-28 19:01:23 +00:00
|
|
|
/* take the UCA rules and append real rules at the end */
|
2001-03-03 09:27:42 +00:00
|
|
|
/* UCA rules will be probably coming from the root RB */
|
|
|
|
ucaRules = ures_getStringByKey(coll->rb,"%%UCARULES",&UCAlen,&status);
|
2001-02-28 19:01:23 +00:00
|
|
|
}
|
2001-03-10 03:03:45 +00:00
|
|
|
if(buffer){
|
|
|
|
*buffer=0;
|
|
|
|
if(bufferLen >= len + UCAlen) {
|
2001-05-31 06:06:30 +00:00
|
|
|
if(UCAlen >0) {
|
|
|
|
u_memcpy(buffer, ucaRules, UCAlen);
|
|
|
|
}
|
|
|
|
u_memcpy(buffer+UCAlen, rules, len);
|
2001-03-10 03:03:45 +00:00
|
|
|
} else {
|
2001-05-31 06:06:30 +00:00
|
|
|
if(bufferLen >= UCAlen) {
|
|
|
|
u_memcpy(buffer, ucaRules, UCAlen);
|
|
|
|
u_memcpy(buffer+UCAlen, rules, bufferLen-UCAlen);
|
|
|
|
} else {
|
|
|
|
u_memcpy(buffer, ucaRules, bufferLen);
|
|
|
|
}
|
|
|
|
|
2001-03-10 03:03:45 +00:00
|
|
|
}
|
2001-02-28 19:01:23 +00:00
|
|
|
}
|
|
|
|
return len+UCAlen;
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar*
|
2001-04-23 01:53:49 +00:00
|
|
|
ucol_getRules( const UCollator *coll,
|
2001-01-16 00:28:40 +00:00
|
|
|
int32_t *length)
|
|
|
|
{
|
|
|
|
if(coll->rules != NULL) {
|
|
|
|
*length = u_strlen(coll->rules);
|
|
|
|
return coll->rules;
|
|
|
|
} else {
|
2001-03-03 09:27:42 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
if(coll->rb != NULL) {
|
|
|
|
UResourceBundle *collElem = ures_getByKey(coll->rb, "CollationElements", NULL, &status);
|
|
|
|
if(U_SUCCESS(status)) {
|
|
|
|
/*Semantic const */
|
|
|
|
((UCollator *)coll)->rules = ures_getStringByKey(collElem, "Sequence", length, &status);
|
|
|
|
((UCollator *)coll)->freeRulesOnClose = FALSE;
|
|
|
|
ures_close(collElem);
|
|
|
|
return coll->rules;
|
|
|
|
}
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
*length = 0;
|
|
|
|
return &coll->zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2001-03-17 23:36:26 +00:00
|
|
|
return uprv_fillOutputString(dst, result, resultLength, status);
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const char*
|
|
|
|
ucol_getAvailable(int32_t index)
|
|
|
|
{
|
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
|
|
|
ucol_countAvailable()
|
|
|
|
{
|
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
U_CAPI void
|
|
|
|
ucol_getVersion(const UCollator* coll,
|
|
|
|
UVersionInfo versionInfo)
|
2001-01-16 00:28:40 +00:00
|
|
|
{
|
2001-02-10 02:42:54 +00:00
|
|
|
/* RunTime version */
|
|
|
|
uint8_t rtVersion = UCOL_RUNTIME_VERSION;
|
2001-02-26 23:52:44 +00:00
|
|
|
/* Builder version*/
|
|
|
|
uint8_t bdVersion = coll->dataInfo.dataVersion[0];
|
|
|
|
|
2001-02-10 02:42:54 +00:00
|
|
|
/* Charset Version. Need to get the version from cnv files
|
2001-04-23 01:53:49 +00:00
|
|
|
* makeconv should populate cnv files with version and
|
2001-02-10 02:42:54 +00:00
|
|
|
* an api has to be provided in ucnv.h to obtain this version
|
|
|
|
*/
|
|
|
|
uint8_t csVersion = 0;
|
|
|
|
|
|
|
|
/* combine the version info */
|
2001-02-28 19:30:41 +00:00
|
|
|
uint16_t cmbVersion = (uint16_t)((rtVersion<<11) | (bdVersion<<6) | (csVersion));
|
2001-02-10 02:42:54 +00:00
|
|
|
|
2001-02-26 23:52:44 +00:00
|
|
|
/* Tailoring rules */
|
2001-02-28 19:30:41 +00:00
|
|
|
versionInfo[0] = (uint8_t)(cmbVersion>>8);
|
2001-02-10 02:42:54 +00:00
|
|
|
versionInfo[1] = (uint8_t)cmbVersion;
|
2001-02-26 23:52:44 +00:00
|
|
|
versionInfo[2] = coll->dataInfo.dataVersion[1];
|
|
|
|
versionInfo[3] = UCA->dataInfo.dataVersion[1];
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-02-26 23:52:44 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
|
2001-03-22 18:45:31 +00:00
|
|
|
/* This internal API checks whether a character is tailored or not */
|
|
|
|
U_CAPI UBool isTailored(const UCollator *coll, const UChar u, UErrorCode *status) {
|
|
|
|
uint32_t CE = UCOL_NOT_FOUND;
|
|
|
|
const UChar *ContractionStart = NULL;
|
|
|
|
if(U_SUCCESS(*status) && coll != NULL) {
|
|
|
|
if(coll == UCA) {
|
|
|
|
return FALSE;
|
|
|
|
} else if(u < 0x100) { /* latin-1 */
|
|
|
|
CE = coll->latinOneMapping[u];
|
|
|
|
if(CE == UCA->latinOneMapping[u]) {
|
|
|
|
return FALSE;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-22 18:45:31 +00:00
|
|
|
} else { /* regular */
|
|
|
|
CE = ucmp32_get(coll->mapping, u);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isContraction(CE)) {
|
|
|
|
ContractionStart = (UChar *)coll->image+getContractOffset(CE);
|
|
|
|
CE = *(coll->contractionCEs + (ContractionStart- coll->contractionIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CE == UCOL_NOT_FOUND) {
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-21 22:54:51 +00:00
|
|
|
/* String compare in code point order - u_strcmp() compares in code unit order. */
|
2001-06-06 23:26:50 +00:00
|
|
|
U_CFUNC int32_t
|
2001-05-21 22:54:51 +00:00
|
|
|
u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n) {
|
|
|
|
UChar c1, c2;
|
|
|
|
int32_t diff;
|
|
|
|
|
|
|
|
/* rotate each code unit's value so that surrogates get the highest values */
|
|
|
|
if(n > 0) {
|
|
|
|
for(;;) {
|
|
|
|
c1=*s1;
|
|
|
|
c1+=utf16Fixup[c1>>11]; /* additional "fix-up" line */
|
|
|
|
c2=*s2;
|
|
|
|
c2+=utf16Fixup[c2>>11]; /* additional "fix-up" line */
|
2001-06-06 23:26:50 +00:00
|
|
|
|
2001-05-21 22:54:51 +00:00
|
|
|
/* now c1 and c2 are in UTF-32-compatible order */
|
|
|
|
diff=(int32_t)c1-(int32_t)c2;
|
|
|
|
if(diff!=0 || --n == 0) {
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
++s1;
|
|
|
|
++s2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2001-04-19 17:08:07 +00:00
|
|
|
|
2001-03-03 03:35:17 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Following are the string compare functions */
|
|
|
|
/* */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
|
|
|
|
/* ucol_checkIdent internal function. Does byte level string compare. */
|
|
|
|
/* Used by strcoll if strength == identical and strings */
|
|
|
|
/* are otherwise equal. Moved out-of-line because this */
|
|
|
|
/* is a rare case. */
|
|
|
|
/* */
|
|
|
|
/* Comparison must be done on NFD normalized strings. */
|
|
|
|
/* FCD is not good enough. */
|
|
|
|
/* */
|
|
|
|
/* TODO: make an incremental NFD Comparison function, which could */
|
|
|
|
/* be of general use */
|
|
|
|
|
|
|
|
UCollationResult ucol_checkIdent(collIterate *sColl, collIterate *tColl, UBool normalize)
|
|
|
|
{
|
2001-04-19 00:52:55 +00:00
|
|
|
int32_t comparison;
|
2001-05-28 20:57:59 +00:00
|
|
|
int32_t sLen = (sColl->flags & UCOL_ITER_HASLEN) ? sColl->endp - sColl->string : -1;
|
2001-04-06 23:37:48 +00:00
|
|
|
UChar *sBuf = sColl->string;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-05-28 20:57:59 +00:00
|
|
|
int32_t tLen = (tColl->flags & UCOL_ITER_HASLEN) ? tColl->endp - tColl->string : -1;
|
2001-04-06 23:37:48 +00:00
|
|
|
UChar *tBuf = tColl->string;
|
2001-05-02 23:36:22 +00:00
|
|
|
// uint32_t compLen = 0;
|
2001-04-06 23:37:48 +00:00
|
|
|
uint32_t normLength;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UCollationResult result;
|
|
|
|
UBool sAlloc = FALSE;
|
|
|
|
UBool tAlloc = FALSE;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
if (normalize) {
|
|
|
|
if (unorm_quickCheck(sColl->string, sLen, UNORM_NFD, &status) != UNORM_YES) {
|
|
|
|
sBuf = sColl->writableBuffer;
|
|
|
|
normLength = unorm_normalize(sColl->string, sLen, UNORM_NFD, 0,
|
|
|
|
sBuf, UCOL_WRITABLE_BUFFER_SIZE, &status);
|
|
|
|
if (U_FAILURE(status)) { /*this would be buffer overflow */
|
|
|
|
sBuf = (UChar *)uprv_malloc((normLength+1)*sizeof(UChar));
|
|
|
|
sAlloc = TRUE;
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
normLength = unorm_normalize(sColl->string, sLen, UNORM_NFD, 0, sBuf, normLength+1, &status);
|
|
|
|
}
|
|
|
|
sLen = normLength;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
if (unorm_quickCheck(tColl->string, tLen, UNORM_NFD, &status) != UNORM_YES) {
|
|
|
|
tBuf = tColl->writableBuffer;
|
|
|
|
normLength = unorm_normalize(tColl->string, tLen, UNORM_NFD, 0,
|
|
|
|
tBuf, UCOL_WRITABLE_BUFFER_SIZE, &status);
|
|
|
|
if (U_FAILURE(status)) { /*this would be buffer overflow */
|
|
|
|
tBuf = (UChar *)uprv_malloc((normLength+1)*sizeof(UChar));
|
|
|
|
tAlloc = TRUE;
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
normLength = unorm_normalize(tColl->string, tLen, UNORM_NFD, 0, tBuf, normLength+1, &status);
|
|
|
|
}
|
|
|
|
tLen = normLength;
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
if (sLen == -1 && tLen == -1) {
|
2001-05-21 22:30:49 +00:00
|
|
|
comparison = u_strcmpCodePointOrder(sBuf, tBuf);
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
else
|
|
|
|
{
|
2001-04-12 19:59:28 +00:00
|
|
|
if (sLen == -1) {
|
2001-04-06 23:37:48 +00:00
|
|
|
sLen = u_strlen(sBuf);
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
|
|
|
if (tLen == -1) {
|
2001-04-06 23:37:48 +00:00
|
|
|
tLen = u_strlen(tBuf);
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
comparison = u_strncmpCodePointOrder(sBuf, tBuf, uprv_min(sLen, tLen));
|
2001-04-06 23:37:48 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
result = UCOL_LESS;
|
|
|
|
if (comparison > 0) {
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
}
|
|
|
|
else if (comparison == 0) {
|
|
|
|
if(sLen > tLen) {
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
} else if (sLen == tLen){
|
|
|
|
result = UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-12 19:59:28 +00:00
|
|
|
if (sAlloc) {
|
2001-05-17 23:09:35 +00:00
|
|
|
uprv_free(sBuf);
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
|
|
|
if (tAlloc) {
|
2001-05-17 23:09:35 +00:00
|
|
|
uprv_free(tBuf);
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
/* CEBuf - A struct and some inline functions to handle the saving */
|
|
|
|
/* of CEs in a buffer within ucol_strcoll */
|
|
|
|
|
|
|
|
#define UCOL_CEBUF_SIZE 512
|
|
|
|
typedef struct ucol_CEBuf {
|
|
|
|
uint32_t *buf;
|
|
|
|
uint32_t *endp;
|
|
|
|
uint32_t *pos;
|
|
|
|
uint32_t localArray[UCOL_CEBUF_SIZE];
|
|
|
|
} ucol_CEBuf;
|
2001-04-06 23:37:48 +00:00
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
|
|
|
|
inline void UCOL_INIT_CEBUF(ucol_CEBuf *b) {
|
|
|
|
(b)->buf = (b)->pos = (b)->localArray;
|
|
|
|
(b)->endp = (b)->buf + UCOL_CEBUF_SIZE;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ucol_CEBuf_Expand(ucol_CEBuf *b, collIterate *ci) {
|
2001-04-06 23:37:48 +00:00
|
|
|
uint32_t oldSize;
|
|
|
|
uint32_t newSize;
|
|
|
|
uint32_t *newBuf;
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
ci->flags |= UCOL_ITER_ALLOCATED;
|
2001-04-06 23:37:48 +00:00
|
|
|
oldSize = b->pos - b->buf;
|
|
|
|
newSize = oldSize * 2;
|
|
|
|
newBuf = (uint32_t *)uprv_malloc(newSize * sizeof(uint32_t));
|
|
|
|
uprv_memcpy(newBuf, b->buf, oldSize * sizeof(uint32_t));
|
2001-04-12 19:59:28 +00:00
|
|
|
if (b->buf != b->localArray) {
|
2001-05-17 23:09:35 +00:00
|
|
|
uprv_free(b->buf);
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-06 23:37:48 +00:00
|
|
|
b->buf = newBuf;
|
|
|
|
b->endp = b->buf + newSize;
|
|
|
|
b->pos = b->buf + oldSize;
|
|
|
|
}
|
|
|
|
|
2001-05-17 23:09:35 +00:00
|
|
|
inline void UCOL_CEBUF_PUT(ucol_CEBuf *b, uint32_t ce, collIterate *ci) {
|
|
|
|
if (b->pos == b->endp) {
|
|
|
|
ucol_CEBuf_Expand(b, ci);
|
2001-04-18 19:31:05 +00:00
|
|
|
}
|
|
|
|
*(b)->pos++ = ce;
|
|
|
|
};
|
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* */
|
|
|
|
/* ucol_strcoll Main public API string comparison function */
|
|
|
|
/* */
|
2001-01-16 00:28:40 +00:00
|
|
|
U_CAPI UCollationResult
|
2001-04-23 01:53:49 +00:00
|
|
|
ucol_strcoll( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
2001-01-05 00:47:25 +00:00
|
|
|
{
|
2001-05-10 22:12:53 +00:00
|
|
|
U_ALIGN_CODE(16);
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-03-15 02:16:02 +00:00
|
|
|
/* Scan the strings. Find: */
|
2001-03-03 03:35:17 +00:00
|
|
|
/* The length of any leading portion that is equal */
|
2001-04-06 23:37:48 +00:00
|
|
|
/* Whether they are exactly equal. (in which case we just return) */
|
2001-03-03 03:35:17 +00:00
|
|
|
const UChar *pSrc = source;
|
|
|
|
const UChar *pTarg = target;
|
2001-03-20 02:26:23 +00:00
|
|
|
int32_t equalLength;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
if (sourceLength == -1 && targetLength == -1) {
|
|
|
|
// Both strings are null terminated.
|
|
|
|
// Check for them being the same string, and scan through
|
|
|
|
// any leading equal portion.
|
|
|
|
if (source==target) {
|
|
|
|
return UCOL_EQUAL;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if ( *pSrc != *pTarg || *pSrc == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pSrc++;
|
|
|
|
pTarg++;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
if (*pSrc == 0 && *pTarg == 0) {
|
|
|
|
return UCOL_EQUAL;
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
equalLength = pSrc - source;
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// One or both strings has an explicit length.
|
|
|
|
/* check if source and target are same strings */
|
2001-03-20 02:26:23 +00:00
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
if (source==target && sourceLength==targetLength) {
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
const UChar *pSrcEnd = source + sourceLength;
|
|
|
|
const UChar *pTargEnd = target + targetLength;
|
|
|
|
|
|
|
|
|
|
|
|
// Scan while the strings are bitwise ==, or until one is exhausted.
|
2001-04-23 01:53:49 +00:00
|
|
|
for (;;) {
|
|
|
|
if (pSrc == pSrcEnd || pTarg == pTargEnd) {
|
|
|
|
break;
|
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
if ((*pSrc == 0 && sourceLength == -1) || (*pTarg == 0 && targetLength == -1)) {
|
2001-04-23 01:53:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*pSrc != *pTarg) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pSrc++;
|
|
|
|
pTarg++;
|
|
|
|
}
|
|
|
|
equalLength = pSrc - source;
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
// If we made it all the way through both strings, we are done. They are ==
|
|
|
|
if ((pSrc ==pSrcEnd || (pSrcEnd <pSrc && *pSrc==0)) && /* At end of src string, however it was specified. */
|
|
|
|
(pTarg==pTargEnd || (pTargEnd<pTarg && *pTarg==0))) { /* and also at end of dest string */
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
if (equalLength > 0) {
|
2001-03-03 03:35:17 +00:00
|
|
|
/* There is an identical portion at the beginning of the two strings. */
|
|
|
|
/* If the identical portion ends within a contraction or a comibining */
|
|
|
|
/* character sequence, back up to the start of that sequence. */
|
|
|
|
pSrc = source + equalLength; /* point to the first differing chars */
|
|
|
|
pTarg = target + equalLength;
|
2001-04-23 01:53:49 +00:00
|
|
|
if (pSrc != source+sourceLength && ucol_unsafeCP(*pSrc, coll) ||
|
2001-03-03 03:35:17 +00:00
|
|
|
pTarg != target+targetLength && ucol_unsafeCP(*pTarg, coll))
|
|
|
|
{
|
|
|
|
// We are stopped in the middle of a contraction.
|
|
|
|
// Scan backwards through the == part of the string looking for the start of the contraction.
|
|
|
|
// It doesn't matter which string we scan, since they are the same in this region.
|
2001-04-23 01:53:49 +00:00
|
|
|
do
|
2001-03-03 03:35:17 +00:00
|
|
|
{
|
|
|
|
equalLength--;
|
|
|
|
pSrc--;
|
|
|
|
}
|
|
|
|
while (equalLength>0 && ucol_unsafeCP(*pSrc, coll));
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-03-03 03:35:17 +00:00
|
|
|
source += equalLength;
|
|
|
|
target += equalLength;
|
2001-04-12 19:59:28 +00:00
|
|
|
if (sourceLength > 0) {
|
|
|
|
sourceLength -= equalLength;
|
|
|
|
}
|
|
|
|
if (targetLength > 0) {
|
|
|
|
targetLength -= equalLength;
|
|
|
|
}
|
2001-03-03 03:35:17 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
|
2001-05-22 22:26:58 +00:00
|
|
|
// setting up the collator parameters
|
2001-03-14 02:45:39 +00:00
|
|
|
UColAttributeValue strength = coll->strength;
|
|
|
|
UBool initialCheckSecTer = (strength >= UCOL_SECONDARY);
|
|
|
|
|
|
|
|
UBool checkSecTer = initialCheckSecTer;
|
|
|
|
UBool checkTertiary = (strength >= UCOL_TERTIARY);
|
|
|
|
UBool checkQuad = (strength >= UCOL_QUATERNARY);
|
|
|
|
UBool checkIdent = (strength == UCOL_IDENTICAL);
|
|
|
|
UBool checkCase = (coll->caseLevel == UCOL_ON);
|
|
|
|
UBool isFrenchSec = (coll->frenchCollation == UCOL_ON) && checkSecTer;
|
2001-03-15 02:49:35 +00:00
|
|
|
UBool shifted = (coll->alternateHandling == UCOL_SHIFTED);
|
|
|
|
UBool qShifted = shifted && checkQuad;
|
2001-03-14 02:45:39 +00:00
|
|
|
|
2001-05-22 22:26:58 +00:00
|
|
|
uint8_t caseSwitch = coll->caseSwitch;
|
|
|
|
uint8_t tertiaryMask = coll->tertiaryMask;
|
|
|
|
|
|
|
|
// This is the lowest primary value that will not be ignored if shifted
|
|
|
|
uint32_t LVT = (shifted)?((coll->variableMax1)<<24 | (coll->variableMax2)<<16):0;
|
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
UCollationResult result = UCOL_EQUAL;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-05-22 22:26:58 +00:00
|
|
|
// Preparing the context objects for iterating over strings
|
2001-01-16 00:28:40 +00:00
|
|
|
collIterate sColl, tColl;
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(coll, source, sourceLength, &sColl);
|
|
|
|
IInit_collIterate(coll, target, targetLength, &tColl);
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-05-22 22:26:58 +00:00
|
|
|
// Preparing the CE buffers. They will be filled during the primary phase
|
2001-04-06 23:37:48 +00:00
|
|
|
ucol_CEBuf sCEs;
|
|
|
|
ucol_CEBuf tCEs;
|
|
|
|
UCOL_INIT_CEBUF(&sCEs);
|
|
|
|
UCOL_INIT_CEBUF(&tCEs);
|
|
|
|
|
2001-01-24 16:18:48 +00:00
|
|
|
uint32_t secS = 0, secT = 0;
|
2001-01-24 00:35:19 +00:00
|
|
|
uint32_t sOrder=0, tOrder=0;
|
2001-05-22 22:26:58 +00:00
|
|
|
|
|
|
|
// Non shifted primary processing is quite simple
|
2001-01-25 06:51:18 +00:00
|
|
|
if(!shifted) {
|
|
|
|
for(;;) {
|
2001-05-22 22:26:58 +00:00
|
|
|
|
|
|
|
// We fetch CEs until we hit a non ignorable primary or end.
|
|
|
|
do {
|
|
|
|
// We get the next CE
|
2001-04-18 19:31:05 +00:00
|
|
|
sOrder = ucol_IGetNextCE(coll, &sColl, &status);
|
2001-05-22 22:26:58 +00:00
|
|
|
// Stuff it in the buffer
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-05-22 22:26:58 +00:00
|
|
|
// And keep just the primary part.
|
2001-05-21 22:30:49 +00:00
|
|
|
sOrder &= UCOL_PRIMARYMASK;
|
2001-05-22 22:26:58 +00:00
|
|
|
} while(sOrder == 0);
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-05-22 22:26:58 +00:00
|
|
|
// see the comments on the above block
|
|
|
|
do {
|
2001-04-18 19:31:05 +00:00
|
|
|
tOrder = ucol_IGetNextCE(coll, &tColl, &status);
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-05-21 22:30:49 +00:00
|
|
|
tOrder &= UCOL_PRIMARYMASK;
|
2001-05-22 22:26:58 +00:00
|
|
|
} while(tOrder == 0);
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-05-22 22:26:58 +00:00
|
|
|
// if both primaries are the same
|
2001-01-25 06:51:18 +00:00
|
|
|
if(sOrder == tOrder) {
|
2001-05-22 22:26:58 +00:00
|
|
|
// and there are no more CEs, we advance to the next level
|
2001-05-21 22:30:49 +00:00
|
|
|
if(sOrder == UCOL_NO_MORE_CES_PRIMARY) {
|
2001-01-25 06:51:18 +00:00
|
|
|
break;
|
2001-06-06 23:26:50 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
} else {
|
2001-05-22 22:26:58 +00:00
|
|
|
// if two primaries are different, we are done
|
2001-04-06 23:37:48 +00:00
|
|
|
result = (sOrder < tOrder) ? UCOL_LESS: UCOL_GREATER;
|
|
|
|
goto commonReturn;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-05-22 22:26:58 +00:00
|
|
|
} // no primary difference... do the rest from the buffers
|
|
|
|
} else { // shifted - do a slightly more complicated processing :)
|
2001-01-25 06:51:18 +00:00
|
|
|
for(;;) {
|
|
|
|
UBool sInShifted = FALSE;
|
|
|
|
UBool tInShifted = FALSE;
|
2001-05-22 22:26:58 +00:00
|
|
|
// This version of code can be refactored. However, it seems easier to understand this way.
|
2001-06-06 23:26:50 +00:00
|
|
|
// Source loop. Sam as the target loop.
|
2001-01-26 00:12:23 +00:00
|
|
|
for(;;) {
|
2001-04-18 19:31:05 +00:00
|
|
|
sOrder = ucol_IGetNextCE(coll, &sColl, &status);
|
2001-03-02 00:19:43 +00:00
|
|
|
if(sOrder == UCOL_NO_MORE_CES) {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-01-26 00:12:23 +00:00
|
|
|
break;
|
2001-05-21 22:30:49 +00:00
|
|
|
} else if(sOrder == 0) {
|
2001-01-26 00:12:23 +00:00
|
|
|
continue;
|
|
|
|
} else if(isContinuation(sOrder)) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((sOrder & UCOL_PRIMARYMASK) > 0) { /* There is primary value */
|
2001-01-26 00:12:23 +00:00
|
|
|
if(sInShifted) {
|
2001-06-02 01:01:18 +00:00
|
|
|
sOrder = (sOrder & UCOL_PRIMARYMASK) | 0xC0; /* preserve interesting continuation */
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-01-26 00:12:23 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-01-26 00:12:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else { /* Just lower level values */
|
|
|
|
if(sInShifted) {
|
|
|
|
continue;
|
|
|
|
} else {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-01-26 00:12:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* regular */
|
|
|
|
if(sOrder > LVT) {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-01-26 00:12:23 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((sOrder & UCOL_PRIMARYMASK) > 0) {
|
2001-01-26 00:12:23 +00:00
|
|
|
sInShifted = TRUE;
|
2001-05-21 22:30:49 +00:00
|
|
|
sOrder &= UCOL_PRIMARYMASK;
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-01-26 00:12:23 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&sCEs, sOrder, &sColl);
|
2001-05-15 17:38:18 +00:00
|
|
|
sInShifted = FALSE;
|
2001-01-26 00:12:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
sOrder &= UCOL_PRIMARYMASK;
|
2001-01-26 00:12:23 +00:00
|
|
|
sInShifted = FALSE;
|
2001-01-22 23:48:48 +00:00
|
|
|
|
2001-01-25 06:51:18 +00:00
|
|
|
for(;;) {
|
2001-04-18 19:31:05 +00:00
|
|
|
tOrder = ucol_IGetNextCE(coll, &tColl, &status);
|
2001-03-02 00:19:43 +00:00
|
|
|
if(tOrder == UCOL_NO_MORE_CES) {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-01-25 06:51:18 +00:00
|
|
|
break;
|
2001-05-21 22:30:49 +00:00
|
|
|
} else if(tOrder == 0) {
|
2001-01-25 06:51:18 +00:00
|
|
|
continue;
|
|
|
|
} else if(isContinuation(tOrder)) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((tOrder & UCOL_PRIMARYMASK) > 0) { /* There is primary value */
|
2001-01-25 06:51:18 +00:00
|
|
|
if(tInShifted) {
|
2001-06-02 01:01:18 +00:00
|
|
|
tOrder = (tOrder & UCOL_PRIMARYMASK) | 0xC0; /* preserve interesting continuation */
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-01-25 06:51:18 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-01-24 00:35:19 +00:00
|
|
|
break;
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
} else { /* Just lower level values */
|
|
|
|
if(tInShifted) {
|
|
|
|
continue;
|
2001-01-23 06:58:22 +00:00
|
|
|
} else {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-01-24 00:35:19 +00:00
|
|
|
continue;
|
2001-01-23 06:58:22 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
} else { /* regular */
|
|
|
|
if(tOrder > LVT) {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-01-25 06:51:18 +00:00
|
|
|
break;
|
2001-01-24 00:35:19 +00:00
|
|
|
} else {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((tOrder & UCOL_PRIMARYMASK) > 0) {
|
2001-01-25 06:51:18 +00:00
|
|
|
tInShifted = TRUE;
|
2001-05-21 22:30:49 +00:00
|
|
|
tOrder &= UCOL_PRIMARYMASK;
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-01-25 06:51:18 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2001-05-17 23:09:35 +00:00
|
|
|
UCOL_CEBUF_PUT(&tCEs, tOrder, &tColl);
|
2001-05-15 17:38:18 +00:00
|
|
|
tInShifted = FALSE;
|
2001-01-25 06:51:18 +00:00
|
|
|
continue;
|
2001-01-24 16:18:48 +00:00
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
tOrder &= UCOL_PRIMARYMASK;
|
2001-01-26 00:12:23 +00:00
|
|
|
tInShifted = FALSE;
|
2001-01-16 00:28:40 +00:00
|
|
|
|
2001-01-25 06:51:18 +00:00
|
|
|
if(sOrder == tOrder) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(sOrder == UCOL_NO_MORE_CES_PRIMARY) {
|
2001-01-25 06:51:18 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
sOrder = 0; tOrder = 0;
|
|
|
|
continue;
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
} else {
|
2001-04-06 23:37:48 +00:00
|
|
|
result = (sOrder < tOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
goto commonReturn;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
} /* no primary difference... do the rest from the buffers */
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
|
2001-01-25 06:51:18 +00:00
|
|
|
/* now, we're gonna reexamine collected CEs */
|
2001-04-06 23:37:48 +00:00
|
|
|
uint32_t *sCE;
|
|
|
|
uint32_t *tCE;
|
2001-01-25 06:51:18 +00:00
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
/* This is the secondary level of comparison */
|
2001-01-25 06:51:18 +00:00
|
|
|
if(checkSecTer) {
|
|
|
|
if(!isFrenchSec) { /* normal */
|
2001-04-06 23:37:48 +00:00
|
|
|
sCE = sCEs.buf;
|
|
|
|
tCE = tCEs.buf;
|
2001-01-25 06:51:18 +00:00
|
|
|
for(;;) {
|
2001-03-02 00:19:43 +00:00
|
|
|
while (secS == 0) {
|
2001-05-21 22:30:49 +00:00
|
|
|
secS = *(sCE++) & UCOL_SECONDARYMASK;
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
while(secT == 0) {
|
2001-05-21 22:30:49 +00:00
|
|
|
secT = *(tCE++) & UCOL_SECONDARYMASK;
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(secS == secT) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secS == UCOL_NO_MORE_CES_SECONDARY) {
|
2001-01-25 06:51:18 +00:00
|
|
|
break;
|
2001-01-24 16:18:48 +00:00
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0; secT = 0;
|
2001-01-25 06:51:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2001-04-06 23:37:48 +00:00
|
|
|
result = (secS < secT) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
goto commonReturn;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
} else { /* do the French */
|
2001-01-26 00:12:23 +00:00
|
|
|
uint32_t *sCESave = NULL;
|
|
|
|
uint32_t *tCESave = NULL;
|
2001-04-06 23:37:48 +00:00
|
|
|
sCE = sCEs.pos-2; /* this could also be sCEs-- if needs to be optimized */
|
|
|
|
tCE = tCEs.pos-2;
|
2001-01-26 00:12:23 +00:00
|
|
|
for(;;) {
|
2001-04-06 23:37:48 +00:00
|
|
|
while (secS == 0 && sCE >= sCEs.buf) {
|
2001-01-26 00:12:23 +00:00
|
|
|
if(sCESave == 0) {
|
2001-05-21 22:30:49 +00:00
|
|
|
secS = *(sCE--);
|
2001-01-26 00:12:23 +00:00
|
|
|
if(isContinuation(secS)) {
|
2001-05-21 22:30:49 +00:00
|
|
|
while(isContinuation(secS = *(sCE--)));
|
2001-01-26 00:12:23 +00:00
|
|
|
/* after this, secS has the start of continuation, and sCEs points before that */
|
2001-04-06 23:37:48 +00:00
|
|
|
sCESave = sCE; /* we save it, so that we know where to come back AND that we need to go forward */
|
|
|
|
sCE+=2; /* need to point to the first continuation CP */
|
2001-01-26 00:12:23 +00:00
|
|
|
/* However, now you can just continue doing stuff */
|
|
|
|
}
|
|
|
|
} else {
|
2001-05-21 22:30:49 +00:00
|
|
|
secS = *(sCE++);
|
2001-01-26 00:12:23 +00:00
|
|
|
if(!isContinuation(secS)) { /* This means we have finished with this cont */
|
2001-04-06 23:37:48 +00:00
|
|
|
sCE = sCESave; /* reset the pointer to before continuation */
|
2001-01-26 00:12:23 +00:00
|
|
|
sCESave = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secS &= UCOL_SECONDARYMASK; /* remove the continuation bit */
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
while(secT == 0 && tCE >= tCEs.buf) {
|
2001-01-26 00:12:23 +00:00
|
|
|
if(tCESave == 0) {
|
2001-05-21 22:30:49 +00:00
|
|
|
secT = *(tCE--);
|
2001-01-26 00:12:23 +00:00
|
|
|
if(isContinuation(secT)) {
|
2001-05-21 22:30:49 +00:00
|
|
|
while(isContinuation(secT = *(tCE--)));
|
2001-01-26 00:12:23 +00:00
|
|
|
/* after this, secS has the start of continuation, and sCEs points before that */
|
2001-04-06 23:37:48 +00:00
|
|
|
tCESave = tCE; /* we save it, so that we know where to come back AND that we need to go forward */
|
|
|
|
tCE+=2; /* need to point to the first continuation CP */
|
2001-01-26 00:12:23 +00:00
|
|
|
/* However, now you can just continue doing stuff */
|
|
|
|
}
|
|
|
|
} else {
|
2001-05-21 22:30:49 +00:00
|
|
|
secT = *(tCE++);
|
2001-01-26 00:12:23 +00:00
|
|
|
if(!isContinuation(secT)) { /* This means we have finished with this cont */
|
2001-04-06 23:37:48 +00:00
|
|
|
tCE = tCESave; /* reset the pointer to before continuation */
|
2001-01-26 00:12:23 +00:00
|
|
|
tCESave = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secT &= UCOL_SECONDARYMASK; /* remove the continuation bit */
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(secS == secT) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secS == UCOL_NO_MORE_CES_SECONDARY || (sCE < sCEs.buf && tCE < tCEs.buf)) {
|
2001-01-26 00:12:23 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0; secT = 0;
|
2001-01-26 00:12:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2001-04-06 23:37:48 +00:00
|
|
|
result = (secS < secT) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
goto commonReturn;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-26 00:12:23 +00:00
|
|
|
/* doing the case bit */
|
2001-01-25 06:51:18 +00:00
|
|
|
if(checkCase) {
|
2001-04-06 23:37:48 +00:00
|
|
|
sCE = sCEs.buf;
|
|
|
|
tCE = tCEs.buf;
|
2001-01-25 06:51:18 +00:00
|
|
|
for(;;) {
|
2001-03-02 00:19:43 +00:00
|
|
|
while((secS & UCOL_REMOVE_CASE) == 0) {
|
2001-04-06 23:37:48 +00:00
|
|
|
if(!isContinuation(*sCE++)) {
|
|
|
|
secS =*(sCE-1) & UCOL_TERT_CASE_MASK;
|
2001-05-10 22:33:50 +00:00
|
|
|
secS ^= caseSwitch;
|
|
|
|
} else {
|
|
|
|
secS = 0;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
while((secT & UCOL_REMOVE_CASE) == 0) {
|
2001-04-06 23:37:48 +00:00
|
|
|
if(!isContinuation(*tCE++)) {
|
|
|
|
secT = *(tCE-1) & UCOL_TERT_CASE_MASK;
|
2001-05-10 22:33:50 +00:00
|
|
|
secT ^= caseSwitch;
|
|
|
|
} else {
|
|
|
|
secT = 0;
|
2001-03-16 19:06:07 +00:00
|
|
|
}
|
2001-01-26 00:12:23 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
if((secS & UCOL_CASE_BIT_MASK) < (secT & UCOL_CASE_BIT_MASK)) {
|
2001-04-06 23:37:48 +00:00
|
|
|
result = UCOL_LESS;
|
|
|
|
goto commonReturn;
|
2001-03-02 00:19:43 +00:00
|
|
|
} else if((secS & UCOL_CASE_BIT_MASK) > (secT & UCOL_CASE_BIT_MASK)) {
|
2001-04-06 23:37:48 +00:00
|
|
|
result = UCOL_GREATER;
|
|
|
|
goto commonReturn;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-02 00:19:43 +00:00
|
|
|
|
2001-05-21 22:30:49 +00:00
|
|
|
if((secS & UCOL_REMOVE_CASE) == UCOL_NO_MORE_CES_TERTIARY || (secT & UCOL_REMOVE_CASE) == UCOL_NO_MORE_CES_TERTIARY ) {
|
2001-03-02 00:19:43 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
secS = 0;
|
|
|
|
secT = 0;
|
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
/* Tertiary level */
|
2001-01-25 06:51:18 +00:00
|
|
|
if(checkTertiary) {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0;
|
2001-01-25 06:51:18 +00:00
|
|
|
secT = 0;
|
2001-04-06 23:37:48 +00:00
|
|
|
sCE = sCEs.buf;
|
|
|
|
tCE = tCEs.buf;
|
2001-01-25 06:51:18 +00:00
|
|
|
for(;;) {
|
2001-03-02 00:19:43 +00:00
|
|
|
while((secS & UCOL_REMOVE_CASE) == 0) {
|
2001-04-06 23:37:48 +00:00
|
|
|
secS = *(sCE++) & tertiaryMask;
|
2001-05-10 22:33:50 +00:00
|
|
|
if(!isContinuation(secS)) {
|
|
|
|
secS ^= caseSwitch;
|
|
|
|
} else {
|
|
|
|
secS &= UCOL_REMOVE_CASE;
|
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
|
2001-03-02 00:19:43 +00:00
|
|
|
while((secT & UCOL_REMOVE_CASE) == 0) {
|
2001-05-10 22:33:50 +00:00
|
|
|
secT = *(tCE++) & tertiaryMask;
|
|
|
|
if(!isContinuation(secT)) {
|
|
|
|
secT ^= caseSwitch;
|
|
|
|
} else {
|
|
|
|
secT &= UCOL_REMOVE_CASE;
|
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(secS == secT) {
|
2001-03-02 00:19:43 +00:00
|
|
|
if((secS & UCOL_REMOVE_CASE) == 1) {
|
2001-01-25 06:51:18 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0; secT = 0;
|
2001-01-25 06:51:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2001-04-06 23:37:48 +00:00
|
|
|
result = (secS < secT) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
goto commonReturn;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-25 06:51:18 +00:00
|
|
|
|
2001-03-15 02:49:35 +00:00
|
|
|
if(qShifted) {
|
2001-01-25 06:51:18 +00:00
|
|
|
UBool sInShifted = TRUE;
|
|
|
|
UBool tInShifted = TRUE;
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0;
|
2001-01-25 06:51:18 +00:00
|
|
|
secT = 0;
|
2001-04-06 23:37:48 +00:00
|
|
|
sCE = sCEs.buf;
|
|
|
|
tCE = tCEs.buf;
|
2001-01-25 06:51:18 +00:00
|
|
|
for(;;) {
|
2001-05-21 22:30:49 +00:00
|
|
|
while(secS == 0 && secS != UCOL_NO_MORE_CES || (isContinuation(secS) && !sInShifted)) {
|
2001-04-06 23:37:48 +00:00
|
|
|
secS = *(sCE++);
|
2001-06-02 01:01:18 +00:00
|
|
|
if(isContinuation(secS)) {
|
|
|
|
if(!sInShifted) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if(secS > LVT || (secS & UCOL_PRIMARYMASK) == 0) { /* non continuation */
|
2001-05-21 22:30:49 +00:00
|
|
|
secS = UCOL_PRIMARYMASK;
|
2001-01-25 06:51:18 +00:00
|
|
|
sInShifted = FALSE;
|
|
|
|
} else {
|
|
|
|
sInShifted = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secS &= UCOL_PRIMARYMASK;
|
2000-11-29 00:16:15 +00:00
|
|
|
|
2001-01-25 06:51:18 +00:00
|
|
|
|
2001-05-21 22:30:49 +00:00
|
|
|
while(secT == 0 && secT != UCOL_NO_MORE_CES || (isContinuation(secT) && !tInShifted)) {
|
2001-04-06 23:37:48 +00:00
|
|
|
secT = *(tCE++);
|
2001-06-02 01:01:18 +00:00
|
|
|
if(isContinuation(secT)) {
|
|
|
|
if(!tInShifted) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if(secT > LVT || (secT & UCOL_PRIMARYMASK) == 0) {
|
2001-05-21 22:30:49 +00:00
|
|
|
secT = UCOL_PRIMARYMASK;
|
2001-01-25 06:51:18 +00:00
|
|
|
tInShifted = FALSE;
|
|
|
|
} else {
|
|
|
|
tInShifted = TRUE;
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secT &= UCOL_PRIMARYMASK;
|
2001-01-25 06:51:18 +00:00
|
|
|
|
|
|
|
if(secS == secT) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secS == UCOL_NO_MORE_CES_PRIMARY) {
|
2001-01-25 06:51:18 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
secS = 0; secT = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2001-04-06 23:37:48 +00:00
|
|
|
result = (secS < secT) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
goto commonReturn;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-25 06:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* For IDENTICAL comparisons, we use a bitwise character comparison */
|
2001-04-06 23:37:48 +00:00
|
|
|
/* as a tiebreaker if all else is equal. */
|
|
|
|
/* Getting here should be quite rare - strings are not identical - */
|
|
|
|
/* that is checked first, but compared == through all other checks. */
|
2001-02-28 19:01:23 +00:00
|
|
|
if(checkIdent)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2001-04-06 23:37:48 +00:00
|
|
|
result = ucol_checkIdent(&sColl, &tColl, coll->normalizationMode == UCOL_ON);
|
|
|
|
}
|
2001-03-14 02:45:39 +00:00
|
|
|
|
2001-04-06 23:37:48 +00:00
|
|
|
commonReturn:
|
2001-04-18 19:31:05 +00:00
|
|
|
if ((sColl.flags | tColl.flags) & UCOL_ITER_ALLOCATED) {
|
2001-05-10 17:49:24 +00:00
|
|
|
freeHeapWritableBuffer(&sColl);
|
|
|
|
freeHeapWritableBuffer(&tColl);
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
if (sCEs.buf != sCEs.localArray ) {
|
|
|
|
uprv_free(sCEs.buf);
|
|
|
|
}
|
|
|
|
if (tCEs.buf != tCEs.localArray ) {
|
|
|
|
uprv_free(tCEs.buf);
|
2001-04-18 19:31:05 +00:00
|
|
|
}
|
2001-04-12 19:59:28 +00:00
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
|
2001-03-09 00:50:37 +00:00
|
|
|
void init_incrementalContext(const UCollator *coll, UCharForwardIterator *source, void *sourceContext, incrementalContext *s) {
|
2001-01-16 00:28:40 +00:00
|
|
|
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;
|
2001-03-09 00:50:37 +00:00
|
|
|
s->coll = coll;
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the incremental function */
|
2001-04-23 01:53:49 +00:00
|
|
|
U_CAPI UCollationResult ucol_strcollinc(const UCollator *coll,
|
2001-03-03 03:35:17 +00:00
|
|
|
UCharForwardIterator *source, void *sourceContext,
|
|
|
|
UCharForwardIterator *target, void *targetContext)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2001-01-16 00:28:40 +00:00
|
|
|
incrementalContext sColl, tColl;
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2001-03-09 00:50:37 +00:00
|
|
|
init_incrementalContext(coll, source, sourceContext, &sColl);
|
|
|
|
init_incrementalContext(coll, target, targetContext, &tColl);
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
UCollationResult result = UCOL_EQUAL;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
if(coll->normalizationMode != UCOL_OFF) { /* run away screaming!!!! */
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
UColAttributeValue strength = coll->strength;
|
|
|
|
UBool initialCheckSecTer = (strength >= UCOL_SECONDARY);
|
|
|
|
|
2000-11-30 23:20:14 +00:00
|
|
|
UBool checkSecTer = initialCheckSecTer;
|
2001-01-16 00:28:40 +00:00
|
|
|
UBool checkTertiary = (strength >= UCOL_TERTIARY);
|
|
|
|
UBool checkQuad = (strength >= UCOL_QUATERNARY);
|
2001-03-07 23:56:26 +00:00
|
|
|
UBool checkIdent = (strength == UCOL_IDENTICAL);
|
|
|
|
UBool checkCase = (coll->caseLevel == UCOL_ON);
|
2001-01-16 00:28:40 +00:00
|
|
|
UBool isFrenchSec = (coll->frenchCollation == UCOL_ON) && checkSecTer;
|
2001-03-15 02:49:35 +00:00
|
|
|
UBool shifted = (coll->alternateHandling == UCOL_SHIFTED);
|
|
|
|
UBool qShifted = shifted && checkQuad;
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
uint32_t sCEsArray[512], tCEsArray[512];
|
|
|
|
uint32_t *sCEs = sCEsArray, *tCEs = tCEsArray;
|
|
|
|
uint32_t *sCEend = sCEs+512, *tCEend = tCEs+512;
|
|
|
|
uint8_t caseSwitch = coll->caseSwitch;
|
|
|
|
uint8_t tertiaryMask = coll->tertiaryMask;
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-15 02:49:35 +00:00
|
|
|
uint32_t LVT = (shifted)?((coll->variableMax1)<<24 | (coll->variableMax2)<<16):0;
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
uint32_t secS = 0, secT = 0;
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
uint32_t sOrder=0, tOrder=0;
|
|
|
|
if(!shifted) {
|
|
|
|
for(;;) {
|
|
|
|
if(sCEs == sCEend || tCEs == tCEend) {
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
/* Get the next collation element in each of the strings, unless */
|
|
|
|
/* we've been requested to skip it. */
|
|
|
|
while(sOrder == 0) {
|
|
|
|
sOrder = ucol_getIncrementalCE(coll, &sColl, &status);
|
|
|
|
sOrder ^= caseSwitch;
|
|
|
|
*(sCEs++) = sOrder;
|
2001-05-21 22:30:49 +00:00
|
|
|
sOrder &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
while(tOrder == 0) {
|
|
|
|
tOrder = ucol_getIncrementalCE(coll, &tColl, &status);
|
|
|
|
tOrder ^= caseSwitch;
|
|
|
|
*(tCEs++) = tOrder;
|
2001-05-21 22:30:49 +00:00
|
|
|
tOrder &= UCOL_PRIMARYMASK;
|
2001-03-17 00:46:46 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
if((sOrder == (UCOL_NO_MORE_CES & UCOL_PRIMARYORDERMASK) && sColl.panic == TRUE) ||
|
2001-03-17 00:46:46 +00:00
|
|
|
(tOrder == (UCOL_NO_MORE_CES & UCOL_PRIMARYORDERMASK) && tColl.panic == TRUE)) {
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
if(sOrder == tOrder) {
|
2001-03-17 00:46:46 +00:00
|
|
|
if(sOrder == (UCOL_NO_MORE_CES & UCOL_PRIMARYORDERMASK)) {
|
2000-11-30 23:20:14 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
sOrder = 0; tOrder = 0;
|
|
|
|
continue;
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
} else if(sOrder < tOrder) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else {
|
|
|
|
return UCOL_GREATER;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
} /* no primary difference... do the rest from the buffers */
|
|
|
|
} else { /* shifted - do a slightly more complicated processing */
|
|
|
|
for(;;) {
|
|
|
|
UBool sInShifted = FALSE;
|
|
|
|
UBool tInShifted = FALSE;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
if(sCEs == sCEend || tCEs == tCEend) {
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
/* This is where abridged version for shifted should go */
|
|
|
|
for(;;) {
|
|
|
|
sOrder = ucol_getIncrementalCE(coll, &sColl, &status);
|
|
|
|
if(sOrder == UCOL_NO_MORE_CES) {
|
2001-03-17 00:46:46 +00:00
|
|
|
if(sColl.panic == TRUE) {
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
*(sCEs++) = sOrder;
|
|
|
|
break;
|
2001-05-21 22:30:49 +00:00
|
|
|
} else if(sOrder == 0) {
|
2001-03-07 23:56:26 +00:00
|
|
|
continue;
|
|
|
|
} else if(isContinuation(sOrder)) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((sOrder & UCOL_PRIMARYMASK) > 0) { /* There is primary value */
|
2001-03-07 23:56:26 +00:00
|
|
|
if(sInShifted) {
|
2001-05-21 22:30:49 +00:00
|
|
|
sOrder &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
*(sCEs++) = sOrder;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
sOrder ^= caseSwitch;
|
|
|
|
*(sCEs++) = sOrder;
|
2001-01-05 00:47:25 +00:00
|
|
|
break;
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
} else { /* Just lower level values */
|
|
|
|
if(sInShifted) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
sOrder ^= caseSwitch;
|
|
|
|
*(sCEs++) = sOrder;
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
} else { /* regular */
|
|
|
|
if(sOrder > LVT) {
|
|
|
|
*(sCEs++) = sOrder;
|
|
|
|
break;
|
|
|
|
} else {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((sOrder & UCOL_PRIMARYMASK) > 0) {
|
2001-03-07 23:56:26 +00:00
|
|
|
sInShifted = TRUE;
|
2001-05-21 22:30:49 +00:00
|
|
|
sOrder &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
*(sCEs++) = sOrder;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
sOrder ^= caseSwitch;
|
|
|
|
*(sCEs++) = sOrder;
|
2001-01-05 00:47:25 +00:00
|
|
|
continue;
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
sOrder &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
sInShifted = FALSE;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
for(;;) {
|
|
|
|
tOrder = ucol_getIncrementalCE(coll, &tColl, &status);
|
|
|
|
if(tOrder == UCOL_NO_MORE_CES) {
|
2001-03-17 00:46:46 +00:00
|
|
|
if(tColl.panic == TRUE) {
|
|
|
|
return alternateIncrementalProcessing(coll, &sColl, &tColl);
|
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
*(tCEs++) = tOrder;
|
|
|
|
break;
|
2001-05-21 22:30:49 +00:00
|
|
|
} else if(tOrder == 0) {
|
2001-03-07 23:56:26 +00:00
|
|
|
continue;
|
|
|
|
} else if(isContinuation(tOrder)) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((tOrder & UCOL_PRIMARYMASK) > 0) { /* There is primary value */
|
2001-03-07 23:56:26 +00:00
|
|
|
if(tInShifted) {
|
2001-05-21 22:30:49 +00:00
|
|
|
tOrder &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
*(tCEs++) = tOrder;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
tOrder ^= caseSwitch;
|
|
|
|
*(tCEs++) = tOrder;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else { /* Just lower level values */
|
|
|
|
if(tInShifted) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
tOrder ^= caseSwitch;
|
2001-04-23 01:53:49 +00:00
|
|
|
*(tCEs++) = tOrder;
|
2001-03-07 23:56:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* regular */
|
|
|
|
if(tOrder > LVT) {
|
|
|
|
*(tCEs++) = tOrder;
|
|
|
|
break;
|
|
|
|
} else {
|
2001-05-21 22:30:49 +00:00
|
|
|
if((tOrder & UCOL_PRIMARYMASK) > 0) {
|
2001-03-07 23:56:26 +00:00
|
|
|
tInShifted = TRUE;
|
2001-05-21 22:30:49 +00:00
|
|
|
tOrder &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
*(tCEs++) = tOrder;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
tOrder ^= caseSwitch;
|
|
|
|
*(tCEs++) = tOrder;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
tOrder &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
tInShifted = FALSE;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
if(sOrder == tOrder) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(sOrder == UCOL_NO_MORE_CES_PRIMARY) {
|
2001-03-07 23:56:26 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
sOrder = 0; tOrder = 0;
|
|
|
|
continue;
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
} else if(sOrder < tOrder) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else {
|
|
|
|
return UCOL_GREATER;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
} /* no primary difference... do the rest from the buffers */
|
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
/* now, we're gonna reexamine collected CEs */
|
|
|
|
sCEend = sCEs;
|
|
|
|
tCEend = tCEs;
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
/* This is the secondary level of comparison */
|
|
|
|
if(checkSecTer) {
|
|
|
|
if(!isFrenchSec) { /* normal */
|
|
|
|
sCEs = sCEsArray;
|
|
|
|
tCEs = tCEsArray;
|
|
|
|
for(;;) {
|
|
|
|
while (secS == 0) {
|
2001-05-21 22:30:49 +00:00
|
|
|
secS = *(sCEs++) & UCOL_SECONDARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
while(secT == 0) {
|
2001-05-21 22:30:49 +00:00
|
|
|
secT = *(tCEs++) & UCOL_SECONDARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
2001-01-05 00:47:25 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
if(secS == secT) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secS == UCOL_NO_MORE_CES_SECONDARY) {
|
2001-03-07 23:56:26 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0; secT = 0;
|
2001-03-07 23:56:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if(secS < secT) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else {
|
|
|
|
return UCOL_GREATER;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2000-12-08 00:52:46 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
} else { /* do the French */
|
|
|
|
uint32_t *sCESave = NULL;
|
|
|
|
uint32_t *tCESave = NULL;
|
|
|
|
sCEs = sCEend-2; /* this could also be sCEs-- if needs to be optimized */
|
|
|
|
tCEs = tCEend-2;
|
|
|
|
for(;;) {
|
|
|
|
while (secS == 0 && sCEs >= sCEsArray) {
|
|
|
|
if(sCESave == 0) {
|
|
|
|
secS = *(sCEs--) & 0xFF80;
|
|
|
|
if(isContinuation(secS)) {
|
|
|
|
while(isContinuation(secS = *(sCEs--) & 0xFF80));
|
|
|
|
/* after this, secS has the start of continuation, and sCEs points before that */
|
|
|
|
sCESave = sCEs; /* we save it, so that we know where to come back AND that we need to go forward */
|
|
|
|
sCEs+=2; /* need to point to the first continuation CP */
|
|
|
|
/* However, now you can just continue doing stuff */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
secS = *(sCEs++) & 0xFF80;
|
|
|
|
if(!isContinuation(secS)) { /* This means we have finished with this cont */
|
|
|
|
sCEs = sCESave; /* reset the pointer to before continuation */
|
|
|
|
sCESave = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secS &= UCOL_SECONDARYMASK; /* remove the continuation bit */
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
2000-12-08 00:52:46 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
while(secT == 0 && tCEs >= tCEsArray) {
|
|
|
|
if(tCESave == 0) {
|
|
|
|
secT = *(tCEs--) & 0xFF80;
|
|
|
|
if(isContinuation(secT)) {
|
|
|
|
while(isContinuation(secT = *(tCEs--) & 0xFF80));
|
|
|
|
/* after this, secS has the start of continuation, and sCEs points before that */
|
|
|
|
tCESave = tCEs; /* we save it, so that we know where to come back AND that we need to go forward */
|
|
|
|
tCEs+=2; /* need to point to the first continuation CP */
|
|
|
|
/* However, now you can just continue doing stuff */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
secT = *(tCEs++) & 0xFF80;
|
|
|
|
if(!isContinuation(secT)) { /* This means we have finished with this cont */
|
|
|
|
tCEs = tCESave; /* reset the pointer to before continuation */
|
|
|
|
tCESave = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-15 07:28:54 +00:00
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secT &= UCOL_SECONDARYMASK; /* remove the continuation bit */
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(secS == secT) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secS == UCOL_NO_MORE_CES_SECONDARY || (sCEs < sCEsArray && tCEs < tCEsArray)) {
|
2001-03-07 23:56:26 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0; secT = 0;
|
2001-03-07 23:56:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if(secS < secT) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else {
|
|
|
|
return UCOL_GREATER;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-01-15 07:28:54 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* doing the case bit */
|
|
|
|
if(checkCase) {
|
|
|
|
sCEs = sCEsArray;
|
|
|
|
tCEs = tCEsArray;
|
|
|
|
for(;;) {
|
|
|
|
while((secS & UCOL_REMOVE_CASE) == 0) {
|
2001-03-16 19:06:07 +00:00
|
|
|
if(!isContinuation(*sCEs++)) {
|
|
|
|
secS =*(sCEs-1) & UCOL_TERT_CASE_MASK;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while((secT & UCOL_REMOVE_CASE) == 0) {
|
2001-03-16 19:06:07 +00:00
|
|
|
if(!isContinuation(*tCEs++)) {
|
|
|
|
secT = *(tCEs-1) & UCOL_TERT_CASE_MASK;
|
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if((secS & UCOL_CASE_BIT_MASK) < (secT & UCOL_CASE_BIT_MASK)) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else if((secS & UCOL_CASE_BIT_MASK) > (secT & UCOL_CASE_BIT_MASK)) {
|
|
|
|
return UCOL_GREATER;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
|
2001-06-06 23:26:50 +00:00
|
|
|
if((secS & UCOL_REMOVE_CASE) == UCOL_NO_MORE_CES_TERTIARY
|
2001-05-21 22:30:49 +00:00
|
|
|
|| (secT & UCOL_REMOVE_CASE) == UCOL_NO_MORE_CES_TERTIARY ) {
|
2001-03-07 23:56:26 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
secS = 0;
|
|
|
|
secT = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tertiary level */
|
|
|
|
if(checkTertiary) {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0;
|
2001-03-07 23:56:26 +00:00
|
|
|
secT = 0;
|
|
|
|
sCEs = sCEsArray;
|
|
|
|
tCEs = tCEsArray;
|
|
|
|
for(;;) {
|
|
|
|
while((secS & UCOL_REMOVE_CASE) == 0) {
|
|
|
|
secS = *(sCEs++) & tertiaryMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
while((secT & UCOL_REMOVE_CASE) == 0) {
|
|
|
|
secT = *(tCEs++) & tertiaryMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(secS == secT) {
|
|
|
|
if((secS & UCOL_REMOVE_CASE) == 1) {
|
|
|
|
break;
|
|
|
|
} else {
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0; secT = 0;
|
2001-03-07 23:56:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if(secS < secT) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else {
|
|
|
|
return UCOL_GREATER;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
|
2001-03-15 02:49:35 +00:00
|
|
|
if(qShifted) {
|
2001-03-07 23:56:26 +00:00
|
|
|
UBool sInShifted = TRUE;
|
|
|
|
UBool tInShifted = TRUE;
|
2001-04-23 01:53:49 +00:00
|
|
|
secS = 0;
|
2001-03-07 23:56:26 +00:00
|
|
|
secT = 0;
|
|
|
|
sCEs = sCEsArray;
|
|
|
|
tCEs = tCEsArray;
|
|
|
|
for(;;) {
|
2001-05-21 22:30:49 +00:00
|
|
|
while(secS == 0 && secS != UCOL_NO_MORE_CES || (isContinuation(secS) && !sInShifted)) {
|
2001-03-07 23:56:26 +00:00
|
|
|
secS = *(sCEs++);
|
|
|
|
if(isContinuation(secS) && !sInShifted) {
|
|
|
|
continue;
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secS > LVT || (secS & UCOL_PRIMARYMASK) == 0) {
|
|
|
|
secS = UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
sInShifted = FALSE;
|
|
|
|
} else {
|
|
|
|
sInShifted = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secS &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
|
|
|
|
|
2001-05-21 22:30:49 +00:00
|
|
|
while(secT == 0 && secT != UCOL_NO_MORE_CES || (isContinuation(secT) && !tInShifted)) {
|
2001-03-07 23:56:26 +00:00
|
|
|
secT = *(tCEs++);
|
|
|
|
if(isContinuation(secT) && !tInShifted) {
|
|
|
|
continue;
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secT > LVT || (secT & UCOL_PRIMARYMASK) == 0) {
|
|
|
|
secT = UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
tInShifted = FALSE;
|
|
|
|
} else {
|
|
|
|
tInShifted = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 22:30:49 +00:00
|
|
|
secT &= UCOL_PRIMARYMASK;
|
2001-03-07 23:56:26 +00:00
|
|
|
|
|
|
|
if(secS == secT) {
|
2001-05-21 22:30:49 +00:00
|
|
|
if(secS == UCOL_NO_MORE_CES_PRIMARY) {
|
2001-03-07 23:56:26 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
secS = 0; secT = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if(secS < secT) {
|
|
|
|
return UCOL_LESS;
|
|
|
|
} else {
|
|
|
|
return UCOL_GREATER;
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
2001-01-16 00:28:40 +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 */
|
2001-03-07 23:56:26 +00:00
|
|
|
/* if (result == UCOL_EQUAL && strength == UCOL_IDENTICAL) */
|
|
|
|
if(checkIdent)
|
2001-01-15 07:28:54 +00:00
|
|
|
{
|
|
|
|
UnicodeString sourceDecomp, targetDecomp;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
int8_t comparison;
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-03-14 01:14:34 +00:00
|
|
|
/* synwee : implemented in c++ since normalizer is implemented there */
|
|
|
|
Normalizer::EMode mode = Normalizer::getNormalizerEMode(
|
|
|
|
ucol_getNormalization(coll), status);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
|
|
|
Normalizer::normalize(UnicodeString(sColl.stringP, sColl.len-sColl.stringP-1),
|
2001-03-14 01:14:34 +00:00
|
|
|
mode, 0, sourceDecomp, status);
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-04-23 01:53:49 +00:00
|
|
|
Normalizer::normalize(UnicodeString(tColl.stringP, tColl.len-tColl.stringP-1),
|
2001-03-14 01:14:34 +00:00
|
|
|
mode, 0, targetDecomp, status);
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
comparison = sourceDecomp.compare(targetDecomp);
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
if (comparison < 0)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS;
|
|
|
|
}
|
|
|
|
else if (comparison == 0)
|
|
|
|
{
|
|
|
|
result = UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER;
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* convenience function for comparing strings */
|
|
|
|
U_CAPI UBool
|
|
|
|
ucol_greater( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
2001-04-23 01:53:49 +00:00
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
2001-01-16 00:28:40 +00:00
|
|
|
== UCOL_GREATER);
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* convenience function for comparing strings */
|
|
|
|
U_CAPI UBool
|
|
|
|
ucol_greaterOrEqual( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
2001-04-23 01:53:49 +00:00
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
2001-01-16 00:28:40 +00:00
|
|
|
!= UCOL_LESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convenience function for comparing strings */
|
|
|
|
U_CAPI UBool
|
|
|
|
ucol_equal( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
2001-04-23 01:53:49 +00:00
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
2001-01-16 00:28:40 +00:00
|
|
|
== UCOL_EQUAL);
|
2001-01-15 07:28:54 +00:00
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
int32_t ucol_getIncrementalCE(const UCollator *coll, incrementalContext *ctx, UErrorCode *status) {
|
2001-03-07 23:56:26 +00:00
|
|
|
uint32_t order;
|
|
|
|
if (ctx->CEpos > ctx->toReturn) { /* Are there any CEs from previous expansions? */
|
|
|
|
order = *(ctx->toReturn++); /* if so, return them */
|
|
|
|
if(ctx->CEpos == ctx->toReturn) {
|
2001-04-23 01:53:49 +00:00
|
|
|
ctx->CEpos = ctx->toReturn = ctx->CEs;
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
|
|
|
} else { /* This is the real business now */
|
|
|
|
if(ctx->lastChar == 0xFFFF) {
|
|
|
|
ctx->currentChar = ctx->source(ctx->sourceContext);
|
|
|
|
incctx_appendChar(ctx, ctx->currentChar);
|
|
|
|
if(ctx->currentChar == 0xFFFF) {
|
|
|
|
return UCOL_NO_MORE_CES;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctx->currentChar = ctx->lastChar;
|
|
|
|
ctx->lastChar = 0xFFFF;
|
2001-01-15 07:28:54 +00:00
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
UChar ch = ctx->currentChar;
|
|
|
|
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 */
|
|
|
|
order = ucol_getIncrementalSpecialCE(coll, order, ctx, status); /* and try to get the special CE */
|
|
|
|
if(order == UCOL_NOT_FOUND) { /* We couldn't find a good CE in the tailoring */
|
2001-03-09 00:50:37 +00:00
|
|
|
order = ucol_getIncrementalUCA(ch, ctx, status);
|
2001-03-07 23:56:26 +00:00
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
/* This means that contraction should spit back the last codepoint eaten! */
|
|
|
|
return order; /* return the CE */
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function tries to get a CE from UCA, which should be always around */
|
|
|
|
/* UChar is passed in in order to speed things up */
|
|
|
|
/* here is also the generation of implicit CEs */
|
2001-03-09 00:50:37 +00:00
|
|
|
uint32_t ucol_getIncrementalUCA(UChar ch, incrementalContext *collationSource, UErrorCode *status) {
|
2001-01-16 00:28:40 +00:00
|
|
|
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 */
|
2001-04-23 01:53:49 +00:00
|
|
|
order = ucol_getIncrementalSpecialCE(UCA, order, collationSource, status);
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
if(order == UCOL_NOT_FOUND) { /* This is where we have to resort to algorithmical generation */
|
|
|
|
/* 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 */
|
2001-04-23 01:53:49 +00:00
|
|
|
const uint32_t
|
2001-03-07 23:56:26 +00:00
|
|
|
SBase = 0xAC00, LBase = 0x1100, VBase = 0x1161, TBase = 0x11A7,
|
|
|
|
LCount = 19, VCount = 21, TCount = 28,
|
|
|
|
NCount = VCount * TCount, // 588
|
|
|
|
SCount = LCount * NCount; // 11172
|
|
|
|
//LLimit = LBase + LCount, // 1113
|
|
|
|
//VLimit = VBase + VCount, // 1176
|
|
|
|
//TLimit = TBase + TCount, // 11C3
|
|
|
|
//SLimit = SBase + SCount; // D7A4
|
|
|
|
|
|
|
|
// once we have failed to find a match for codepoint cp, and are in the implicit code.
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
uint32_t L = ch - SBase;
|
|
|
|
//if (ch < SLimit) { // since it is unsigned, catchs zero case too
|
|
|
|
if (L < SCount) { // since it is unsigned, catchs zero case too
|
|
|
|
|
|
|
|
// divide into pieces
|
|
|
|
|
|
|
|
uint32_t T = L % TCount; // we do it in this order since some compilers can do % and / in one operation
|
|
|
|
L /= TCount;
|
|
|
|
uint32_t V = L % VCount;
|
|
|
|
L /= VCount;
|
|
|
|
|
|
|
|
// offset them
|
|
|
|
|
|
|
|
L += LBase;
|
|
|
|
V += VBase;
|
|
|
|
T += TBase;
|
|
|
|
|
|
|
|
// return the first CE, but first put the rest into the expansion buffer
|
2001-03-09 00:50:37 +00:00
|
|
|
if (!collationSource->coll->image->jamoSpecial) { // FAST PATH
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
*(collationSource->CEpos++) = ucmp32_get(UCA->mapping, V);
|
|
|
|
if (T != TBase) {
|
|
|
|
*(collationSource->CEpos++) = ucmp32_get(UCA->mapping, T);
|
|
|
|
}
|
2001-04-23 01:53:49 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
return ucmp32_get(UCA->mapping, L); // return first one
|
|
|
|
|
|
|
|
} else { // Jamo is Special
|
2001-03-22 18:45:31 +00:00
|
|
|
collIterate jamos;
|
|
|
|
UChar jamoString[3];
|
|
|
|
uint32_t CE = UCOL_NOT_FOUND;
|
|
|
|
const UCollator *collator = collationSource->coll;
|
2001-03-28 20:12:12 +00:00
|
|
|
jamoString[0] = (UChar)L;
|
|
|
|
jamoString[1] = (UChar)V;
|
2001-03-22 18:45:31 +00:00
|
|
|
if (T != TBase) {
|
2001-03-28 20:12:12 +00:00
|
|
|
jamoString[2] = (UChar)T;
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(collator, jamoString, 3, &jamos);
|
2001-03-22 18:45:31 +00:00
|
|
|
} else {
|
2001-04-06 23:37:48 +00:00
|
|
|
IInit_collIterate(collator, jamoString, 2, &jamos);
|
2001-03-22 18:45:31 +00:00
|
|
|
}
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
CE = ucol_IGetNextCE(collator, &jamos, status);
|
2001-03-22 18:45:31 +00:00
|
|
|
|
|
|
|
while(CE != UCOL_NO_MORE_CES) {
|
|
|
|
*(collationSource->CEpos++) = CE;
|
2001-04-18 19:31:05 +00:00
|
|
|
CE = ucol_IGetNextCE(collator, &jamos, status);
|
2001-03-22 18:45:31 +00:00
|
|
|
}
|
|
|
|
return *(collationSource->toReturn++);
|
|
|
|
|
|
|
|
/*
|
2001-03-09 00:50:37 +00:00
|
|
|
ucol_getJamoCEs(collationSource->coll, L, &collationSource->CEpos);
|
|
|
|
ucol_getJamoCEs(collationSource->coll, V, &collationSource->CEpos);
|
|
|
|
if (T != TBase) {
|
|
|
|
ucol_getJamoCEs(collationSource->coll, T, &collationSource->CEpos);
|
|
|
|
}
|
|
|
|
return *(collationSource->toReturn++);
|
2001-03-22 18:45:31 +00:00
|
|
|
*/
|
2001-03-07 23:56:26 +00:00
|
|
|
|
2001-03-09 00:50:37 +00:00
|
|
|
/*
|
2001-03-07 23:56:26 +00:00
|
|
|
// do recursive processing of L, V, and T with fetchCE (but T only if not equal to TBase!!)
|
|
|
|
// Since fetchCE returns a CE, and (potentially) stuffs items into the ce buffer,
|
|
|
|
// this is how it is done.
|
2001-03-09 00:50:37 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
int firstCE = fetchCE(L, ...);
|
|
|
|
int* lastExpansion = expansionBufferEnd++; // set pointer, leave gap!
|
|
|
|
*lastExpansion = fetchCE(V,...);
|
|
|
|
if (T != TBase) {
|
|
|
|
lastExpansion = expansionBufferEnd++; // set pointer, leave gap!
|
|
|
|
*lastExpansion = fetchCE(T,...);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
collationSource->lastChar = collationSource->source(collationSource->sourceContext);
|
|
|
|
incctx_appendChar(collationSource, collationSource->lastChar);
|
|
|
|
|
|
|
|
if(UTF_IS_FIRST_SURROGATE(ch)) {
|
|
|
|
if( (collationSource->lastChar != 0xFFFF) &&
|
|
|
|
UTF_IS_SECOND_SURROGATE((collationSource->lastChar))) {
|
2001-05-16 18:23:26 +00:00
|
|
|
//uint32_t cp = (((ch)<<10UL)+(collationSource->lastChar)-((0xd800<<10UL)+0xdc00));
|
|
|
|
uint32_t cp = ((((uint32_t)ch)<<10UL)+(collationSource->lastChar)-(((uint32_t)0xd800<<10UL)+0xdc00-0x10000));
|
2001-03-07 23:56:26 +00:00
|
|
|
collationSource->lastChar = 0xFFFF; /*used up*/
|
|
|
|
if ((cp & 0xFFFE) == 0xFFFE || (0xD800 <= cp && cp <= 0xDC00)) {
|
|
|
|
return 0; /* illegal code value, use completely ignoreable! */
|
|
|
|
}
|
|
|
|
/* This is a code point minus 0x10000, that's what algorithm requires */
|
|
|
|
order = 0xE0010303 | (cp & 0xFFE00) << 8;
|
|
|
|
|
|
|
|
*(collationSource->CEpos++) = 0x80200080 | (cp & 0x001FF) << 22;
|
|
|
|
} else {
|
|
|
|
return 0; /* completely ignorable */
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
} else {
|
|
|
|
/* otherwise */
|
2001-03-07 23:56:26 +00:00
|
|
|
if(UTF_IS_SECOND_SURROGATE((ch)) || (ch & 0xFFFE) == 0xFFFE) {
|
|
|
|
return 0; /* completely ignorable */
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
/* Make up an artifical CE from code point as per UCA */
|
2001-03-07 23:56:26 +00:00
|
|
|
order = 0xD0800303 | (ch & 0xF000) << 12 | (ch & 0x0FE0) << 11;
|
|
|
|
*(collationSource->CEpos++) = 0x04000080 | (ch & 0x001F) << 27;
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
return order; /* return the CE */
|
|
|
|
}
|
|
|
|
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-03-07 23:56:26 +00:00
|
|
|
int32_t ucol_getIncrementalSpecialCE(const UCollator *coll, uint32_t CE, incrementalContext *source, UErrorCode *status) {
|
2001-03-22 21:16:20 +00:00
|
|
|
uint32_t i = 0; /* general counter */
|
2001-03-07 23:56:26 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*status)) return -1;
|
|
|
|
|
2001-03-17 00:46:46 +00:00
|
|
|
for(;;) {
|
2001-01-16 00:28:40 +00:00
|
|
|
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;
|
|
|
|
case SURROGATE_TAG:
|
|
|
|
/* pending surrogate discussion with Markus and Mark */
|
|
|
|
return UCOL_NOT_FOUND;
|
|
|
|
case THAI_TAG:
|
|
|
|
/* Thai/Lao reordering */
|
2001-03-07 23:56:26 +00:00
|
|
|
source->panic = TRUE;
|
|
|
|
return UCOL_NO_MORE_CES;
|
2001-01-16 00:28:40 +00:00
|
|
|
case CONTRACTION_TAG:
|
|
|
|
/* This should handle contractions */
|
|
|
|
for(;;) {
|
|
|
|
/* First we position ourselves at the begining of contraction sequence */
|
|
|
|
const UChar *ContractionStart = UCharOffset = (UChar *)coll->image+getContractOffset(CE);
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-16 00:28:40 +00:00
|
|
|
/* we need to convey the notion of having a backward search - most probably through the context object */
|
|
|
|
/* if (backwardsSearch) offset += contractionUChars[(int16_t)offset]; else UCharOffset++; */
|
2001-03-07 23:56:26 +00:00
|
|
|
schar = source->lastChar = source->source(source->sourceContext);
|
|
|
|
incctx_appendChar(source, source->lastChar);
|
|
|
|
if (schar == 0xFFFF) { /* this is the end of string */
|
2001-01-16 00:28:40 +00:00
|
|
|
CE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex)); /* So we'll pick whatever we have at the point... */
|
2001-04-23 01:53:49 +00:00
|
|
|
//! source->pos--; /* I think, since we'll advance in the getCE */
|
2001-01-16 00:28:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-03-17 00:46:46 +00:00
|
|
|
UCharOffset++; /* skip the backward offset, see above */
|
|
|
|
//! schar = *(++source->pos);
|
2001-01-16 00:28:40 +00:00
|
|
|
while(schar > (tchar = *UCharOffset)) { /* since the contraction codepoints should be ordered, we skip all that are smaller */
|
|
|
|
UCharOffset++;
|
|
|
|
}
|
|
|
|
if(schar != tchar) { /* we didn't find the correct codepoint. We can use either the first or the last CE */
|
|
|
|
if(tchar != 0xFFFF) {
|
|
|
|
UCharOffset = ContractionStart; /* We're not at the end, bailed out in the middle. Better use starting CE */
|
|
|
|
}
|
2001-03-07 23:56:26 +00:00
|
|
|
//! source->pos--; /* Spit out the last char of the string, wasn't tasty enough */
|
|
|
|
} else {
|
|
|
|
source->lastChar = 0xFFFF;
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
CE = *(coll->contractionCEs + (UCharOffset - coll->contractionIndex));
|
2001-03-17 00:46:46 +00:00
|
|
|
/*
|
2001-01-16 00:28:40 +00:00
|
|
|
if(!isContraction(CE)) {
|
2001-04-23 01:53:49 +00:00
|
|
|
break;
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
2001-03-17 00:46:46 +00:00
|
|
|
*/
|
|
|
|
if(isContraction(CE)) { /* fix for the bug. Other places need to be checked */
|
|
|
|
/* this is contraction, and we will continue. However, we can fail along the */
|
|
|
|
/* th road, which means that we have part of contraction correct */
|
|
|
|
source->panic = TRUE;
|
|
|
|
return UCOL_NO_MORE_CES;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
}
|
|
|
|
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 */
|
|
|
|
CEOffset = (uint32_t *)coll->image+getExpansionOffset(CE); /* find the offset to expansion table */
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*source->toReturn++;*/
|
|
|
|
return CE;
|
|
|
|
case CHARSET_TAG:
|
|
|
|
/* probably after 1.8 */
|
|
|
|
return UCOL_NOT_FOUND;
|
|
|
|
default:
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
CE=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (CE <= UCOL_NOT_FOUND) break;
|
2001-01-15 07:28:54 +00:00
|
|
|
}
|
2001-01-16 00:28:40 +00:00
|
|
|
return CE;
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
void incctx_cleanUpContext(incrementalContext *ctx) {
|
|
|
|
if(ctx->stringP != ctx->stackString) {
|
|
|
|
uprv_free(ctx->stringP);
|
|
|
|
}
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
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*/
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-15 07:28:54 +00:00
|
|
|
ctx->len=newStuff+(ctx->len - ctx->stringP);
|
|
|
|
ctx->capacity = newStuff+2*(ctx->capacity - ctx->stringP);
|
|
|
|
ctx->stringP = newStuff;
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-15 07:28:54 +00:00
|
|
|
*(ctx->len++) = c;
|
|
|
|
return c;
|
|
|
|
}
|
2001-01-04 00:45:41 +00:00
|
|
|
|
|
|
|
|
2001-01-15 07:28:54 +00:00
|
|
|
|
|
|
|
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);
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-15 07:28:54 +00:00
|
|
|
if(trgCtx->stringP == trgCtx->len || *(trgCtx->len-1) != 0xFFFF) {
|
|
|
|
while(incctx_appendChar(trgCtx, trgCtx->source(trgCtx->sourceContext)) != 0xFFFF);
|
2001-01-04 00:45:41 +00:00
|
|
|
}
|
2001-01-15 07:28:54 +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);
|
2000-12-12 01:15:30 +00:00
|
|
|
return result;
|
|
|
|
}
|