2001-01-15 19:02:30 +00:00
|
|
|
/*
|
2001-02-20 00:26:50 +00:00
|
|
|
******************************************************************************
|
2014-02-25 21:21:49 +00:00
|
|
|
* Copyright (C) 2001-2014, International Business Machines
|
2001-01-15 19:02:30 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
2001-02-20 00:26:50 +00:00
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* File ucoleitr.cpp
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/15/2001 synwee Modified all methods to process its own function
|
|
|
|
* instead of calling the equivalent c++ api (coleitr.h)
|
2014-02-25 21:21:49 +00:00
|
|
|
* 2012-2014 markus Rewritten in C++ again.
|
2001-02-20 00:26:50 +00:00
|
|
|
******************************************************************************/
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_COLLATION
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
#include "unicode/coleitr.h"
|
|
|
|
#include "unicode/tblcoll.h"
|
2001-01-15 19:02:30 +00:00
|
|
|
#include "unicode/ucoleitr.h"
|
|
|
|
#include "unicode/ustring.h"
|
2001-11-14 22:24:17 +00:00
|
|
|
#include "unicode/sortkey.h"
|
2008-05-23 04:22:28 +00:00
|
|
|
#include "unicode/uobject.h"
|
2001-02-20 00:26:50 +00:00
|
|
|
#include "cmemory.h"
|
2014-02-25 21:21:49 +00:00
|
|
|
#include "usrchimp.h"
|
|
|
|
|
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
2001-02-20 00:26:50 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2001-04-12 00:08:26 +00:00
|
|
|
#define BUFFER_LENGTH 100
|
2001-02-20 00:26:50 +00:00
|
|
|
|
2008-05-23 04:22:28 +00:00
|
|
|
#define DEFAULT_BUFFER_SIZE 16
|
|
|
|
#define BUFFER_GROW 8
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
|
|
|
|
|
|
|
|
#define ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0])
|
|
|
|
|
|
|
|
#define NEW_ARRAY(type, count) (type *) uprv_malloc((count) * sizeof(type))
|
|
|
|
|
|
|
|
#define GROW_ARRAY(array, newSize) uprv_realloc((void *) (array), (newSize) * sizeof (array)[0])
|
|
|
|
|
|
|
|
#define DELETE_ARRAY(array) uprv_free((void *) (array))
|
|
|
|
|
|
|
|
struct RCEI
|
|
|
|
{
|
|
|
|
uint32_t ce;
|
|
|
|
int32_t low;
|
|
|
|
int32_t high;
|
|
|
|
};
|
|
|
|
|
2008-06-06 21:51:25 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2008-05-23 04:22:28 +00:00
|
|
|
struct RCEBuffer
|
|
|
|
{
|
|
|
|
RCEI defaultBuffer[DEFAULT_BUFFER_SIZE];
|
|
|
|
RCEI *buffer;
|
|
|
|
int32_t bufferIndex;
|
|
|
|
int32_t bufferSize;
|
|
|
|
|
|
|
|
RCEBuffer();
|
|
|
|
~RCEBuffer();
|
|
|
|
|
|
|
|
UBool empty() const;
|
|
|
|
void put(uint32_t ce, int32_t ixLow, int32_t ixHigh);
|
|
|
|
const RCEI *get();
|
|
|
|
};
|
|
|
|
|
|
|
|
RCEBuffer::RCEBuffer()
|
|
|
|
{
|
|
|
|
buffer = defaultBuffer;
|
|
|
|
bufferIndex = 0;
|
2014-02-25 21:21:49 +00:00
|
|
|
bufferSize = LENGTHOF(defaultBuffer);
|
2008-05-23 04:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCEBuffer::~RCEBuffer()
|
|
|
|
{
|
|
|
|
if (buffer != defaultBuffer) {
|
|
|
|
DELETE_ARRAY(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool RCEBuffer::empty() const
|
|
|
|
{
|
|
|
|
return bufferIndex <= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCEBuffer::put(uint32_t ce, int32_t ixLow, int32_t ixHigh)
|
|
|
|
{
|
|
|
|
if (bufferIndex >= bufferSize) {
|
|
|
|
RCEI *newBuffer = NEW_ARRAY(RCEI, bufferSize + BUFFER_GROW);
|
|
|
|
|
|
|
|
ARRAY_COPY(newBuffer, buffer, bufferSize);
|
|
|
|
|
|
|
|
if (buffer != defaultBuffer) {
|
|
|
|
DELETE_ARRAY(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = newBuffer;
|
|
|
|
bufferSize += BUFFER_GROW;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[bufferIndex].ce = ce;
|
|
|
|
buffer[bufferIndex].low = ixLow;
|
|
|
|
buffer[bufferIndex].high = ixHigh;
|
|
|
|
|
|
|
|
bufferIndex += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RCEI *RCEBuffer::get()
|
|
|
|
{
|
|
|
|
if (bufferIndex > 0) {
|
|
|
|
return &buffer[--bufferIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCEBuffer::PCEBuffer()
|
|
|
|
{
|
|
|
|
buffer = defaultBuffer;
|
|
|
|
bufferIndex = 0;
|
2014-02-25 21:21:49 +00:00
|
|
|
bufferSize = LENGTHOF(defaultBuffer);
|
2008-05-23 04:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PCEBuffer::~PCEBuffer()
|
|
|
|
{
|
|
|
|
if (buffer != defaultBuffer) {
|
|
|
|
DELETE_ARRAY(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCEBuffer::reset()
|
|
|
|
{
|
|
|
|
bufferIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool PCEBuffer::empty() const
|
|
|
|
{
|
|
|
|
return bufferIndex <= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCEBuffer::put(uint64_t ce, int32_t ixLow, int32_t ixHigh)
|
|
|
|
{
|
|
|
|
if (bufferIndex >= bufferSize) {
|
|
|
|
PCEI *newBuffer = NEW_ARRAY(PCEI, bufferSize + BUFFER_GROW);
|
|
|
|
|
|
|
|
ARRAY_COPY(newBuffer, buffer, bufferSize);
|
|
|
|
|
|
|
|
if (buffer != defaultBuffer) {
|
|
|
|
DELETE_ARRAY(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = newBuffer;
|
|
|
|
bufferSize += BUFFER_GROW;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[bufferIndex].ce = ce;
|
|
|
|
buffer[bufferIndex].low = ixLow;
|
|
|
|
buffer[bufferIndex].high = ixHigh;
|
|
|
|
|
|
|
|
bufferIndex += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PCEI *PCEBuffer::get()
|
|
|
|
{
|
|
|
|
if (bufferIndex > 0) {
|
|
|
|
return &buffer[--bufferIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
UCollationPCE::UCollationPCE(UCollationElements *elems) { init(elems); }
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
UCollationPCE::UCollationPCE(CollationElementIterator *iter) { init(iter); }
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
void UCollationPCE::init(UCollationElements *elems) {
|
|
|
|
init(CollationElementIterator::fromUCollationElements(elems));
|
|
|
|
}
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
void UCollationPCE::init(CollationElementIterator *iter)
|
2008-05-23 04:22:28 +00:00
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
cei = iter;
|
|
|
|
init(*iter->rbc_);
|
2008-05-23 04:22:28 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
void UCollationPCE::init(const Collator &coll)
|
2008-05-23 04:22:28 +00:00
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
strength = coll.getAttribute(UCOL_STRENGTH, status);
|
|
|
|
toShift = coll.getAttribute(UCOL_ALTERNATE_HANDLING, status) == UCOL_SHIFTED;
|
2008-05-23 04:22:28 +00:00
|
|
|
isShifted = FALSE;
|
2014-02-25 21:21:49 +00:00
|
|
|
variableTop = coll.getVariableTop(status);
|
2008-05-23 04:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UCollationPCE::~UCollationPCE()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
uint64_t UCollationPCE::processCE(uint32_t ce)
|
2008-05-23 04:22:28 +00:00
|
|
|
{
|
|
|
|
uint64_t primary = 0, secondary = 0, tertiary = 0, quaternary = 0;
|
|
|
|
|
|
|
|
// This is clean, but somewhat slow...
|
|
|
|
// We could apply the mask to ce and then
|
|
|
|
// just get all three orders...
|
2014-02-25 21:21:49 +00:00
|
|
|
switch(strength) {
|
2008-05-23 04:22:28 +00:00
|
|
|
default:
|
|
|
|
tertiary = ucol_tertiaryOrder(ce);
|
|
|
|
/* note fall-through */
|
|
|
|
|
|
|
|
case UCOL_SECONDARY:
|
|
|
|
secondary = ucol_secondaryOrder(ce);
|
|
|
|
/* note fall-through */
|
|
|
|
|
|
|
|
case UCOL_PRIMARY:
|
|
|
|
primary = ucol_primaryOrder(ce);
|
|
|
|
}
|
|
|
|
|
2009-01-22 00:24:48 +00:00
|
|
|
// **** This should probably handle continuations too. ****
|
|
|
|
// **** That means that we need 24 bits for the primary ****
|
|
|
|
// **** instead of the 16 that we're currently using. ****
|
|
|
|
// **** So we can lay out the 64 bits as: 24.12.12.16. ****
|
|
|
|
// **** Another complication with continuations is that ****
|
|
|
|
// **** the *second* CE is marked as a continuation, so ****
|
|
|
|
// **** we always have to peek ahead to know how long ****
|
|
|
|
// **** the primary is... ****
|
2014-02-25 21:21:49 +00:00
|
|
|
if ((toShift && variableTop > ce && primary != 0)
|
|
|
|
|| (isShifted && primary == 0)) {
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
if (primary == 0) {
|
|
|
|
return UCOL_IGNORABLE;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
if (strength >= UCOL_QUATERNARY) {
|
2008-05-23 04:22:28 +00:00
|
|
|
quaternary = primary;
|
|
|
|
}
|
|
|
|
|
|
|
|
primary = secondary = tertiary = 0;
|
2014-02-25 21:21:49 +00:00
|
|
|
isShifted = TRUE;
|
2008-05-23 04:22:28 +00:00
|
|
|
} else {
|
2014-02-25 21:21:49 +00:00
|
|
|
if (strength >= UCOL_QUATERNARY) {
|
2008-05-23 04:22:28 +00:00
|
|
|
quaternary = 0xFFFF;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
isShifted = FALSE;
|
2008-05-23 04:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return primary << 48 | secondary << 32 | tertiary << 16 | quaternary;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
U_NAMESPACE_END
|
2008-06-06 21:51:25 +00:00
|
|
|
|
2001-02-20 00:26:50 +00:00
|
|
|
/* public methods ---------------------------------------------------- */
|
2001-01-15 19:02:30 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UCollationElements* U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_openElements(const UCollator *coll,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2008-02-10 20:17:14 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-25 21:21:49 +00:00
|
|
|
if (coll == NULL || (text == NULL && textLength != 0)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
const RuleBasedCollator *rbc = RuleBasedCollator::rbcFromUCollator(coll);
|
|
|
|
if (rbc == NULL) {
|
|
|
|
*status = U_UNSUPPORTED_ERROR; // coll is a Collator but not a RuleBasedCollator
|
2008-02-10 20:17:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-06 23:50:03 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
UnicodeString s((UBool)(textLength < 0), text, textLength);
|
|
|
|
CollationElementIterator *cei = rbc->createCollationElementIterator(s);
|
|
|
|
if (cei == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
2008-02-10 20:17:14 +00:00
|
|
|
}
|
2001-02-20 00:26:50 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
return cei->toUCollationElements();
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 00:24:48 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-01-15 19:02:30 +00:00
|
|
|
ucol_closeElements(UCollationElements *elems)
|
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
delete CollationElementIterator::fromUCollationElements(elems);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-01-15 19:02:30 +00:00
|
|
|
ucol_reset(UCollationElements *elems)
|
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
CollationElementIterator::fromUCollationElements(elems)->reset();
|
2009-01-22 00:24:48 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-04-26 01:15:34 +00:00
|
|
|
ucol_next(UCollationElements *elems,
|
2001-02-20 00:26:50 +00:00
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2008-02-10 20:17:14 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return UCOL_NULLORDER;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
return CollationElementIterator::fromUCollationElements(elems)->next(*status);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
UCollationPCE::nextProcessed(
|
2008-05-23 04:22:28 +00:00
|
|
|
int32_t *ixLow,
|
|
|
|
int32_t *ixHigh,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
int64_t result = UCOL_IGNORABLE;
|
|
|
|
uint32_t low = 0, high = 0;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return UCOL_PROCESSED_NULLORDER;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
pceBuffer.reset();
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
do {
|
2014-02-25 21:21:49 +00:00
|
|
|
low = cei->getOffset();
|
|
|
|
int32_t ce = cei->next(*status);
|
|
|
|
high = cei->getOffset();
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
if (ce == UCOL_NULLORDER) {
|
2008-05-23 04:22:28 +00:00
|
|
|
result = UCOL_PROCESSED_NULLORDER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
result = processCE((uint32_t)ce);
|
2008-05-23 04:22:28 +00:00
|
|
|
} while (result == UCOL_IGNORABLE);
|
|
|
|
|
|
|
|
if (ixLow != NULL) {
|
|
|
|
*ixLow = low;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ixHigh != NULL) {
|
|
|
|
*ixHigh = high;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_previous(UCollationElements *elems,
|
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2008-02-10 20:17:14 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return UCOL_NULLORDER;
|
2001-04-12 00:08:26 +00:00
|
|
|
}
|
2014-02-25 21:21:49 +00:00
|
|
|
return CollationElementIterator::fromUCollationElements(elems)->previous(*status);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
UCollationPCE::previousProcessed(
|
2008-05-23 04:22:28 +00:00
|
|
|
int32_t *ixLow,
|
|
|
|
int32_t *ixHigh,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
int64_t result = UCOL_IGNORABLE;
|
2008-05-26 19:18:33 +00:00
|
|
|
int32_t low = 0, high = 0;
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return UCOL_PROCESSED_NULLORDER;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
// pceBuffer.reset();
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
while (pceBuffer.empty()) {
|
2008-05-23 04:22:28 +00:00
|
|
|
// buffer raw CEs up to non-ignorable primary
|
|
|
|
RCEBuffer rceb;
|
2014-02-25 21:21:49 +00:00
|
|
|
int32_t ce;
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
// **** do we need to reset rceb, or will it always be empty at this point ****
|
|
|
|
do {
|
2014-02-25 21:21:49 +00:00
|
|
|
high = cei->getOffset();
|
|
|
|
ce = cei->previous(*status);
|
|
|
|
low = cei->getOffset();
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
if (ce == UCOL_NULLORDER) {
|
2008-05-23 04:22:28 +00:00
|
|
|
if (! rceb.empty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
rceb.put((uint32_t)ce, low, high);
|
|
|
|
} while ((ce & UCOL_PRIMARYORDERMASK) == 0 || isContinuation(ce));
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
// process the raw CEs
|
|
|
|
while (! rceb.empty()) {
|
|
|
|
const RCEI *rcei = rceb.get();
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
result = processCE(rcei->ce);
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
if (result != UCOL_IGNORABLE) {
|
2014-02-25 21:21:49 +00:00
|
|
|
pceBuffer.put(result, rcei->low, rcei->high);
|
2008-05-23 04:22:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
2014-02-25 21:21:49 +00:00
|
|
|
if (pceBuffer.empty()) {
|
2008-05-23 04:22:28 +00:00
|
|
|
// **** Is -1 the right value for ixLow, ixHigh? ****
|
|
|
|
if (ixLow != NULL) {
|
|
|
|
*ixLow = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ixHigh != NULL) {
|
|
|
|
*ixHigh = -1
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return UCOL_PROCESSED_NULLORDER;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
const PCEI *pcei = pceBuffer.get();
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
if (ixLow != NULL) {
|
|
|
|
*ixLow = pcei->low;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ixHigh != NULL) {
|
|
|
|
*ixHigh = pcei->high;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pcei->ce;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_getMaxExpansion(const UCollationElements *elems,
|
|
|
|
int32_t order)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
return CollationElementIterator::fromUCollationElements(elems)->getMaxExpansion(order);
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
// TODO: The old code masked the order according to strength and then did a binary search.
|
|
|
|
// However this was probably at least partially broken because of the following comment.
|
|
|
|
// Still, it might have found a match when this version may not.
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
// FIXME: with a masked search, there might be more than one hit,
|
|
|
|
// so we need to look forward and backward from the match to find all
|
|
|
|
// of the hits...
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
2014-02-25 21:21:49 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_setText( UCollationElements *elems,
|
|
|
|
const UChar *text,
|
|
|
|
int32_t textLength,
|
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2008-02-10 20:17:14 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-06-20 18:14:51 +00:00
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
if ((text == NULL && textLength != 0)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
2010-03-12 20:08:20 +00:00
|
|
|
}
|
2014-02-25 21:21:49 +00:00
|
|
|
UnicodeString s((UBool)(textLength < 0), text, textLength);
|
|
|
|
return CollationElementIterator::fromUCollationElements(elems)->setText(s, *status);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-01-15 19:02:30 +00:00
|
|
|
ucol_getOffset(const UCollationElements *elems)
|
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
return CollationElementIterator::fromUCollationElements(elems)->getOffset();
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-02-20 00:26:50 +00:00
|
|
|
ucol_setOffset(UCollationElements *elems,
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t offset,
|
2001-02-20 00:26:50 +00:00
|
|
|
UErrorCode *status)
|
2001-01-15 19:02:30 +00:00
|
|
|
{
|
2008-02-10 20:17:14 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:21:49 +00:00
|
|
|
CollationElementIterator::fromUCollationElements(elems)->setOffset(offset, *status);
|
2001-01-15 19:02:30 +00:00
|
|
|
}
|
|
|
|
|
2003-04-23 04:47:00 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucol_primaryOrder (int32_t order)
|
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
return (order >> 16) & 0xffff;
|
2003-04-23 04:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucol_secondaryOrder (int32_t order)
|
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
return (order >> 8) & 0xff;
|
2003-04-23 04:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ucol_tertiaryOrder (int32_t order)
|
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
return order & 0xff;
|
2009-03-27 00:37:55 +00:00
|
|
|
}
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_COLLATION */
|