1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-11-23 01:30:04 +00:00
|
|
|
* Copyright (C) 1996-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ucol.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/coll.h"
|
|
|
|
#include "unicode/tblcoll.h"
|
|
|
|
#include "unicode/coleitr.h"
|
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/normlzr.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cpputils.h"
|
2000-05-15 19:48:26 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
#define UCOL_UNMAPPEDCHARVALUE 0x7fff0000 // from coleiterator
|
|
|
|
|
2000-11-07 00:00:17 +00:00
|
|
|
#define UCOL_LEVELTERMINATOR 0
|
|
|
|
#define UCOL_IGNORABLE 0x0000
|
|
|
|
#define UCOL_CHARINDEX 0x70000000 // need look up in .commit()
|
|
|
|
#define UCOL_EXPANDCHARINDEX 0x7E000000 // Expand index follows
|
|
|
|
#define UCOL_CONTRACTCHARINDEX 0x7F000000 // contract indexes follows
|
|
|
|
#define UCOL_UNMAPPED 0xFFFFFFFF // unmapped character values
|
|
|
|
#define UCOL_PRIMARYORDERINCREMENT 0x00010000 // primary strength increment
|
|
|
|
#define UCOL_SECONDARYORDERINCREMENT 0x00000100 // secondary strength increment
|
|
|
|
#define UCOL_TERTIARYORDERINCREMENT 0x00000001 // tertiary strength increment
|
|
|
|
#define UCOL_MAXIGNORABLE 0x00010000 // maximum ignorable char order value
|
|
|
|
#define UCOL_PRIMARYORDERMASK 0xffff0000 // mask off anything but primary order
|
|
|
|
#define UCOL_SECONDARYORDERMASK 0x0000ff00 // mask off anything but secondary order
|
|
|
|
#define UCOL_TERTIARYORDERMASK 0x000000ff // mask off anything but tertiary order
|
|
|
|
#define UCOL_SECONDARYRESETMASK 0x0000ffff // mask off secondary and tertiary order
|
|
|
|
#define UCOL_IGNORABLEMASK 0x0000ffff // mask off ignorable char order
|
|
|
|
#define UCOL_PRIMARYDIFFERENCEONLY 0xffff0000 // use only the primary difference
|
|
|
|
#define UCOL_SECONDARYDIFFERENCEONLY 0xffffff00 // use only the primary and secondary difference
|
|
|
|
#define UCOL_PRIMARYORDERSHIFT 16 // primary order shift
|
|
|
|
#define UCOL_SECONDARYORDERSHIFT 8 // secondary order shift
|
|
|
|
#define UCOL_SORTKEYOFFSET 1 // minimum sort key offset
|
|
|
|
#define UCOL_CONTRACTCHAROVERFLOW 0x7FFFFFFF // Indicates the char is a contract char
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
u_normalize(const UChar* source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
UNormalizationMode mode,
|
|
|
|
int32_t option,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
Normalizer::EMode normMode;
|
|
|
|
switch(mode) {
|
|
|
|
case UCOL_NO_NORMALIZATION:
|
|
|
|
normMode = Normalizer::NO_OP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN:
|
|
|
|
normMode = Normalizer::DECOMP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT:
|
|
|
|
normMode = Normalizer::DECOMP_COMPAT;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN_COMP_COMPAT:
|
|
|
|
normMode = Normalizer::COMPOSE;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT_COMP_CAN:
|
|
|
|
normMode = Normalizer::COMPOSE_COMPAT;
|
|
|
|
break;
|
2000-08-23 16:46:39 +00:00
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t len = (sourceLength == -1 ? u_strlen(source) : sourceLength);
|
|
|
|
const UnicodeString src((UChar*)source, len, len);
|
|
|
|
UnicodeString dst(result, 0, resultLength);
|
|
|
|
Normalizer::normalize(src, normMode, option, dst, *status);
|
|
|
|
int32_t actualLen;
|
|
|
|
T_fillOutputParams(&dst, result, resultLength, &actualLen, status);
|
|
|
|
return actualLen;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UCollator*
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_open( const char *loc,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
Collator *col = 0;
|
|
|
|
|
|
|
|
if(loc == 0)
|
|
|
|
col = Collator::createInstance(*status);
|
|
|
|
else
|
2000-04-15 21:23:28 +00:00
|
|
|
col = Collator::createInstance(Locale(loc), *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if(col == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UCollator*)col;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UCollator*
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_openRules( const UChar *rules,
|
|
|
|
int32_t rulesLength,
|
|
|
|
UNormalizationMode mode,
|
|
|
|
UCollationStrength strength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t len = (rulesLength == -1 ? u_strlen(rules) : rulesLength);
|
|
|
|
const UnicodeString ruleString((UChar*)rules, len, len);
|
|
|
|
|
|
|
|
Normalizer::EMode normMode;
|
|
|
|
switch(mode) {
|
|
|
|
case UCOL_NO_NORMALIZATION:
|
|
|
|
normMode = Normalizer::NO_OP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN:
|
|
|
|
normMode = Normalizer::DECOMP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT:
|
|
|
|
normMode = Normalizer::DECOMP_COMPAT;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN_COMP_COMPAT:
|
|
|
|
normMode = Normalizer::COMPOSE;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT_COMP_CAN:
|
|
|
|
normMode = Normalizer::COMPOSE_COMPAT;
|
|
|
|
break;
|
2000-08-23 16:46:39 +00:00
|
|
|
default:
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RuleBasedCollator *col = 0;
|
|
|
|
col = new RuleBasedCollator(ruleString,
|
|
|
|
(Collator::ECollationStrength) strength,
|
|
|
|
normMode,
|
|
|
|
*status);
|
|
|
|
|
|
|
|
if(col == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UCollator*) col;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_close(UCollator *coll)
|
|
|
|
{
|
|
|
|
delete (Collator*)coll;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_greater( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
|
|
|
== UCOL_GREATER);
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_greaterOrEqual( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
|
|
|
!= UCOL_LESS);
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_equal( const UCollator *coll,
|
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
return (ucol_strcoll(coll, source, sourceLength, target, targetLength)
|
|
|
|
== UCOL_EQUAL);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UCollationStrength
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getStrength(const UCollator *coll)
|
|
|
|
{
|
|
|
|
return (UCollationStrength) ((Collator*)coll)->getStrength();
|
|
|
|
}
|
|
|
|
|
2000-11-20 19:17:17 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_setStrength( UCollator *coll,
|
|
|
|
UCollationStrength strength)
|
|
|
|
{
|
|
|
|
((Collator*)coll)->setStrength((Collator::ECollationStrength)strength);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UNormalizationMode
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getNormalization(const UCollator* coll)
|
|
|
|
{
|
|
|
|
switch(((Collator*)coll)->getDecomposition()) {
|
|
|
|
case Normalizer::NO_OP:
|
|
|
|
return UCOL_NO_NORMALIZATION;
|
|
|
|
|
|
|
|
case Normalizer::COMPOSE:
|
|
|
|
return UCOL_DECOMP_COMPAT_COMP_CAN;
|
|
|
|
|
|
|
|
case Normalizer::COMPOSE_COMPAT:
|
|
|
|
return UCOL_DECOMP_CAN_COMP_COMPAT;
|
|
|
|
|
|
|
|
case Normalizer::DECOMP:
|
2000-11-22 00:04:03 +00:00
|
|
|
return UCOL_DECOMP_CAN;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case Normalizer::DECOMP_COMPAT:
|
|
|
|
return UCOL_DECOMP_COMPAT;
|
1999-10-22 00:43:39 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-10-22 00:43:39 +00:00
|
|
|
return UCOL_NO_NORMALIZATION;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_setNormalization( UCollator *coll,
|
|
|
|
UNormalizationMode mode)
|
|
|
|
{
|
|
|
|
Normalizer::EMode normMode;
|
|
|
|
switch(mode) {
|
|
|
|
case UCOL_NO_NORMALIZATION:
|
|
|
|
normMode = Normalizer::NO_OP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN:
|
|
|
|
normMode = Normalizer::DECOMP;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT:
|
|
|
|
normMode = Normalizer::DECOMP_COMPAT;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_COMPAT_COMP_CAN:
|
|
|
|
normMode = Normalizer::COMPOSE;
|
|
|
|
break;
|
|
|
|
case UCOL_DECOMP_CAN_COMP_COMPAT:
|
|
|
|
normMode = Normalizer::COMPOSE_COMPAT;
|
|
|
|
break;
|
2000-08-23 16:46:39 +00:00
|
|
|
default:
|
|
|
|
/* Shouldn't get here. */
|
|
|
|
/* *status = U_ILLEGAL_ARGUMENT_ERROR; */
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
((Collator*)coll)->setDecomposition(normMode);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getDisplayName( const char *objLoc,
|
|
|
|
const char *dispLoc,
|
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString dst(result, resultLength, resultLength);
|
2000-04-15 21:23:28 +00:00
|
|
|
Collator::getDisplayName(Locale(objLoc), Locale(dispLoc), dst);
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t actLen;
|
|
|
|
T_fillOutputParams(&dst, result, resultLength, &actLen, status);
|
|
|
|
return actLen;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const char*
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getAvailable(int32_t index)
|
|
|
|
{
|
|
|
|
return uloc_getAvailable(index);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_countAvailable()
|
|
|
|
{
|
|
|
|
return uloc_countAvailable();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UChar*
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getRules( const UCollator *coll,
|
|
|
|
int32_t *length)
|
|
|
|
{
|
|
|
|
const UnicodeString& rules = ((RuleBasedCollator*)coll)->getRules();
|
1999-12-08 02:11:04 +00:00
|
|
|
*length = rules.length();
|
1999-08-16 21:50:52 +00:00
|
|
|
return rules.getUChars();
|
|
|
|
}
|
|
|
|
|
2000-11-20 19:17:17 +00:00
|
|
|
static uint8_t 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, 0x20, 0xf8, 0xf8, 0xf8, 0xf8
|
|
|
|
};
|
|
|
|
|
|
|
|
// This will get the next CE(s)?
|
|
|
|
// Should be part macro, part function
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2000-11-07 00:00:17 +00:00
|
|
|
#include "unicode/normlzr.h"
|
|
|
|
#include "ucmp32.h"
|
|
|
|
#include "tcoldata.h"
|
|
|
|
#include "tables.h"
|
2000-11-20 19:17:17 +00:00
|
|
|
#define UCOL_MAX_BUFFER 1000
|
2000-11-29 00:16:15 +00:00
|
|
|
#define UCOL_WRITABLE_BUFFER_SIZE 256
|
2000-11-07 00:00:17 +00:00
|
|
|
|
|
|
|
struct collIterate {
|
|
|
|
UChar *string; // Original string
|
2000-11-20 19:17:17 +00:00
|
|
|
UChar *len; // Original string length
|
|
|
|
UChar *pos; // This is position in the string
|
|
|
|
uint32_t *toReturn; // This is the CE from CEs buffer that should be returned
|
|
|
|
uint32_t *CEpos; // This is the position to which we have stored processed CEs
|
2000-11-29 00:16:15 +00:00
|
|
|
uint32_t CEs[UCOL_MAX_BUFFER]; // This is where we store CEs
|
|
|
|
UBool isThai; // Have we already encountered a Thai prevowel
|
|
|
|
UBool isWritable; // is the source buffer writable?
|
|
|
|
UChar stackWritableBuffer[UCOL_WRITABLE_BUFFER_SIZE]; // A writable buffer.
|
|
|
|
UChar *writableBuffer;
|
2000-11-07 00:00:17 +00:00
|
|
|
};
|
2000-11-29 00:16:15 +00:00
|
|
|
/*
|
|
|
|
void init_collIterate(const UChar *string, int32_t len, collIterate *s, UBool isWritable) {
|
2000-11-20 19:17:17 +00:00
|
|
|
s->string = s->pos = (UChar *)string;
|
|
|
|
s->len = (UChar *)string+len;
|
|
|
|
s->CEpos = s->toReturn = s->CEs;
|
2000-11-29 00:16:15 +00:00
|
|
|
s->isThai = TRUE;
|
|
|
|
s->isWritable = isWritable;
|
|
|
|
s->writableBuffer = s->stackWritableBuffer;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
#define init_collIterate(sourceString, sourceLen, s, isSourceWritable) { \
|
|
|
|
(s)->string = (s)->pos = (UChar *)(sourceString); \
|
|
|
|
(s)->len = (UChar *)(sourceString)+(sourceLen); \
|
|
|
|
(s)->CEpos = (s)->toReturn = (s)->CEs; \
|
|
|
|
(s)->isThai = TRUE; \
|
|
|
|
(s)->isWritable = (isSourceWritable); \
|
|
|
|
(s)->writableBuffer = (s)->stackWritableBuffer; \
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
/**
|
|
|
|
* Determine if a character is a Thai vowel (which sorts after
|
|
|
|
* its base consonant).
|
|
|
|
*/
|
|
|
|
#define isThaiPreVowel(ch) ((uint32_t)(ch) - 0xe40) <= (0xe44 - 0xe40)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a character is a Thai base consonant
|
|
|
|
*/
|
|
|
|
#define isThaiBaseConsonant(ch) ((uint32_t)(ch) - 0xe01) <= (0xe2e - 0xe01)
|
|
|
|
|
|
|
|
/*
|
2000-11-07 00:00:17 +00:00
|
|
|
int32_t ucol_getNextCE(const UCollator *coll, collIterate *source, UErrorCode *status) {
|
|
|
|
|
|
|
|
if (U_FAILURE(*status) || (source->pos>=source->len && source->CEpos <= source->toReturn)) {
|
|
|
|
return CollationElementIterator::NULLORDER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source->CEpos > source->toReturn) {
|
2000-11-20 19:17:17 +00:00
|
|
|
return(*(source->toReturn++));
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
|
|
|
source->CEpos = source->toReturn = source->CEs;
|
|
|
|
|
|
|
|
*(source->CEpos) = ucmp32_get(((RuleBasedCollator *)coll)->data->mapping, *(source->pos));
|
2000-11-07 00:00:17 +00:00
|
|
|
|
|
|
|
// this should benefit from reordering of the clauses, so that the cleanest case is returned the first.
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if(*(source->CEpos) < UCOL_EXPANDCHARINDEX && !(isThaiPreVowel(*(source->pos)))) {
|
2000-11-07 00:00:17 +00:00
|
|
|
source->pos++;
|
2000-11-20 19:17:17 +00:00
|
|
|
return (*(source->CEpos));
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
return getComplicatedCE(coll, source, status);
|
|
|
|
}
|
|
|
|
*/
|
2000-11-07 00:00:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
#define UCOL_getNextCE(order, coll, collationSource, status) { \
|
|
|
|
if (U_FAILURE(*(status)) || ((collationSource)->pos>=(collationSource)->len \
|
|
|
|
&& (collationSource)->CEpos <= (collationSource)->toReturn)) { \
|
|
|
|
(order) = UCOL_NULLORDER; \
|
|
|
|
} else if ((collationSource)->CEpos > (collationSource)->toReturn) { \
|
|
|
|
(order) = *((collationSource)->toReturn++); \
|
|
|
|
} else {\
|
|
|
|
(collationSource)->CEpos = (collationSource)->toReturn = (collationSource)->CEs; \
|
|
|
|
*((collationSource)->CEpos) = ucmp32_get(((RuleBasedCollator *)(coll))->data->mapping, *((collationSource)->pos)); \
|
|
|
|
if(*((collationSource)->CEpos) < UCOL_EXPANDCHARINDEX && !(isThaiPreVowel(*((collationSource)->pos)))) { \
|
|
|
|
(collationSource)->pos++; \
|
|
|
|
(order)=(*((collationSource)->CEpos)); \
|
|
|
|
} else { \
|
|
|
|
(order) = getComplicatedCE((coll), (collationSource), (status)); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32_t getComplicatedCE(const UCollator *coll, collIterate *source, UErrorCode *status) {
|
2000-11-20 19:17:17 +00:00
|
|
|
if (*(source->CEpos) == UCOL_UNMAPPED) {
|
2000-11-07 00:00:17 +00:00
|
|
|
// Returned an "unmapped" flag and save the character so it can be
|
|
|
|
// returned next time this method is called.
|
2000-11-20 19:17:17 +00:00
|
|
|
if (*(source->pos) == 0x0000) return *(source->pos++); // \u0000 is not valid in C++'s UnicodeString
|
2000-11-29 00:16:15 +00:00
|
|
|
*(source->CEpos++) = UCOL_UNMAPPEDCHARVALUE;
|
2000-11-22 23:52:43 +00:00
|
|
|
*(source->CEpos++) = *(source->pos)<<16;
|
2000-11-07 00:00:17 +00:00
|
|
|
} else {
|
|
|
|
// Contraction sequence start...
|
2000-11-20 19:17:17 +00:00
|
|
|
if (*(source->CEpos) >= UCOL_CONTRACTCHARINDEX) {
|
2000-11-22 23:52:43 +00:00
|
|
|
UChar key[1024];
|
|
|
|
for(int aj = 0; aj < 1024; aj++) {
|
|
|
|
key[aj] = 0;
|
|
|
|
}
|
|
|
|
uint32_t posKey = 0;
|
|
|
|
|
2000-11-20 19:17:17 +00:00
|
|
|
VectorOfPToContractElement* list = ((RuleBasedCollator *)coll)->data->contractTable->at(*(source->CEpos)-UCOL_CONTRACTCHARINDEX);
|
2000-11-07 00:00:17 +00:00
|
|
|
// The upper line obtained a list of contracting sequences.
|
2000-11-22 00:04:03 +00:00
|
|
|
if (list != NULL) {
|
|
|
|
EntryPair *pair = (EntryPair *)list->at(0); // Taking out the first one.
|
|
|
|
int32_t order = pair->value; // This got us mapping for just the first element - the one that signalled a contraction.
|
|
|
|
|
|
|
|
key[posKey++] = *(source->pos);
|
|
|
|
// This tries to find the longes common match for the data in contraction table...
|
|
|
|
// and needs to be rewritten, especially the test down there!
|
|
|
|
int32_t i;
|
|
|
|
UBool foundSmaller = TRUE;
|
|
|
|
while(source->pos<source->len && foundSmaller) {
|
|
|
|
|
|
|
|
key[posKey++] = *(++source->pos);
|
|
|
|
|
|
|
|
foundSmaller = FALSE;
|
|
|
|
i = 0;
|
|
|
|
while(i<list->size() && !foundSmaller) {
|
|
|
|
pair = list->at(i);
|
2000-11-29 04:48:39 +00:00
|
|
|
if ((pair != NULL) && (pair->fwd == TRUE /*fwd*/) && (pair->equalTo(key, posKey))) {
|
2000-11-22 00:04:03 +00:00
|
|
|
order = pair->value;
|
|
|
|
foundSmaller = TRUE;
|
|
|
|
}
|
|
|
|
i++;
|
2000-11-22 23:52:43 +00:00
|
|
|
|
2000-11-22 00:04:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
source->pos--; /* spit back the last char - it wasn't part of the sequence */
|
|
|
|
*(source->CEpos) = order;
|
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
// Expansion sequence start...
|
2000-11-22 00:04:03 +00:00
|
|
|
if (*(source->CEpos) >= UCOL_EXPANDCHARINDEX) {
|
2000-11-20 19:17:17 +00:00
|
|
|
VectorOfInt *v = ((RuleBasedCollator *)coll)->data->expandTable->at(*(source->CEpos)-UCOL_EXPANDCHARINDEX);
|
2000-11-07 00:00:17 +00:00
|
|
|
if(v != NULL) {
|
|
|
|
int32_t expandindex=0;
|
|
|
|
while(expandindex < v->size()) {
|
2000-11-20 19:17:17 +00:00
|
|
|
*(source->CEpos++) = v->at(expandindex++);
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
|
|
|
// Thai/Lao reordering
|
2000-11-29 00:16:15 +00:00
|
|
|
if (isThaiPreVowel(*(source->pos)) &&
|
|
|
|
isThaiBaseConsonant(*(source->pos+1))) {
|
|
|
|
if(source->isThai == TRUE) {
|
|
|
|
source->isThai = FALSE;
|
|
|
|
if((source->len - source->pos) > UCOL_WRITABLE_BUFFER_SIZE) {
|
|
|
|
// allocate a new buffer
|
|
|
|
}
|
|
|
|
UChar *sourceCopy = source->pos;
|
|
|
|
UChar *targetCopy = source->writableBuffer;
|
|
|
|
while(sourceCopy < source->len) {
|
|
|
|
if(isThaiPreVowel(*(sourceCopy)) &&
|
|
|
|
isThaiBaseConsonant(*(sourceCopy+1))) {
|
|
|
|
*(targetCopy) = *(sourceCopy+1);
|
|
|
|
*(targetCopy+1) = *(sourceCopy);
|
|
|
|
targetCopy+=2;
|
|
|
|
sourceCopy+=2;
|
|
|
|
} else {
|
|
|
|
*(targetCopy++) = *(sourceCopy++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
source->pos = source->writableBuffer;
|
|
|
|
source->len = targetCopy;
|
|
|
|
source->CEpos = source->toReturn = source->CEs;
|
|
|
|
return UCOL_IGNORABLE;
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
source->pos++;
|
2000-11-20 19:17:17 +00:00
|
|
|
return (*(source->toReturn++));
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
|
2000-11-20 19:17:17 +00:00
|
|
|
U_CAPI UCollationResult
|
2000-11-22 00:04:03 +00:00
|
|
|
ucol_strcollEx( const UCollator *coll,
|
2000-11-20 19:17:17 +00:00
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
|
|
|
if (coll == NULL) return UCOL_EQUAL;
|
|
|
|
if (sourceLength == -1) sourceLength = u_strlen(source);
|
|
|
|
if (targetLength == -1) targetLength = u_strlen(target);
|
2000-11-22 00:04:03 +00:00
|
|
|
return (UCollationResult) ((RuleBasedCollator*)coll)->compareEx(source,sourceLength,target,targetLength);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollationResult
|
2000-11-22 00:04:03 +00:00
|
|
|
ucol_strcoll( const UCollator *coll,
|
2000-11-20 19:17:17 +00:00
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
const UChar *target,
|
|
|
|
int32_t targetLength)
|
|
|
|
{
|
2000-11-29 04:48:39 +00:00
|
|
|
Collator *cppColl = (Collator*)coll;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
|
|
|
// check if source and target are valid strings
|
|
|
|
if (((source == 0) && (target == 0)) ||
|
|
|
|
((sourceLength == 0) && (targetLength == 0)))
|
|
|
|
{
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
UCollationResult result = UCOL_EQUAL;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
UChar normSource[UCOL_MAX_BUFFER], normTarget[UCOL_MAX_BUFFER];
|
|
|
|
uint32_t normSourceLength = UCOL_MAX_BUFFER, normTargetLength = UCOL_MAX_BUFFER;
|
|
|
|
|
|
|
|
collIterate sColl, tColl;
|
|
|
|
|
2000-11-29 04:48:39 +00:00
|
|
|
if(cppColl->getDecomposition() == Normalizer::NO_OP) {
|
2000-11-29 00:16:15 +00:00
|
|
|
init_collIterate(source, sourceLength, &sColl, FALSE);
|
|
|
|
init_collIterate(target, targetLength, &tColl, FALSE);
|
2000-11-20 19:17:17 +00:00
|
|
|
} else {
|
2000-11-29 04:48:39 +00:00
|
|
|
UNormalizationMode normMode = ucol_getNormalization(coll);
|
2000-11-20 19:17:17 +00:00
|
|
|
normSourceLength = u_normalize(source, sourceLength, normMode, 0, normSource, normSourceLength, &status);
|
|
|
|
normTargetLength = u_normalize(target, targetLength, normMode, 0, normTarget, normTargetLength, &status);
|
2000-11-29 00:16:15 +00:00
|
|
|
init_collIterate(normSource, normSourceLength, &sColl, TRUE);
|
|
|
|
init_collIterate(normTarget, normTargetLength, &tColl, TRUE);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (U_FAILURE(status))
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t sOrder, tOrder;
|
2000-11-29 00:16:15 +00:00
|
|
|
uint32_t pSOrder, pTOrder;
|
2000-11-20 19:17:17 +00:00
|
|
|
UBool gets = TRUE, gett = TRUE;
|
2000-11-29 04:48:39 +00:00
|
|
|
UBool initialCheckSecTer = cppColl->getStrength() >= UCOL_SECONDARY;
|
2000-11-20 19:17:17 +00:00
|
|
|
UBool checkSecTer = initialCheckSecTer;
|
2000-11-29 04:48:39 +00:00
|
|
|
UBool checkTertiary = cppColl->getStrength() >= UCOL_TERTIARY;
|
|
|
|
UBool checkQuad = cppColl->getStrength() >= UCOL_QUATERNARY;
|
|
|
|
UBool isFrenchSec = (cppColl->getAttribute(UCOL_FRENCH_COLLATION, status) == UCOL_ON) && checkSecTer;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if(!isFrenchSec) {
|
|
|
|
for(;;)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Get the next collation element in each of the strings, unless
|
|
|
|
// we've been requested to skip it.
|
|
|
|
if (gets)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
UCOL_getNextCE(sOrder, coll, &sColl, &status);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
gets = TRUE;
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (gett)
|
|
|
|
{
|
|
|
|
UCOL_getNextCE(tOrder, coll, &tColl, &status);
|
|
|
|
}
|
|
|
|
gett = TRUE;
|
|
|
|
|
|
|
|
// If we've hit the end of one of the strings, jump out of the loop
|
|
|
|
if ((sOrder == CollationElementIterator::NULLORDER)||
|
|
|
|
(tOrder == CollationElementIterator::NULLORDER)) {
|
|
|
|
break;
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// If there's no difference at this position, we can skip to the
|
|
|
|
// next one.
|
|
|
|
if (sOrder == tOrder)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// Compare primary differences first.
|
|
|
|
pSOrder = CollationElementIterator::primaryOrder(sOrder);
|
|
|
|
pTOrder = CollationElementIterator::primaryOrder(tOrder);
|
|
|
|
if (pSOrder != pTOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
if (sOrder == 0)
|
|
|
|
{
|
|
|
|
// The entire source element is ignorable.
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tOrder == 0)
|
|
|
|
{
|
|
|
|
gets = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The source and target elements aren't ignorable, but it's still possible
|
|
|
|
// for the primary component of one of the elements to be ignorable....
|
|
|
|
if (pSOrder == 0) // primary order in source is ignorable
|
|
|
|
{
|
|
|
|
// The source's primary is ignorable, but the target's isn't. We treat ignorables
|
|
|
|
// as a secondary difference, so remember that we found one.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER; // (strength is SECONDARY) - still need to check for tertiary or quad
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
}
|
|
|
|
else if (pTOrder == 0)
|
|
|
|
{
|
|
|
|
// record differences - see the comment above.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS; // (strength is SECONDARY) - still need to check for tertiary or quad
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
// Skip to the next target element, but don't fetch another source element.
|
|
|
|
gets = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Neither of the orders is ignorable, and we already know that the primary
|
|
|
|
// orders are different because of the (pSOrder != pTOrder) test above.
|
|
|
|
// Record the difference and stop the comparison.
|
|
|
|
if (pSOrder < pTOrder)
|
|
|
|
{
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
else
|
|
|
|
{ // else of if ( pSOrder != pTOrder )
|
|
|
|
// primary order is the same, but complete order is different. So there
|
|
|
|
// are no base elements at this point, only ignorables (Since the strings are
|
|
|
|
// normalized)
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
// a secondary or tertiary difference may still matter
|
|
|
|
uint32_t secSOrder = CollationElementIterator::secondaryOrder(sOrder);
|
|
|
|
uint32_t secTOrder = CollationElementIterator::secondaryOrder(tOrder);
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (secSOrder != secTOrder)
|
|
|
|
{
|
|
|
|
// there is a secondary difference
|
|
|
|
result = (secSOrder < secTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (checkTertiary)
|
|
|
|
{
|
|
|
|
// a tertiary difference may still matter
|
|
|
|
uint32_t terSOrder = CollationElementIterator::tertiaryOrder(sOrder);
|
|
|
|
uint32_t terTOrder = CollationElementIterator::tertiaryOrder(tOrder);
|
|
|
|
|
|
|
|
if (terSOrder != terTOrder)
|
|
|
|
{
|
|
|
|
// there is a tertiary difference
|
|
|
|
result = (terSOrder < terTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is TERTIARY)
|
|
|
|
checkTertiary = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if (checkSecTer)
|
|
|
|
|
|
|
|
} // if ( pSOrder != pTOrder )
|
|
|
|
} // while()
|
|
|
|
|
|
|
|
if (sOrder != CollationElementIterator::NULLORDER)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// (tOrder must be CollationElementIterator::NULLORDER,
|
|
|
|
// since this point is only reached when sOrder or tOrder is NULLORDER.)
|
|
|
|
// The source string has more elements, but the target string hasn't.
|
|
|
|
do
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
if (CollationElementIterator::primaryOrder(sOrder) != 0)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// We found an additional non-ignorable base character in the source string.
|
|
|
|
// This is a primary difference, so the source is greater
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
|
|
|
|
if (CollationElementIterator::secondaryOrder(sOrder) != 0)
|
|
|
|
{
|
|
|
|
// Additional secondary elements mean the source string is greater
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER; // (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UCOL_getNextCE(sOrder, coll, &sColl, &status);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
//while ((sOrder = ucol_getNextCE(coll, &sColl, &status)) != CollationElementIterator::NULLORDER);
|
|
|
|
while (sOrder != CollationElementIterator::NULLORDER);
|
|
|
|
}
|
|
|
|
else if (tOrder != CollationElementIterator::NULLORDER)
|
|
|
|
{
|
|
|
|
// The target string has more elements, but the source string hasn't.
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (CollationElementIterator::primaryOrder(tOrder) != 0)
|
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the target string.
|
|
|
|
// This is a primary difference, so the source is less
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (CollationElementIterator::secondaryOrder(tOrder) != 0)
|
|
|
|
{
|
|
|
|
// Additional secondary elements in the target mean the source string is less
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS; // (strength is SECONDARY)
|
|
|
|
checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UCOL_getNextCE(tOrder, coll, &tColl, &status);
|
|
|
|
}
|
|
|
|
while ( tOrder != CollationElementIterator::NULLORDER);
|
|
|
|
//while ((tOrder = ucol_getNextCE(coll, &tColl, &status)) != CollationElementIterator::NULLORDER);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
} else { //French
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// there is a bad situation with French when there is a different number of secondaries...
|
|
|
|
// If that situation arises (when one primary is ignorable with nonignorable secondary and the other primary is not
|
|
|
|
// ignorable
|
|
|
|
UBool bufferFrenchSec = FALSE;
|
|
|
|
uint32_t sourceFrenchSec[UCOL_MAX_BUFFER], targetFrenchSec[UCOL_MAX_BUFFER];
|
|
|
|
uint32_t *sFSBEnd = sourceFrenchSec+UCOL_MAX_BUFFER;
|
|
|
|
uint32_t *tFSBEnd = targetFrenchSec+UCOL_MAX_BUFFER;
|
|
|
|
|
|
|
|
for(;;)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Get the next collation element in each of the strings, unless
|
|
|
|
// we've been requested to skip it.
|
|
|
|
if (gets)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
UCOL_getNextCE(sOrder, coll, &sColl, &status);
|
|
|
|
*(--sFSBEnd) = CollationElementIterator::secondaryOrder(sOrder);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
gets = TRUE;
|
|
|
|
|
|
|
|
if (gett)
|
|
|
|
{
|
|
|
|
UCOL_getNextCE(tOrder, coll, &tColl, &status);
|
|
|
|
*(--tFSBEnd) = CollationElementIterator::secondaryOrder(tOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
gett = TRUE;
|
|
|
|
|
|
|
|
// If we've hit the end of one of the strings, jump out of the loop
|
|
|
|
if ((sOrder == CollationElementIterator::NULLORDER)||
|
|
|
|
(tOrder == CollationElementIterator::NULLORDER)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's no difference at this position, we can skip to the
|
|
|
|
// next one.
|
|
|
|
if (sOrder == tOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// Compare primary differences first.
|
|
|
|
pSOrder = CollationElementIterator::primaryOrder(sOrder);
|
|
|
|
pTOrder = CollationElementIterator::primaryOrder(tOrder);
|
|
|
|
if (pSOrder != pTOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
if (sOrder == 0)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// The entire source element is ignorable.
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
|
|
|
continue;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (tOrder == 0)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
gets = FALSE;
|
|
|
|
continue;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
// The source and target elements aren't ignorable, but it's still possible
|
|
|
|
// for the primary component of one of the elements to be ignorable....
|
|
|
|
if (pSOrder == 0) // primary order in source is ignorable
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// The source's primary is ignorable, but the target's isn't. We treat ignorables
|
|
|
|
// as a secondary difference, so remember that we found one.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
// Skip to the next source element, but don't fetch another target element.
|
|
|
|
gett = FALSE;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
else if (pTOrder == 0)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// record differences - see the comment above.
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
// Skip to the next target element, but don't fetch another source element.
|
|
|
|
gets = FALSE;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Neither of the orders is ignorable, and we already know that the primary
|
|
|
|
// orders are different because of the (pSOrder != pTOrder) test above.
|
|
|
|
// Record the difference and stop the comparison.
|
|
|
|
if (pSOrder < pTOrder)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // else of if ( pSOrder != pTOrder )
|
|
|
|
// primary order is the same, but complete order is different. So there
|
|
|
|
// are no base elements at this point, only ignorables (Since the strings are
|
|
|
|
// normalized)
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
// a secondary or tertiary difference may still matter
|
|
|
|
uint32_t secSOrder = CollationElementIterator::secondaryOrder(sOrder);
|
|
|
|
uint32_t secTOrder = CollationElementIterator::secondaryOrder(tOrder);
|
|
|
|
|
|
|
|
if (secSOrder != secTOrder)
|
|
|
|
{
|
|
|
|
// there is a secondary difference
|
|
|
|
result = (secSOrder < secTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is SECONDARY)
|
|
|
|
checkSecTer = isFrenchSec; // We still want to track the French secondaries
|
|
|
|
//checkSecTer = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (checkTertiary)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// a tertiary difference may still matter
|
|
|
|
uint32_t terSOrder = CollationElementIterator::tertiaryOrder(sOrder);
|
|
|
|
uint32_t terTOrder = CollationElementIterator::tertiaryOrder(tOrder);
|
|
|
|
|
|
|
|
if (terSOrder != terTOrder)
|
|
|
|
{
|
|
|
|
// there is a tertiary difference
|
|
|
|
result = (terSOrder < terTOrder) ? UCOL_LESS : UCOL_GREATER;
|
|
|
|
// (strength is TERTIARY)
|
|
|
|
checkTertiary = FALSE;
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
} // if (checkSecTer)
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
} // if ( pSOrder != pTOrder )
|
|
|
|
} // while()
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (sOrder != CollationElementIterator::NULLORDER)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// (tOrder must be CollationElementIterator::NULLORDER,
|
|
|
|
// since this point is only reached when sOrder or tOrder is NULLORDER.)
|
|
|
|
// The source string has more elements, but the target string hasn't.
|
|
|
|
do
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
if (CollationElementIterator::primaryOrder(sOrder) != 0)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// We found an additional non-ignorable base character in the source string.
|
|
|
|
// This is a primary difference, so the source is greater
|
|
|
|
return UCOL_GREATER; // (strength is PRIMARY)
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
|
|
|
|
if (CollationElementIterator::secondaryOrder(sOrder) != 0)
|
|
|
|
{
|
|
|
|
// Additional secondary elements mean the source string is greater
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UCOL_getNextCE(sOrder, coll, &sColl, &status);
|
|
|
|
*(--sFSBEnd) = CollationElementIterator::secondaryOrder(sOrder);
|
|
|
|
}
|
|
|
|
//while ((sOrder = ucol_getNextCE(coll, &sColl, &status)) != CollationElementIterator::NULLORDER);
|
|
|
|
while (sOrder != CollationElementIterator::NULLORDER);
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
else if (tOrder != CollationElementIterator::NULLORDER)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// The target string has more elements, but the source string hasn't.
|
|
|
|
do
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
if (CollationElementIterator::primaryOrder(tOrder) != 0)
|
|
|
|
{
|
|
|
|
// We found an additional non-ignorable base character in the target string.
|
|
|
|
// This is a primary difference, so the source is less
|
|
|
|
return UCOL_LESS; // (strength is PRIMARY)
|
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
if (CollationElementIterator::secondaryOrder(tOrder) != 0)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
2000-11-29 00:16:15 +00:00
|
|
|
// Additional secondary elements in the target mean the source string is less
|
|
|
|
if (checkSecTer)
|
|
|
|
{
|
|
|
|
bufferFrenchSec = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UCOL_getNextCE(tOrder, coll, &tColl, &status);
|
|
|
|
*(--tFSBEnd) = CollationElementIterator::secondaryOrder(tOrder);
|
|
|
|
}
|
|
|
|
while ( tOrder != CollationElementIterator::NULLORDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bufferFrenchSec) {
|
|
|
|
while(sFSBEnd < sourceFrenchSec+UCOL_MAX_BUFFER && tFSBEnd < targetFrenchSec+UCOL_MAX_BUFFER) {
|
|
|
|
if(*sFSBEnd == *tFSBEnd) {
|
|
|
|
sFSBEnd++;
|
|
|
|
tFSBEnd++;
|
|
|
|
} else if(*sFSBEnd < *tFSBEnd) {
|
|
|
|
result = UCOL_LESS;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
break;
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
}
|
2000-11-20 19:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// For IDENTICAL comparisons, we use a bitwise character comparison
|
|
|
|
// as a tiebreaker if all else is equal
|
|
|
|
// NOTE: The java code compares result with 0, and
|
|
|
|
// puts the result of the string comparison directly into result
|
2000-11-29 04:48:39 +00:00
|
|
|
if (result == UCOL_EQUAL && cppColl->getStrength() == UCOL_IDENTICAL)
|
2000-11-20 19:17:17 +00:00
|
|
|
{
|
|
|
|
UnicodeString sourceDecomp, targetDecomp;
|
|
|
|
|
|
|
|
int8_t comparison;
|
|
|
|
|
2000-11-27 04:14:36 +00:00
|
|
|
Normalizer::normalize(UnicodeString(source, sourceLength), ((RuleBasedCollator *)coll)->getDecomposition(),
|
2000-11-20 19:17:17 +00:00
|
|
|
0, sourceDecomp, status);
|
|
|
|
|
2000-11-27 04:14:36 +00:00
|
|
|
Normalizer::normalize(UnicodeString(target, targetLength), ((RuleBasedCollator *)coll)->getDecomposition(),
|
2000-11-20 19:17:17 +00:00
|
|
|
0, targetDecomp, status);
|
|
|
|
|
|
|
|
comparison = sourceDecomp.compare(targetDecomp);
|
|
|
|
|
|
|
|
if (comparison < 0)
|
|
|
|
{
|
|
|
|
result = UCOL_LESS;
|
|
|
|
}
|
|
|
|
else if (comparison == 0)
|
|
|
|
{
|
|
|
|
result = UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = UCOL_GREATER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t
|
2000-11-22 00:04:03 +00:00
|
|
|
ucol_getSortKeyEx(const UCollator *coll,
|
2000-11-20 19:17:17 +00:00
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t *result,
|
|
|
|
int32_t resultLength)
|
|
|
|
{
|
|
|
|
int32_t count;
|
|
|
|
const uint8_t* bytes = NULL;
|
|
|
|
CollationKey key;
|
|
|
|
int32_t copyLen;
|
|
|
|
int32_t len = (sourceLength == -1 ? u_strlen(source)
|
|
|
|
: sourceLength);
|
|
|
|
// UnicodeString string((UChar*)source, len, len);
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
2000-11-22 00:04:03 +00:00
|
|
|
((RuleBasedCollator*)coll)->getCollationKeyEx(source, len, key, status);
|
2000-11-20 19:17:17 +00:00
|
|
|
if(U_FAILURE(status))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bytes = key.getByteArray(count);
|
|
|
|
|
|
|
|
copyLen = uprv_min(count, resultLength);
|
|
|
|
uprv_arrayCopy((const int8_t*)bytes, (int8_t*)result, copyLen);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2000-11-07 00:00:17 +00:00
|
|
|
|
|
|
|
U_CAPI int32_t
|
2000-11-22 00:04:03 +00:00
|
|
|
ucol_getSortKey(const UCollator *coll,
|
2000-11-07 00:00:17 +00:00
|
|
|
const UChar *source,
|
|
|
|
int32_t sourceLength,
|
|
|
|
uint8_t *result,
|
|
|
|
int32_t resultLength)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
Still problems in:
|
|
|
|
SUMMARY:
|
|
|
|
******* [Total error count: 213]
|
|
|
|
Errors in
|
|
|
|
[tscoll/capitst/TestSortKey] // this is normal, since we are changing binary keys
|
|
|
|
[tscoll/cfrtst/TestSecondary] // this is also OK, ICU original implementation was messed up
|
|
|
|
[tscoll/cfrtst/TestTertiary] // probably the same as above
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t i = 0; // general purpose counter
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
uint8_t prim[2*UCOL_MAX_BUFFER], second[UCOL_MAX_BUFFER], tert[UCOL_MAX_BUFFER];
|
|
|
|
|
|
|
|
uint8_t *primaries = prim, *secondaries = second, *tertiaries = tert;
|
|
|
|
|
|
|
|
UChar normBuffer[2*UCOL_MAX_BUFFER];
|
|
|
|
UChar *normSource = normBuffer;
|
|
|
|
int32_t normSourceLen = 2048;
|
|
|
|
|
|
|
|
int32_t len = (sourceLength == -1 ? u_strlen(source) : sourceLength);
|
|
|
|
|
|
|
|
UBool compareSec = (((RuleBasedCollator *)coll)->getStrength() >= Collator::SECONDARY);
|
|
|
|
UBool compareTer = (((RuleBasedCollator *)coll)->getStrength() >= Collator::TERTIARY);
|
|
|
|
UBool compareIdent = (((RuleBasedCollator *)coll)->getStrength() == Collator::IDENTICAL);
|
|
|
|
|
|
|
|
if(len > UCOL_MAX_BUFFER) {
|
2000-11-20 19:17:17 +00:00
|
|
|
primaries = (uint8_t *)uprv_malloc(6*len*sizeof(uint8_t));
|
2000-11-07 00:00:17 +00:00
|
|
|
if(compareSec) {
|
|
|
|
secondaries = (uint8_t *)uprv_malloc(2*len*sizeof(uint8_t));
|
|
|
|
}
|
|
|
|
if(compareTer) {
|
|
|
|
tertiaries = (uint8_t *)uprv_malloc(2*len*sizeof(uint8_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *primstart = primaries;
|
|
|
|
uint8_t *secstart = secondaries;
|
|
|
|
uint8_t *terstart = tertiaries;
|
|
|
|
|
2000-11-20 19:17:17 +00:00
|
|
|
collIterate s;
|
2000-11-29 00:16:15 +00:00
|
|
|
init_collIterate((UChar *)source, len, &s, FALSE);
|
2000-11-07 00:00:17 +00:00
|
|
|
|
|
|
|
// If we need to normalize, we'll do it all at once at the beggining!
|
|
|
|
if(((RuleBasedCollator *)coll)->getDecomposition() != Normalizer::NO_OP) {
|
|
|
|
UnicodeString normalized;
|
|
|
|
Normalizer::normalize(UnicodeString(source, sourceLength), ((RuleBasedCollator *)coll)->getDecomposition(),
|
|
|
|
0, normalized, status);
|
|
|
|
normSourceLen = normalized.length();
|
|
|
|
|
|
|
|
if(normSourceLen > UCOL_MAX_BUFFER) {
|
|
|
|
normSource = (UChar *) uprv_malloc(normSourceLen*sizeof(UChar));
|
|
|
|
}
|
|
|
|
normalized.extract(0, normSourceLen, normSource);
|
2000-11-22 23:52:43 +00:00
|
|
|
normSource[normSourceLen] = 0;
|
2000-11-07 00:00:17 +00:00
|
|
|
s.string = normSource;
|
2000-11-20 19:17:17 +00:00
|
|
|
s.pos = normSource;
|
|
|
|
s.len = normSource+normSourceLen;
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t order = 0;
|
|
|
|
|
|
|
|
uint16_t primary = 0;
|
|
|
|
uint8_t secondary = 0;
|
|
|
|
uint8_t tertiary = 0;
|
|
|
|
|
2000-11-29 00:16:15 +00:00
|
|
|
UCOL_getNextCE(order, coll, &s, &status);
|
|
|
|
while(order != CollationElementIterator::NULLORDER) {
|
2000-11-07 00:00:17 +00:00
|
|
|
primary = ((order & UCOL_PRIMARYORDERMASK)>> UCOL_PRIMARYORDERSHIFT);
|
|
|
|
secondary = ((order & UCOL_SECONDARYORDERMASK)>> UCOL_SECONDARYORDERSHIFT);
|
|
|
|
tertiary = (order & UCOL_TERTIARYORDERMASK);
|
|
|
|
|
|
|
|
if(primary != UCOL_IGNORABLE) {
|
|
|
|
*(primaries++) = (primary+UCOL_SORTKEYOFFSET)>>8;
|
|
|
|
*(primaries++) = (primary+UCOL_SORTKEYOFFSET)&0xFF;
|
|
|
|
if(compareSec) {
|
|
|
|
*(secondaries++) = secondary+UCOL_SORTKEYOFFSET;
|
|
|
|
}
|
|
|
|
if(compareTer) {
|
|
|
|
*(tertiaries++) = tertiary+UCOL_SORTKEYOFFSET;
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
} else { // original implementation offsets this with some extra...
|
2000-11-07 00:00:17 +00:00
|
|
|
if(compareSec && secondary != 0) {
|
|
|
|
*(secondaries++) = secondary+UCOL_SORTKEYOFFSET;
|
|
|
|
}
|
|
|
|
if(compareTer && tertiary != 0) {
|
|
|
|
*(tertiaries++) = tertiary+UCOL_SORTKEYOFFSET;
|
|
|
|
}
|
|
|
|
}
|
2000-11-29 00:16:15 +00:00
|
|
|
UCOL_getNextCE(order, coll, &s, &status);
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
|
|
|
|
|
|
|
|
if(compareSec) {
|
|
|
|
uint32_t secsize = secondaries-secstart;
|
2000-11-29 00:16:15 +00:00
|
|
|
if(ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &status) == UCOL_ON) { // do the reverse copy
|
2000-11-07 00:00:17 +00:00
|
|
|
for(i = 0; i<secsize; i++) {
|
|
|
|
*(primaries++) = *(secondaries-i-1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uprv_memcpy(primaries, secstart, secsize);
|
|
|
|
primaries += secsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(compareTer) {
|
|
|
|
uint32_t tersize = tertiaries - terstart;
|
|
|
|
uprv_memcpy(primaries, terstart, tersize);
|
|
|
|
primaries += tersize;
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(compareIdent) {
|
2000-11-27 04:14:36 +00:00
|
|
|
UChar *ident = s.string;
|
|
|
|
while(ident < s.len) {
|
|
|
|
*(primaries++) = (*(ident) >> 8) + utf16fixup[*(ident) >> 11];
|
|
|
|
*(primaries++) = (*(ident) & 0xFF);
|
|
|
|
ident++;
|
2000-11-07 00:00:17 +00:00
|
|
|
}
|
|
|
|
*(primaries++) = UCOL_LEVELTERMINATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_memcpy(result, primstart, uprv_min(resultLength, (primaries-primstart)));
|
|
|
|
|
|
|
|
if(terstart != tert) {
|
|
|
|
uprv_free(terstart);
|
|
|
|
}
|
|
|
|
if(secstart != second) {
|
|
|
|
uprv_free(secstart);
|
|
|
|
}
|
|
|
|
if(primstart != prim) {
|
|
|
|
uprv_free(primstart);
|
|
|
|
}
|
|
|
|
if(normSource != normBuffer) {
|
|
|
|
uprv_free(normSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return primaries-primstart;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_keyHashCode( const uint8_t* key,
|
|
|
|
int32_t length)
|
|
|
|
{
|
|
|
|
CollationKey newKey(key, length);
|
|
|
|
return newKey.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
UCollationElements*
|
|
|
|
ucol_openElements( const UCollator *coll,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
int32_t len = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
|
|
|
|
CollationElementIterator *iter = 0;
|
|
|
|
iter = ((RuleBasedCollator*)coll)->createCollationElementIterator(src);
|
|
|
|
if(iter == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UCollationElements*) iter;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_closeElements(UCollationElements *elems)
|
|
|
|
{
|
|
|
|
delete (CollationElementIterator*)elems;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_reset(UCollationElements *elems)
|
|
|
|
{
|
|
|
|
((CollationElementIterator*)elems)->reset();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_next( UCollationElements *elems,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return UCOL_NULLORDER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return ((CollationElementIterator*)elems)->next(*status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_previous( UCollationElements *elems,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return UCOL_NULLORDER;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return ((CollationElementIterator*)elems)->previous(*status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getMaxExpansion( const UCollationElements *elems,
|
|
|
|
int32_t order)
|
|
|
|
{
|
|
|
|
return ((CollationElementIterator*)elems)->getMaxExpansion(order);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_setText(UCollationElements *elems,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
int32_t len = (textLength == -1 ? u_strlen(text) : textLength);
|
|
|
|
const UnicodeString src((UChar*)text, len, len);
|
|
|
|
|
|
|
|
((CollationElementIterator*)elems)->setText(src, *status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UTextOffset
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_getOffset(const UCollationElements *elems)
|
|
|
|
{
|
|
|
|
return ((CollationElementIterator*)elems)->getOffset();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_setOffset( UCollationElements *elems,
|
|
|
|
UTextOffset offset,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
((CollationElementIterator*)elems)->setOffset(offset, *status);
|
|
|
|
}
|
2000-05-15 19:48:26 +00:00
|
|
|
|
|
|
|
U_CAPI void
|
|
|
|
ucol_getVersion(const UCollator* coll,
|
|
|
|
UVersionInfo versionInfo)
|
|
|
|
{
|
|
|
|
((Collator*)coll)->getVersion(versionInfo);
|
|
|
|
}
|
2000-05-18 21:25:51 +00:00
|
|
|
|
|
|
|
U_CAPI uint8_t *
|
|
|
|
ucol_cloneRuleData(UCollator *coll, int32_t *length, UErrorCode *status)
|
|
|
|
{
|
|
|
|
return ((RuleBasedCollator*)coll)->cloneRuleData(*length,*status);
|
|
|
|
}
|
2000-11-17 23:32:32 +00:00
|
|
|
|
2000-11-20 06:40:54 +00:00
|
|
|
U_CAPI void ucol_setAttribute(UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status) {
|
2000-11-22 00:04:03 +00:00
|
|
|
((RuleBasedCollator *)coll)->setAttribute(attr, value, *status);
|
2000-11-17 23:32:32 +00:00
|
|
|
}
|
|
|
|
|
2000-11-20 06:40:54 +00:00
|
|
|
U_CAPI UColAttributeValue ucol_getAttribute(const UCollator *coll, UColAttribute attr, UErrorCode *status) {
|
2000-11-22 00:04:03 +00:00
|
|
|
return (((RuleBasedCollator *)coll)->getAttribute(attr, *status));
|
2000-11-17 23:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollator *ucol_safeClone(const UCollator *coll, void *stackBuffer, uint32_t bufferSize, UErrorCode *status) {
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UCollationResult ucol_strcollinc(const UCollator *coll,
|
|
|
|
UCharForwardIterator *source, void *sourceContext,
|
|
|
|
UCharForwardIterator *target, void *targetContext) {
|
|
|
|
return UCOL_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen) {
|
|
|
|
return 0;
|
|
|
|
}
|