1999-08-16 21:50:52 +00:00
|
|
|
|
/*
|
2001-01-18 00:23:29 +00:00
|
|
|
|
******************************************************************************
|
2001-01-30 18:52:58 +00:00
|
|
|
|
* Copyright <EFBFBD> {1996-2001}, International Business Machines Corporation and *
|
2001-01-18 00:23:29 +00:00
|
|
|
|
* others. All Rights Reserved. *
|
|
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
2001-01-30 18:52:58 +00:00
|
|
|
|
* File tblcoll.cpp
|
|
|
|
|
*
|
|
|
|
|
* Created by: Helena Shih
|
|
|
|
|
*
|
|
|
|
|
* Modification History:
|
|
|
|
|
*
|
|
|
|
|
* Date Name Description
|
|
|
|
|
* 2/5/97 aliu Added streamIn and streamOut methods. Added
|
|
|
|
|
* constructor which reads RuleBasedCollator object from
|
|
|
|
|
* a binary file. Added writeToFile method which streams
|
|
|
|
|
* RuleBasedCollator out to a binary file. The streamIn
|
|
|
|
|
* and streamOut methods use istream and ostream objects
|
|
|
|
|
* in binary mode.
|
|
|
|
|
* 2/11/97 aliu Moved declarations out of for loop initializer.
|
|
|
|
|
* Added Mac compatibility #ifdef for ios::nocreate.
|
|
|
|
|
* 2/12/97 aliu Modified to use TableCollationData sub-object to
|
|
|
|
|
* hold invariant data.
|
|
|
|
|
* 2/13/97 aliu Moved several methods into this class from Collation.
|
|
|
|
|
* Added a private RuleBasedCollator(Locale&) constructor,
|
|
|
|
|
* to be used by Collator::getInstance(). General
|
|
|
|
|
* clean up. Made use of UErrorCode variables consistent.
|
|
|
|
|
* 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
|
|
|
|
|
* constructor and getDynamicClassID.
|
|
|
|
|
* 3/5/97 aliu Changed compaction cycle to improve performance. We
|
|
|
|
|
* use the maximum allowable value which is kBlockCount.
|
|
|
|
|
* Modified getRules() to load rules dynamically. Changed
|
|
|
|
|
* constructFromFile() call to accomodate this (added
|
|
|
|
|
* parameter to specify whether binary loading is to
|
|
|
|
|
* take place).
|
|
|
|
|
* 05/06/97 helena Added memory allocation error check.
|
|
|
|
|
* 6/20/97 helena Java class name change.
|
|
|
|
|
* 6/23/97 helena Adding comments to make code more readable.
|
|
|
|
|
* 09/03/97 helena Added createCollationKeyValues().
|
|
|
|
|
* 06/26/98 erm Changes for CollationKeys using byte arrays.
|
|
|
|
|
* 08/10/98 erm Synched with 1.2 version of RuleBasedCollator.java
|
|
|
|
|
* 04/23/99 stephen Removed EDecompositionMode, merged with
|
|
|
|
|
* Normalizer::EMode
|
|
|
|
|
* 06/14/99 stephen Removed kResourceBundleSuffix
|
|
|
|
|
* 06/22/99 stephen Fixed logic in constructFromFile() since .ctx
|
|
|
|
|
* files are no longer used.
|
|
|
|
|
* 11/02/99 helena Collator performance enhancements. Special case
|
|
|
|
|
* for NO_OP situations.
|
|
|
|
|
* 11/17/99 srl More performance enhancements. Inlined some internal functions.
|
|
|
|
|
* 12/15/99 aliu Update to support Thai collation. Move NormalizerIterator
|
|
|
|
|
* to implementation file.
|
|
|
|
|
* 01/29/01 synwee Modified into a C++ wrapper calling C APIs (ucol.h)
|
2001-01-18 00:23:29 +00:00
|
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2000-12-12 01:15:30 +00:00
|
|
|
|
#include "ucolimp.h"
|
2000-12-14 01:11:11 +00:00
|
|
|
|
#include "unicode/tblcoll.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
|
#include "unicode/coleitr.h"
|
2001-02-21 01:59:39 +00:00
|
|
|
|
#include "uhash.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
|
#include "unicode/resbund.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2001-01-18 00:23:29 +00:00
|
|
|
|
#include "unistrm.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* forward declarations ----------------------------------------------------- */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UChar forwardCharIteratorGlue(void *iterator);
|
1999-11-23 22:49:29 +00:00
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* global variable ---------------------------------------------------------- */
|
2000-06-03 04:37:12 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/*
|
|
|
|
|
synwee : using another name for this
|
2000-11-22 00:04:03 +00:00
|
|
|
|
const uint32_t tblcoll_StackBufferLen = 1024;
|
2001-01-18 00:23:29 +00:00
|
|
|
|
*/
|
|
|
|
|
const uint32_t StackBufferLen = 1024;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* RuleBasedCollator declaration ----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------
|
|
|
|
|
The following diagram shows the data structure of the RuleBasedCollator object.
|
|
|
|
|
Suppose we have the rule, where 'o-umlaut' is the unicode char 0x00F6.
|
|
|
|
|
"a, A < b, B < c, C, ch, cH, Ch, CH < d, D ... < o, O;
|
|
|
|
|
'o-umlaut'/E, 'O-umlaut'/E ...".
|
|
|
|
|
What the rule says is, sorts 'ch'ligatures and 'c' only with tertiary
|
|
|
|
|
difference and sorts 'o-umlaut' as if it's always expanded with 'e'.
|
|
|
|
|
|
|
|
|
|
mapping table contracting list expanding list
|
|
|
|
|
(contains all unicode
|
|
|
|
|
char entries) ___ ____________ _________________________
|
|
|
|
|
________ |=>|_*_|->|'c' |v('c') | |=>|v('o')|v('umlaut')|v('e')|
|
|
|
|
|
|_\u0001_|-> v('\u0001') | |_:_| |------------| | |-------------------------|
|
|
|
|
|
|_\u0002_|-> v('\u0002') | |_:_| |'ch'|v('ch')| | | : |
|
|
|
|
|
|____:___| | |_:_| |------------| | |-------------------------|
|
|
|
|
|
|____:___| | |'cH'|v('cH')| | | : |
|
|
|
|
|
|__'a'___|-> v('a') | |------------| | |-------------------------|
|
|
|
|
|
|__'b'___|-> v('b') | |'Ch'|v('Ch')| | | : |
|
|
|
|
|
|____:___| | |------------| | |-------------------------|
|
|
|
|
|
|____:___| | |'CH'|v('CH')| | | : |
|
|
|
|
|
|___'c'__|---------------- ------------ | |-------------------------|
|
|
|
|
|
|____:___| | | : |
|
|
|
|
|
|o-umlaut|---------------------------------------- |_________________________|
|
|
|
|
|
|____:___|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/* public RuleBasedCollator constructor ---------------------------------- */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Copy constructor
|
1999-12-16 01:41:19 +00:00
|
|
|
|
*/
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator(const RuleBasedCollator& that) :
|
2001-01-30 18:52:58 +00:00
|
|
|
|
Collator(that), dataIsOwned(FALSE), ucollator(that.ucollator),
|
|
|
|
|
urulestring(that.urulestring)
|
1999-12-16 01:41:19 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
|
|
|
|
|
UErrorCode& status) :
|
|
|
|
|
dataIsOwned(FALSE)
|
1999-12-16 01:41:19 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int32_t length = rules.length();
|
1999-12-16 01:41:19 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UChar ucharrules[StackBufferLen];
|
|
|
|
|
UChar *pucharrules = ucharrules;
|
|
|
|
|
|
|
|
|
|
if (length >= StackBufferLen)
|
|
|
|
|
pucharrules = new UChar[length + 1];
|
|
|
|
|
|
|
|
|
|
rules.extract(0, length, pucharrules);
|
|
|
|
|
pucharrules[length] = 0;
|
1999-12-16 01:41:19 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
ucollator = ucol_openRules(pucharrules, length, UCOL_DEFAULT_NORMALIZATION,
|
|
|
|
|
UCOL_DEFAULT_STRENGTH, &status);
|
2001-01-30 18:52:58 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_SUCCESS(status))
|
2001-01-30 18:52:58 +00:00
|
|
|
|
{
|
|
|
|
|
const UChar *r = ucol_getRules(ucollator, &length);
|
|
|
|
|
urulestring = new UnicodeString(r, length);
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
dataIsOwned = TRUE;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
}
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
if (pucharrules != ucharrules)
|
|
|
|
|
delete[] pucharrules;
|
1999-12-16 01:41:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
|
|
|
|
|
ECollationStrength collationStrength,
|
|
|
|
|
UErrorCode& status) : dataIsOwned(FALSE)
|
1999-12-16 01:41:19 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int32_t length = rules.length();
|
1999-12-16 01:41:19 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UChar ucharrules[StackBufferLen];
|
|
|
|
|
UChar *pucharrules = ucharrules;
|
|
|
|
|
|
|
|
|
|
if (length >= StackBufferLen)
|
|
|
|
|
pucharrules = new UChar[length + 1];
|
|
|
|
|
|
|
|
|
|
rules.extract(0, length, pucharrules);
|
|
|
|
|
pucharrules[length] = 0;
|
1999-12-16 01:41:19 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UCollationStrength strength = getUCollationStrength(collationStrength);
|
|
|
|
|
ucollator = ucol_openRules(pucharrules, length, UCOL_DEFAULT_NORMALIZATION,
|
|
|
|
|
strength, &status);
|
|
|
|
|
|
|
|
|
|
if (U_SUCCESS(status))
|
2001-01-30 18:52:58 +00:00
|
|
|
|
{
|
|
|
|
|
const UChar *r = ucol_getRules(ucollator, &length);
|
|
|
|
|
urulestring = new UnicodeString(r, length);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
dataIsOwned = TRUE;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
}
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
if (pucharrules != ucharrules)
|
|
|
|
|
delete[] pucharrules;
|
1999-12-16 01:41:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
|
|
|
|
|
Normalizer::EMode decompositionMode,
|
|
|
|
|
UErrorCode& status) :
|
|
|
|
|
dataIsOwned(FALSE)
|
1999-12-16 01:41:19 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int32_t length = rules.length();
|
1999-12-16 01:41:19 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UChar ucharrules[StackBufferLen];
|
|
|
|
|
UChar *pucharrules = ucharrules;
|
|
|
|
|
|
|
|
|
|
if (length >= StackBufferLen)
|
|
|
|
|
pucharrules = new UChar[length + 1];
|
|
|
|
|
|
|
|
|
|
rules.extract(0, length, pucharrules);
|
|
|
|
|
pucharrules[length] = 0;
|
1999-12-16 01:41:19 +00:00
|
|
|
|
|
2001-02-03 01:27:02 +00:00
|
|
|
|
UNormalizationMode mode = Normalizer::getUNormalizationMode(
|
|
|
|
|
decompositionMode, status);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
ucollator = ucol_openRules(pucharrules, length, mode,
|
|
|
|
|
UCOL_DEFAULT_STRENGTH, &status);
|
1999-12-16 01:41:19 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_SUCCESS(status))
|
2001-01-30 18:52:58 +00:00
|
|
|
|
{
|
|
|
|
|
const UChar *r = ucol_getRules(ucollator, &length);
|
|
|
|
|
urulestring = new UnicodeString(r, length);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
dataIsOwned = TRUE;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
}
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
if (pucharrules != ucharrules)
|
|
|
|
|
delete[] pucharrules;
|
1999-12-16 01:41:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
|
|
|
|
|
ECollationStrength collationStrength,
|
|
|
|
|
Normalizer::EMode decompositionMode,
|
|
|
|
|
UErrorCode& status) : dataIsOwned(FALSE)
|
1999-12-16 01:41:19 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
2000-01-13 21:36:39 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
int32_t length = rules.length();
|
2000-01-13 21:36:39 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UChar ucharrules[StackBufferLen];
|
|
|
|
|
UChar *pucharrules = ucharrules;
|
|
|
|
|
|
|
|
|
|
if (length >= StackBufferLen)
|
|
|
|
|
pucharrules = new UChar[length + 1];
|
|
|
|
|
|
|
|
|
|
rules.extract(0, length, pucharrules);
|
|
|
|
|
pucharrules[length] = 0;
|
|
|
|
|
|
|
|
|
|
UCollationStrength strength = getUCollationStrength(collationStrength);
|
2001-02-03 01:27:02 +00:00
|
|
|
|
UNormalizationMode mode = Normalizer::getUNormalizationMode(
|
|
|
|
|
decompositionMode, status);
|
2001-01-30 18:52:58 +00:00
|
|
|
|
ucollator = ucol_openRules(pucharrules, length, mode, strength, &status);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_SUCCESS(status))
|
2001-01-30 18:52:58 +00:00
|
|
|
|
{
|
|
|
|
|
const UChar *r = ucol_getRules(ucollator, &length);
|
|
|
|
|
urulestring = new UnicodeString(r, length);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
dataIsOwned = TRUE;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
}
|
2000-01-13 21:36:39 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (pucharrules != ucharrules)
|
|
|
|
|
delete[] pucharrules;
|
2000-01-13 21:36:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* RuleBasedCollator public destructor ----------------------------------- */
|
2000-01-13 21:36:39 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::~RuleBasedCollator()
|
1999-11-23 22:49:29 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (dataIsOwned)
|
|
|
|
|
{
|
|
|
|
|
ucol_close(ucollator);
|
2001-01-30 18:52:58 +00:00
|
|
|
|
delete urulestring;
|
2001-01-18 00:23:29 +00:00
|
|
|
|
}
|
2001-01-30 18:52:58 +00:00
|
|
|
|
ucollator = NULL;
|
1999-11-23 22:49:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* RuleBaseCollator public methods --------------------------------------- */
|
1999-11-23 22:49:29 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UBool RuleBasedCollator::operator==(const Collator& that) const
|
1999-11-23 22:49:29 +00:00
|
|
|
|
{
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* only checks for address equals here */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (Collator::operator==(that))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (getDynamicClassID() != that.getDynamicClassID())
|
2001-02-15 19:30:25 +00:00
|
|
|
|
return FALSE; /* not the same class */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
RuleBasedCollator& thatAlias = (RuleBasedCollator&)that;
|
1999-11-23 22:49:29 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/*
|
|
|
|
|
synwee : orginal code does not check for data compatibility
|
|
|
|
|
*/
|
|
|
|
|
if (ucollator != thatAlias.ucollator)
|
|
|
|
|
return FALSE;
|
1999-11-23 22:49:29 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
1999-11-23 22:49:29 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator& RuleBasedCollator::operator=(
|
|
|
|
|
const RuleBasedCollator& that)
|
|
|
|
|
{
|
|
|
|
|
if (this != &that)
|
|
|
|
|
{
|
|
|
|
|
if (dataIsOwned)
|
1999-11-23 22:49:29 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
ucol_close(ucollator);
|
|
|
|
|
ucollator = NULL;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
delete urulestring;
|
1999-11-23 22:49:29 +00:00
|
|
|
|
}
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
dataIsOwned = FALSE;
|
|
|
|
|
ucollator = that.ucollator;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
urulestring = that.urulestring;
|
2001-01-18 00:23:29 +00:00
|
|
|
|
}
|
|
|
|
|
return *this;
|
1999-11-23 22:49:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
Collator* RuleBasedCollator::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new RuleBasedCollator(*this);
|
|
|
|
|
}
|
1999-11-23 22:49:29 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Create a CollationElementIterator object that will iterator over the
|
|
|
|
|
* elements in a string, using the collation rules defined in this
|
|
|
|
|
* RuleBasedCollator
|
|
|
|
|
*/
|
|
|
|
|
CollationElementIterator* RuleBasedCollator::createCollationElementIterator
|
|
|
|
|
(const UnicodeString& source) const
|
|
|
|
|
{
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
CollationElementIterator *result = new CollationElementIterator(source, this,
|
|
|
|
|
status);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2001-01-30 18:52:58 +00:00
|
|
|
|
return result;
|
2000-12-07 07:22:55 +00:00
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Create a CollationElementIterator object that will iterator over the
|
|
|
|
|
* elements in a string, using the collation rules defined in this
|
|
|
|
|
* RuleBasedCollator
|
|
|
|
|
*/
|
|
|
|
|
CollationElementIterator* RuleBasedCollator::createCollationElementIterator
|
|
|
|
|
(const CharacterIterator& source) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
CollationElementIterator *result = new CollationElementIterator(source, this,
|
|
|
|
|
status);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2001-01-30 18:52:58 +00:00
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return a string representation of this collator's rules. The string can
|
|
|
|
|
* later be passed to the constructor that takes a UnicodeString argument,
|
|
|
|
|
* which will construct a collator that's functionally identical to this one.
|
|
|
|
|
* You can also allow users to edit the string in order to change the collation
|
|
|
|
|
* data, or you can print it out for inspection, or whatever.
|
|
|
|
|
*/
|
|
|
|
|
const UnicodeString& RuleBasedCollator::getRules() const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-30 18:52:58 +00:00
|
|
|
|
return (*urulestring);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
Collator::EComparisonResult RuleBasedCollator::compare(
|
|
|
|
|
const UnicodeString& source,
|
|
|
|
|
const UnicodeString& target,
|
|
|
|
|
int32_t length) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UnicodeString source_togo;
|
|
|
|
|
UnicodeString target_togo;
|
|
|
|
|
UTextOffset begin=0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
source.extract(begin, uprv_min(length,source.length()), source_togo);
|
|
|
|
|
target.extract(begin, uprv_min(length,target.length()), target_togo);
|
|
|
|
|
return compare(source_togo, target_togo);
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
Collator::EComparisonResult RuleBasedCollator::compare(const UChar* source,
|
|
|
|
|
int32_t sourceLength,
|
|
|
|
|
const UChar* target,
|
|
|
|
|
int32_t targetLength)
|
|
|
|
|
const
|
|
|
|
|
{
|
|
|
|
|
return getEComparisonResult(ucol_strcoll(ucollator, source, sourceLength,
|
|
|
|
|
target, targetLength));
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Compare two strings using this collator
|
|
|
|
|
*/
|
|
|
|
|
Collator::EComparisonResult RuleBasedCollator::compare(
|
|
|
|
|
const UnicodeString& source,
|
|
|
|
|
const UnicodeString& target) const
|
|
|
|
|
{
|
|
|
|
|
UChar uSstart[StackBufferLen];
|
|
|
|
|
UChar uTstart[StackBufferLen];
|
|
|
|
|
UChar *uSource = uSstart;
|
|
|
|
|
UChar *uTarget = uTstart;
|
|
|
|
|
uint32_t sourceLen = source.length();
|
|
|
|
|
uint32_t targetLen = target.length();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if(sourceLen >= StackBufferLen)
|
|
|
|
|
uSource = new UChar[sourceLen+1];
|
|
|
|
|
|
|
|
|
|
if(targetLen >= StackBufferLen)
|
|
|
|
|
uTarget = new UChar[targetLen+1];
|
|
|
|
|
|
|
|
|
|
source.extract(0, sourceLen, uSource);
|
|
|
|
|
uSource[sourceLen] = 0;
|
|
|
|
|
target.extract(0, targetLen, uTarget);
|
|
|
|
|
uTarget[targetLen] = 0;
|
|
|
|
|
EComparisonResult result = compare(uSource, sourceLen, uTarget, targetLen);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if(uSstart != uSource)
|
|
|
|
|
delete[] uSource;
|
|
|
|
|
|
|
|
|
|
if(uTstart != uTarget)
|
|
|
|
|
delete[] uTarget;
|
|
|
|
|
|
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Retrieve a collation key for the specified string. The key can be compared
|
|
|
|
|
* with other collation keys using a bitwise comparison (e.g. memcmp) to find
|
|
|
|
|
* the ordering of their respective source strings. This is handy when doing a
|
|
|
|
|
* sort, where each sort key must be compared many times.
|
|
|
|
|
*
|
|
|
|
|
* The basic algorithm here is to find all of the collation elements for each
|
|
|
|
|
* character in the source string, convert them to an ASCII representation, and
|
|
|
|
|
* put them into the collation key. But it's trickier than that. Each
|
|
|
|
|
* collation element in a string has three components: primary ('A' vs 'B'),
|
|
|
|
|
* secondary ('u' vs '<EFBFBD>'), and tertiary ('A' vs 'a'), and a primary difference
|
|
|
|
|
* at the end of a string takes precedence over a secondary or tertiary
|
|
|
|
|
* difference earlier in the string.
|
|
|
|
|
*
|
|
|
|
|
* To account for this, we put all of the primary orders at the beginning of
|
|
|
|
|
* the string, followed by the secondary and tertiary orders. Each set of
|
|
|
|
|
* orders is terminated by nulls so that a key for a string which is a initial
|
|
|
|
|
* substring of another key will compare less without any special case.
|
|
|
|
|
*
|
|
|
|
|
* Here's a hypothetical example, with the collation element represented as a
|
|
|
|
|
* three-digit number, one digit for primary, one for secondary, etc.
|
|
|
|
|
*
|
|
|
|
|
* String: A a B <EFBFBD>
|
|
|
|
|
* Collation Elements: 101 100 201 511
|
|
|
|
|
* Collation Key: 1125<null>0001<null>1011<null>
|
|
|
|
|
*
|
|
|
|
|
* To make things even trickier, secondary differences (accent marks) are
|
|
|
|
|
* compared starting at the *end* of the string in languages with French
|
|
|
|
|
* secondary ordering. But when comparing the accent marks on a single base
|
|
|
|
|
* character, they are compared from the beginning. To handle this, we reverse
|
|
|
|
|
* all of the accents that belong to each base character, then we reverse the
|
|
|
|
|
* entire string of secondary orderings at the end.
|
|
|
|
|
*/
|
|
|
|
|
CollationKey& RuleBasedCollator::getCollationKey(
|
|
|
|
|
const UnicodeString& source,
|
|
|
|
|
CollationKey& sortkey,
|
|
|
|
|
UErrorCode& status) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UChar sStart[StackBufferLen];
|
|
|
|
|
UChar *uSource = sStart;
|
|
|
|
|
uint32_t sourceLen = source.length();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if(sourceLen >= StackBufferLen)
|
|
|
|
|
uSource = new UChar[sourceLen+1];
|
|
|
|
|
|
|
|
|
|
source.extract(0, sourceLen, uSource);
|
|
|
|
|
uSource[sourceLen] = 0;
|
|
|
|
|
CollationKey& result = getCollationKey(uSource, sourceLen, sortkey, status);
|
|
|
|
|
if(sStart != uSource)
|
|
|
|
|
delete[] uSource;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2000-12-14 01:11:11 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
CollationKey& RuleBasedCollator::getCollationKey(const UChar* source,
|
|
|
|
|
int32_t sourceLen,
|
|
|
|
|
CollationKey& sortkey,
|
|
|
|
|
UErrorCode& status) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
{
|
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
|
return sortkey.setToBogus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((!source) || (sourceLen == 0))
|
|
|
|
|
return sortkey.reset();
|
|
|
|
|
|
|
|
|
|
uint8_t *result = new uint8_t[UCOL_MAX_BUFFER];
|
|
|
|
|
uint8_t resLen = ucol_getSortKey(ucollator, source, sourceLen, result,
|
|
|
|
|
UCOL_MAX_BUFFER);
|
|
|
|
|
sortkey.adopt(result, resLen);
|
|
|
|
|
|
|
|
|
|
return sortkey;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return the maximum length of any expansion sequences that end with the
|
|
|
|
|
* specified comparison order.
|
|
|
|
|
* @param order a collation order returned by previous or next.
|
|
|
|
|
* @return the maximum length of any expansion seuences ending with the
|
|
|
|
|
* specified order.
|
|
|
|
|
* @see CollationElementIterator#getMaxExpansion
|
|
|
|
|
*/
|
|
|
|
|
int32_t RuleBasedCollator::getMaxExpansion(int32_t order) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-03-02 01:14:03 +00:00
|
|
|
|
uint8_t result;
|
|
|
|
|
UCOL_GETMAXEXPANSION(ucollator, (uint32_t)order, result);
|
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
uint8_t* RuleBasedCollator::cloneRuleData(int32_t &length,
|
|
|
|
|
UErrorCode &status)
|
|
|
|
|
{
|
|
|
|
|
return ucol_cloneRuleData(ucollator, &length, &status);
|
|
|
|
|
}
|
2000-12-14 01:11:11 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
void RuleBasedCollator::setAttribute(UColAttribute attr,
|
|
|
|
|
UColAttributeValue value,
|
|
|
|
|
UErrorCode &status)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
|
if (U_FAILURE(status))
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return;
|
|
|
|
|
ucol_setAttribute(ucollator, attr, value, &status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UColAttributeValue RuleBasedCollator::getAttribute(UColAttribute attr,
|
|
|
|
|
UErrorCode &status)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return UCOL_DEFAULT;
|
|
|
|
|
return ucol_getAttribute(ucollator, attr, &status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
Collator* RuleBasedCollator::safeClone(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
|
|
|
|
UCollator *ucol = ucol_safeClone(ucollator, NULL, 0, &intStatus);
|
|
|
|
|
if (U_FAILURE(intStatus))
|
|
|
|
|
return NULL;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
int32_t length = 0;
|
|
|
|
|
UnicodeString *r = new UnicodeString(ucol_getRules(ucollator, &length),
|
|
|
|
|
length);
|
|
|
|
|
RuleBasedCollator *result = new RuleBasedCollator(ucol, r);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
result->dataIsOwned = TRUE;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
Collator::EComparisonResult RuleBasedCollator::compare(
|
|
|
|
|
ForwardCharacterIterator &source,
|
|
|
|
|
ForwardCharacterIterator &target)
|
|
|
|
|
{
|
|
|
|
|
return getEComparisonResult(
|
|
|
|
|
ucol_strcollinc(ucollator, forwardCharIteratorGlue, &source,
|
|
|
|
|
forwardCharIteratorGlue, &target));
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
int32_t RuleBasedCollator::getSortKey(const UnicodeString& source,
|
|
|
|
|
uint8_t *result, int32_t resultLength)
|
|
|
|
|
const
|
|
|
|
|
{
|
|
|
|
|
UChar sStart[StackBufferLen];
|
|
|
|
|
UChar *uSource = sStart;
|
|
|
|
|
uint32_t sourceLen = source.length();
|
|
|
|
|
if(sourceLen >= StackBufferLen)
|
|
|
|
|
uSource = new UChar[sourceLen+1];
|
|
|
|
|
|
|
|
|
|
source.extract(0, sourceLen, uSource);
|
|
|
|
|
uSource[sourceLen] = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
uint8_t resLen = ucol_getSortKey(ucollator, uSource, sourceLen, result,
|
|
|
|
|
resultLength);
|
|
|
|
|
if(sStart != uSource)
|
|
|
|
|
delete[] uSource;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return resLen;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
int32_t RuleBasedCollator::getSortKey(const UChar *source,
|
|
|
|
|
int32_t sourceLength, uint8_t *result,
|
|
|
|
|
int32_t resultLength) const
|
1999-08-16 21:50:52 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
return ucol_getSortKey(ucollator, source, sourceLength, result, resultLength);
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
Collator::ECollationStrength RuleBasedCollator::getStrength(void) const
|
|
|
|
|
{
|
|
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
|
|
|
|
return getECollationStrength(ucol_getAttribute(ucollator, UCOL_STRENGTH,
|
|
|
|
|
&intStatus));
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
void RuleBasedCollator::setStrength(ECollationStrength newStrength)
|
|
|
|
|
{
|
|
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
|
|
|
|
UCollationStrength strength = getUCollationStrength(newStrength);
|
|
|
|
|
ucol_setAttribute(ucollator, UCOL_STRENGTH, strength, &intStatus);
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Create a hash code for this collation. Just hash the main rule table -- that
|
|
|
|
|
* should be good enough for almost any use.
|
|
|
|
|
*/
|
|
|
|
|
int32_t RuleBasedCollator::hashCode() const
|
|
|
|
|
{
|
|
|
|
|
int32_t length;
|
|
|
|
|
const UChar *rules = ucol_getRules(ucollator, &length);
|
|
|
|
|
return uhash_hashUCharsN(rules, length);
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set the decomposition mode of the Collator object. success is equal to
|
|
|
|
|
* U_ILLEGAL_ARGUMENT_ERROR if error occurs.
|
|
|
|
|
* @param the new decomposition mode
|
|
|
|
|
* @see Collator#getDecomposition
|
|
|
|
|
*/
|
|
|
|
|
void RuleBasedCollator::setDecomposition(Normalizer::EMode mode)
|
|
|
|
|
{
|
2001-02-03 01:27:02 +00:00
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
ucol_setNormalization(ucollator, Normalizer::getUNormalizationMode(mode,
|
|
|
|
|
status));
|
2001-01-18 00:23:29 +00:00
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the decomposition mode of the Collator object.
|
|
|
|
|
* @return the decomposition mode
|
|
|
|
|
* @see Collator#setDecomposition
|
|
|
|
|
*/
|
|
|
|
|
Normalizer::EMode RuleBasedCollator::getDecomposition(void) const
|
|
|
|
|
{
|
2001-02-03 01:27:02 +00:00
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
return Normalizer::getNormalizerEMode(ucol_getNormalization(ucollator),
|
|
|
|
|
status);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
// RuleBaseCollatorNew private constructor ----------------------------------
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator() : dataIsOwned(FALSE)
|
|
|
|
|
{
|
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-30 18:52:58 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator(UCollator *collator,
|
|
|
|
|
UnicodeString *rule) : dataIsOwned(FALSE)
|
2001-01-18 00:23:29 +00:00
|
|
|
|
{
|
|
|
|
|
ucollator = collator;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
urulestring = rule;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
RuleBasedCollator::RuleBasedCollator(const Locale& desiredLocale,
|
|
|
|
|
UErrorCode& status) :
|
|
|
|
|
dataIsOwned(FALSE)
|
2000-05-22 19:49:10 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
2000-12-07 07:22:55 +00:00
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/*
|
|
|
|
|
Try to load, in order:
|
|
|
|
|
1. The desired locale's collation.
|
|
|
|
|
2. A fallback of the desired locale.
|
|
|
|
|
3. The default locale's collation.
|
|
|
|
|
4. A fallback of the default locale.
|
|
|
|
|
5. The default collation rules, which contains en_US collation rules.
|
|
|
|
|
|
|
|
|
|
To reiterate, we try:
|
|
|
|
|
Specific:
|
|
|
|
|
language+country+variant
|
|
|
|
|
language+country
|
|
|
|
|
language
|
|
|
|
|
Default:
|
|
|
|
|
language+country+variant
|
|
|
|
|
language+country
|
|
|
|
|
language
|
|
|
|
|
Root: (aka DEFAULTRULES)
|
|
|
|
|
steps 1-5 are handled by resource bundle fallback mechanism.
|
|
|
|
|
however, in a very unprobable situation that no resource bundle
|
|
|
|
|
data exists, step 5 is repeated with hardcoded default rules.
|
|
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
setUCollator(desiredLocale, status);
|
2000-08-11 01:27:17 +00:00
|
|
|
|
|
2001-01-30 18:52:58 +00:00
|
|
|
|
if (U_FAILURE(status))
|
1999-12-03 02:51:54 +00:00
|
|
|
|
{
|
2001-01-30 18:52:58 +00:00
|
|
|
|
status = U_ZERO_ERROR;
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
2001-01-30 18:52:58 +00:00
|
|
|
|
setUCollator(ResourceBundle::kDefaultFilename, status);
|
|
|
|
|
if (U_FAILURE(status))
|
2000-07-14 22:31:35 +00:00
|
|
|
|
{
|
2001-01-30 18:52:58 +00:00
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
|
|
2001-02-15 23:43:26 +00:00
|
|
|
|
uint32_t size = 0;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
if (status == U_ZERO_ERROR)
|
|
|
|
|
status = U_USING_DEFAULT_ERROR;
|
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (status == U_MEMORY_ALLOCATION_ERROR)
|
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
2001-01-18 00:23:29 +00:00
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
if (U_SUCCESS(status))
|
2001-01-30 18:52:58 +00:00
|
|
|
|
{
|
|
|
|
|
int32_t length;
|
|
|
|
|
const UChar *r = ucol_getRules(ucollator, &length);
|
|
|
|
|
urulestring = new UnicodeString(r, length);
|
2001-01-18 00:23:29 +00:00
|
|
|
|
dataIsOwned = TRUE;
|
2001-01-30 18:52:58 +00:00
|
|
|
|
}
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* RuleBasedCollator private data members -------------------------------- */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* need look up in .commit() */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::CHARINDEX = 0x70000000;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* Expand index follows */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::EXPANDCHARINDEX = 0x7E000000;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* contract indexes follows */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::CONTRACTCHARINDEX = 0x7F000000;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* unmapped character values */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::UNMAPPED = 0xFFFFFFFF;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* primary strength increment */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::PRIMARYORDERINCREMENT = 0x00010000;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* secondary strength increment */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::SECONDARYORDERINCREMENT = 0x00000100;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* tertiary strength increment */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::TERTIARYORDERINCREMENT = 0x00000001;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* mask off anything but primary order */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::PRIMARYORDERMASK = 0xffff0000;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* mask off anything but secondary order */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::SECONDARYORDERMASK = 0x0000ff00;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* mask off anything but tertiary order */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::TERTIARYORDERMASK = 0x000000ff;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* mask off ignorable char order */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::IGNORABLEMASK = 0x0000ffff;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* use only the primary difference */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::PRIMARYDIFFERENCEONLY = 0xffff0000;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* use only the primary and secondary difference */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::SECONDARYDIFFERENCEONLY = 0xffffff00;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* primary order shift */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::PRIMARYORDERSHIFT = 16;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* secondary order shift */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::SECONDARYORDERSHIFT = 8;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* starting value for collation elements */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::COLELEMENTSTART = 0x02020202;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* testing mask for primary low element */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::PRIMARYLOWZEROMASK = 0x00FF0000;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* reseting value for secondaries and tertiaries */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::RESETSECONDARYTERTIARY = 0x00000202;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* reseting value for tertiaries */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::RESETTERTIARY = 0x00000002;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int32_t RuleBasedCollator::PRIMIGNORABLE = 0x0202;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* unique file id for parity check */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const int16_t RuleBasedCollator::FILEID = 0x5443;
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* binary collation file extension */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
const char* RuleBasedCollator::kFilenameSuffix = ".col";
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* class id ? Value is irrelevant */
|
2001-01-18 00:23:29 +00:00
|
|
|
|
char RuleBasedCollator::fgClassID = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
2001-02-15 19:30:25 +00:00
|
|
|
|
/* other methods not belonging to any classes ------------------------------- */
|
2000-11-22 00:04:03 +00:00
|
|
|
|
|
2001-01-18 00:23:29 +00:00
|
|
|
|
UChar forwardCharIteratorGlue(void *iterator)
|
2000-11-22 00:04:03 +00:00
|
|
|
|
{
|
2001-01-18 00:23:29 +00:00
|
|
|
|
ForwardCharacterIterator *iter = ((ForwardCharacterIterator *)iterator);
|
|
|
|
|
UChar result = iter->nextPostInc();
|
|
|
|
|
if (result == ForwardCharacterIterator::DONE)
|
|
|
|
|
return 0xFFFF;
|
|
|
|
|
else
|
1999-08-16 21:50:52 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|