1999-12-28 23:57:50 +00:00
|
|
|
|
/*
|
2001-01-18 00:22:38 +00:00
|
|
|
|
******************************************************************************
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Copyright (C) 1996-2001, International Business Machines Corporation and
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* others. All Rights Reserved.
|
|
|
|
|
******************************************************************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2001-01-30 18:52:58 +00:00
|
|
|
|
* File tblcoll.h
|
|
|
|
|
*
|
|
|
|
|
* 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/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::createDefault(). General
|
|
|
|
|
* clean up.
|
|
|
|
|
* 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
|
|
|
|
|
* constructor and getDynamicClassID.
|
|
|
|
|
* 3/5/97 aliu Modified constructFromFile() to add parameter
|
|
|
|
|
* specifying whether or not binary loading is to be
|
|
|
|
|
* attempted. This is required for dynamic rule loading.
|
|
|
|
|
* 05/07/97 helena Added memory allocation error detection.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* 6/17/97 helena Added IDENTICAL strength for compare, changed getRules to
|
2001-01-30 18:52:58 +00:00
|
|
|
|
* use MergeCollation::getPattern.
|
|
|
|
|
* 6/20/97 helena Java class name change.
|
|
|
|
|
* 8/18/97 helena Added internal API documentation.
|
|
|
|
|
* 09/03/97 helena Added createCollationKeyValues().
|
|
|
|
|
* 02/10/98 damiba Added compare with "length" parameter
|
|
|
|
|
* 08/05/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
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* 11/02/99 helena Collator performance enhancements. Eliminates the
|
2001-01-30 18:52:58 +00:00
|
|
|
|
* UnicodeString construction and special case for NO_OP.
|
|
|
|
|
* 11/23/99 srl More performance enhancements. Updates to NormalizerIterator
|
|
|
|
|
* internal state management.
|
|
|
|
|
* 12/15/99 aliu Update to support Thai collation. Move NormalizerIterator
|
|
|
|
|
* to implementation file.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* 01/29/01 synwee Modified into a C++ wrapper which calls C API
|
2001-01-30 18:52:58 +00:00
|
|
|
|
* (ucol.h)
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef TBLCOLL_H
|
|
|
|
|
#define TBLCOLL_H
|
|
|
|
|
|
|
|
|
|
#include "unicode/coll.h"
|
|
|
|
|
#include "unicode/sortkey.h"
|
|
|
|
|
#include "unicode/normlzr.h"
|
|
|
|
|
|
|
|
|
|
class CollationElementIterator;
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* The RuleBasedCollator class provides the simple implementation of
|
|
|
|
|
* Collator, using data-driven tables. The user can create a customized
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* table-based collation.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <P>
|
|
|
|
|
* RuleBasedCollator maps characters to collation keys.
|
|
|
|
|
* <p>
|
|
|
|
|
* Table Collation has the following restrictions for efficiency (other
|
|
|
|
|
* subclasses may be used for more complex languages) :
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* <p>1. If the French secondary ordering is specified in a collation
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* object, it is applied to the whole object.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <p>2. All non-mentioned Unicode characters are at the end of the
|
|
|
|
|
* collation order.
|
|
|
|
|
* <p>3. Private use characters are treated as identical. The private
|
|
|
|
|
* use area in Unicode is 0xE800-0xF8FF.
|
|
|
|
|
* <p>The collation table is composed of a list of collation rules, where each
|
|
|
|
|
* rule is of three forms:
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* <modifier >
|
|
|
|
|
* <relation > < text-argument >
|
|
|
|
|
* <reset > < text-argument >
|
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* The following demonstrates how to create your own collation rules:
|
|
|
|
|
* <UL Type=round>
|
|
|
|
|
* <LI><strong>Text Argument</strong>: A text argument is any sequence of
|
|
|
|
|
* characters, excluding special characters (that is, whitespace
|
|
|
|
|
* characters and the characters used in modifier, relation and reset).
|
|
|
|
|
* If those characters are desired, you can put them in single quotes
|
|
|
|
|
* (e.g. ampersand => '&').<P>
|
|
|
|
|
* <LI><strong>Modifier</strong>: There is a single modifier,
|
|
|
|
|
* which is used to specify that all secondary differences are
|
|
|
|
|
* sorted backwards.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* <p>'@' : Indicates that secondary differences, such as accents, are
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* sorted backwards, as in French.<P>
|
|
|
|
|
* <LI><strong>Relation</strong>: The relations are the following:
|
|
|
|
|
* <UL Type=square>
|
|
|
|
|
* <LI>'<' : Greater, as a letter difference (primary)
|
|
|
|
|
* <LI>';' : Greater, as an accent difference (secondary)
|
|
|
|
|
* <LI>',' : Greater, as a case difference (tertiary)
|
|
|
|
|
* <LI>'=' : Equal
|
|
|
|
|
* </UL><P>
|
|
|
|
|
* <LI><strong>Reset</strong>: There is a single reset,
|
|
|
|
|
* which is used primarily for contractions and expansions, but which
|
|
|
|
|
* can also be used to add a modification at the end of a set of rules.
|
|
|
|
|
* <p>'&' : Indicates that the next rule follows the position to where
|
|
|
|
|
* the reset text-argument would be sorted.
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* </UL>
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*
|
|
|
|
|
* <p>
|
|
|
|
|
* This sounds more complicated than it is in practice. For example, the
|
|
|
|
|
* following are equivalent ways of expressing the same thing:
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* a < b < c
|
|
|
|
|
* a < b & b < c
|
|
|
|
|
* a < c & a < b
|
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* Notice that the order is important, as the subsequent item goes immediately
|
|
|
|
|
* after the text-argument. The following are not equivalent:
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* a < b & a < c
|
|
|
|
|
* a < c & a < b
|
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* Either the text-argument must already be present in the sequence, or some
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* initial substring of the text-argument must be present. (e.g. "a < b &
|
|
|
|
|
* ae < e" is valid since "a" is present in the sequence before "ae" is
|
|
|
|
|
* reset). In this latter case, "ae" is not entered and treated as a single
|
|
|
|
|
* character; instead, "e" is sorted as if it were expanded to two characters:
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* "a" followed by an "e". This difference appears in natural languages: in
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* traditional Spanish "ch" is treated as though it contracts to a single
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* character (expressed as "c < ch < d"), while in traditional German
|
|
|
|
|
* "<EFBFBD>" (a-umlaut) is treated as though it expands to two characters (expressed
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* as "a & ae ; <20> < b").
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <p><strong>Ignorable Characters</strong>
|
|
|
|
|
* <p>For ignorable characters, the first rule must start with a relation (the
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* examples we have used above are really fragments; "a < b" really should
|
|
|
|
|
* be "< a < b"). If, however, the first relation is not "<", then
|
|
|
|
|
* all the text-arguments up to the first "<" are ignorable. For example,
|
|
|
|
|
* ", - < a < b" makes "-" an ignorable character, as we saw earlier in
|
|
|
|
|
* the word "black-birds". In the samples for different languages, you see
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* that most accents are ignorable.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <p><strong>Normalization and Accents</strong>
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* <p>The Collator object automatically normalizes text internally to
|
|
|
|
|
* separate accents from base characters where possible. This is done both
|
|
|
|
|
* when processing the rules, and when comparing two strings. Collator also
|
|
|
|
|
* uses the Unicode canonical mapping to ensure that combining sequences are
|
|
|
|
|
* sorted properly (for more information, see
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* <A HREF="http://www.aw.com/devpress"> The Unicode Standard, Version 2.0</A>
|
|
|
|
|
* .)</P>
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <p><strong>Errors</strong>
|
|
|
|
|
* <p>The following are errors:
|
|
|
|
|
* <UL Type=round>
|
|
|
|
|
* <LI>A text-argument contains unquoted punctuation symbols
|
|
|
|
|
* (e.g. "a < b-c < d").
|
|
|
|
|
* <LI>A relation or reset character not followed by a text-argument
|
|
|
|
|
* (e.g. "a < , b").
|
|
|
|
|
* <LI>A reset where the text-argument (or an initial substring of the
|
|
|
|
|
* text-argument) is not already in the sequence.
|
|
|
|
|
* (e.g. "a < b & e < f")
|
|
|
|
|
* </UL>
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* Examples:
|
|
|
|
|
* Simple: "< a < b < c < d"
|
|
|
|
|
* Norwegian: "< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J
|
|
|
|
|
* < k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T
|
|
|
|
|
* < u,U< v,V< w,W< x,X< y,Y< z,Z
|
|
|
|
|
* < <EFBFBD>=a<EFBFBD>,<EFBFBD>=A<EFBFBD>
|
|
|
|
|
* ;aa,AA< <EFBFBD>,<EFBFBD>< <EFBFBD>,<EFBFBD>"
|
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* <p>To create a table-based collation object, simply supply the collation
|
|
|
|
|
* rules to the RuleBasedCollator contructor. For example:
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator *mySimple =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(Simple, status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* <p>Another example:
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator *myNorwegian =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(Norwegian, status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* To add rules on top of an existing table, simply supply the orginal rules
|
|
|
|
|
* and modifications to RuleBasedCollator constructor. For example,
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* Traditional Spanish (fragment): ... & C < ch , cH , Ch , CH ...
|
|
|
|
|
* German (fragment) : ...< y , Y < z , Z
|
|
|
|
|
* & AE, <EFBFBD> & AE, <EFBFBD>
|
|
|
|
|
* & OE , <EFBFBD> & OE, <EFBFBD>
|
|
|
|
|
* & UE , <EFBFBD> & UE, <EFBFBD>
|
|
|
|
|
* Symbols (fragment): ...< y, Y < z , Z
|
|
|
|
|
* & Question-mark ; '?'
|
|
|
|
|
* & Ampersand ; '&'
|
|
|
|
|
* & Dollar-sign ; '$'
|
|
|
|
|
* \endcode
|
|
|
|
|
* </pre>
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <p>To create a collation object for traditional Spanish, the user can take
|
|
|
|
|
* the English collation rules and add the additional rules to the table.
|
|
|
|
|
* For example:
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
* UnicodeString rules(DEFAULTRULES);
|
|
|
|
|
* rules += "& C < ch, cH, Ch, CH";
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator *mySpanish =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(rules, status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* <p>In order to sort symbols in the similiar order of sorting their
|
|
|
|
|
* alphabetic equivalents, you can do the following,
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
* UnicodeString rules(DEFAULTRULES);
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* rules += "& Question-mark ; '?' & Ampersand ; '&' & Dollar-sign ;
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* '$' ";
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator *myTable =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(rules, status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* <p>Another way of creating the table-based collation object, mySimple,
|
|
|
|
|
* is:
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
* RuleBasedCollator *mySimple = new
|
2001-03-19 22:30:38 +00:00
|
|
|
|
* RuleBasedCollator(" < a < b & b < c & c < d", status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* Or,
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
* RuleBasedCollator *mySimple = new
|
2001-03-19 22:30:38 +00:00
|
|
|
|
* RuleBasedCollator(" < a < b < d & b < c", status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Because " < a < b < c < d" is the same as "a < b < d & b
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* < c" or "< a < b & b < c & c < d".
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* <p>To combine collations from two locales, (without error handling for
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* clarity)
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* // Create an en_US Collator object
|
|
|
|
|
* Locale locale_en_US("en", "US", "");
|
|
|
|
|
* RuleBasedCollator* en_USCollator = (RuleBasedCollator*)
|
|
|
|
|
* Collator::createInstance( locale_en_US, success );
|
2001-03-22 00:09:10 +00:00
|
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* // Create a da_DK Collator object
|
|
|
|
|
* Locale locale_da_DK("da", "DK", "");
|
|
|
|
|
* RuleBasedCollator* da_DKCollator = (RuleBasedCollator*)
|
|
|
|
|
* Collator::createInstance( locale_da_DK, success );
|
2001-03-22 00:09:10 +00:00
|
|
|
|
*
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* // Combine the two
|
|
|
|
|
* // First, get the collation rules from en_USCollator
|
|
|
|
|
* UnicodeString rules = en_USCollator->getRules();
|
|
|
|
|
* // Second, get the collation rules from da_DKCollator
|
|
|
|
|
* rules += da_DKCollator->getRules();
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator* newCollator =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(rules, success);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* // newCollator has the combined rules
|
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* <p>Another more interesting example would be to make changes on an existing
|
|
|
|
|
* table to create a new collation object. For example, add
|
|
|
|
|
* "& C < ch, cH, Ch, CH" to the en_USCollation object to create your own
|
|
|
|
|
* English collation object,
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* // Create a new Collator object with additional rules
|
|
|
|
|
* rules = en_USCollator->getRules();
|
|
|
|
|
* rules += "& C < ch, cH, Ch, CH";
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator* myCollator =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(rules, success);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* // myCollator contains the new rules
|
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* <p>The following example demonstrates how to change the order of
|
|
|
|
|
* non-spacing accents,
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UChar contents[] = {
|
|
|
|
|
* '=', 0x0301, ';', 0x0300, ';', 0x0302,
|
|
|
|
|
* ';', 0x0308, ';', 0x0327, ',', 0x0303, // main accents
|
|
|
|
|
* ';', 0x0304, ';', 0x0305, ';', 0x0306, // main accents
|
|
|
|
|
* ';', 0x0307, ';', 0x0309, ';', 0x030A, // main accents
|
|
|
|
|
* ';', 0x030B, ';', 0x030C, ';', 0x030D, // main accents
|
|
|
|
|
* ';', 0x030E, ';', 0x030F, ';', 0x0310, // main accents
|
|
|
|
|
* ';', 0x0311, ';', 0x0312, // main accents
|
|
|
|
|
* '<', 'a', ',', 'A', ';', 'a', 'e', ',', 'A', 'E',
|
|
|
|
|
* ';', 0x00e6, ',', 0x00c6, '<', 'b', ',', 'B',
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* '<', 'c', ',', 'C', '<', 'e', ',', 'E', '&',
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* 'C', '<', 'd', ',', 'D', 0 };
|
|
|
|
|
* UnicodeString oldRules(contents);
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
* // change the order of accent characters
|
|
|
|
|
* UChar addOn[] = { '&', ',', 0x0300, ';', 0x0308, ';', 0x0302, 0 };
|
|
|
|
|
* oldRules += addOn;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator *myCollation =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(oldRules, status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* <p> The last example shows how to put new primary ordering in before the
|
|
|
|
|
* default setting. For example, in Japanese collation, you can either sort
|
|
|
|
|
* English characters before or after Japanese characters,
|
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \code
|
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
* // get en_US collation rules
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator* en_USCollation = (RuleBasedCollator*)
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Collator::createInstance(Locale::US, status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* // Always check the error code after each call.
|
|
|
|
|
* if (U_FAILURE(status)) return;
|
|
|
|
|
* // add a few Japanese character to sort before English characters
|
|
|
|
|
* // suppose the last character before the first base letter 'a' in
|
|
|
|
|
* // the English collation rule is 0x2212
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* UChar jaString[] = {'&', 0x2212, '<', 0x3041, ',', 0x3042, '<',
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* 0x3043, ',', 0x3044, 0};
|
|
|
|
|
* UnicodeString rules(en_USCollation->getRules());
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* rules += jaString;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator *myJapaneseCollation =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* new RuleBasedCollator(rules, status);
|
2000-12-08 18:46:55 +00:00
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* <p><strong>NOTE</strong>: Typically, a collation object is created with
|
|
|
|
|
* Collator::createInstance().
|
|
|
|
|
* <p>
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* <strong>Note:</strong> <code>RuleBasedCollator</code>s with different
|
|
|
|
|
* Locale, CollationStrength and Decomposition mode settings will return
|
|
|
|
|
* different sort orders for the same set of strings. Locales have specific
|
|
|
|
|
* collation rules, and the way in which secondary and tertiary differences
|
|
|
|
|
* are taken into account, for example, will result in a different sorting
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* order for same strings.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <p>
|
|
|
|
|
* @see Collator
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @version 1.8 Jan 8 2001
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
class U_I18N_API RuleBasedCollator : public Collator
|
1999-12-28 23:57:50 +00:00
|
|
|
|
{
|
2001-03-22 00:09:10 +00:00
|
|
|
|
public:
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// constructor -------------------------------------------------------------
|
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator constructor. This takes the table rules and builds a
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* collation table out of them. Please see RuleBasedCollator class
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* description for more details on the collation rule syntax.
|
|
|
|
|
* @param rules the collation rules to build the collation table from.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @param status reporting a success or an error.
|
|
|
|
|
* @see Locale
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator constructor. This takes the table rules and builds a
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* collation table out of them. Please see RuleBasedCollator class
|
|
|
|
|
* description for more details on the collation rule syntax.
|
|
|
|
|
* @param rules the collation rules to build the collation table from.
|
|
|
|
|
* @param collationStrength default strength for comparison
|
|
|
|
|
* @param status reporting a success or an error.
|
|
|
|
|
* @see Locale
|
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
RuleBasedCollator(const UnicodeString& rules,
|
|
|
|
|
ECollationStrength collationStrength,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator constructor. This takes the table rules and builds a
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* collation table out of them. Please see RuleBasedCollator class
|
|
|
|
|
* description for more details on the collation rule syntax.
|
|
|
|
|
* @param rules the collation rules to build the collation table from.
|
|
|
|
|
* @param decompositionMode the normalisation mode
|
|
|
|
|
* @param status reporting a success or an error.
|
|
|
|
|
* @see Locale
|
|
|
|
|
*/
|
|
|
|
|
RuleBasedCollator(const UnicodeString& rules,
|
2001-03-22 00:09:10 +00:00
|
|
|
|
Normalizer::EMode decompositionMode,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator constructor. This takes the table rules and builds a
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* collation table out of them. Please see RuleBasedCollator class
|
|
|
|
|
* description for more details on the collation rule syntax.
|
|
|
|
|
* @param rules the collation rules to build the collation table from.
|
|
|
|
|
* @param collationStrength default strength for comparison
|
|
|
|
|
* @param decompositionMode the normalisation mode
|
|
|
|
|
* @param status reporting a success or an error.
|
|
|
|
|
* @see Locale
|
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
RuleBasedCollator(const UnicodeString& rules,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
ECollationStrength collationStrength,
|
|
|
|
|
Normalizer::EMode decompositionMode,
|
|
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Copy constructor.
|
|
|
|
|
* @param the RuleBasedCollator object to be copied
|
|
|
|
|
* @see Locale
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
RuleBasedCollator(const RuleBasedCollator& other);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// destructor --------------------------------------------------------------
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Destructor.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
virtual ~RuleBasedCollator();
|
|
|
|
|
|
|
|
|
|
// public methods ----------------------------------------------------------
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assignment operator.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @param other other RuleBasedCollator object to compare with.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
|
|
|
|
RuleBasedCollator& operator=(const RuleBasedCollator& other);
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Returns true if argument is the same as this object.
|
|
|
|
|
* @param other Collator object to be compared.
|
|
|
|
|
* @return true if arguments is the same as this object.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
virtual UBool operator==(const Collator& other) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Returns true if argument is not the same as this object.
|
|
|
|
|
* @param other Collator object to be compared
|
|
|
|
|
* @return returns true if argument is not the same as this object.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
virtual UBool operator!=(const Collator& other) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Makes a deep copy of the object.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* The caller owns the returned object.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* @return the cloned object.
|
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
virtual Collator* clone(void) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Creates a collation element iterator for the source string. The caller of
|
|
|
|
|
* this method is responsible for the memory management of the return
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* pointer.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param source the string over which the CollationElementIterator will
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* iterate.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* @return the collation element iterator of the source string using this as
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* the based Collator.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
virtual CollationElementIterator* createCollationElementIterator(
|
|
|
|
|
const UnicodeString& source) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Creates a collation element iterator for the source. The caller of this
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* method is responsible for the memory management of the returned pointer.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param source the CharacterIterator which produces the characters over
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* which the CollationElementItgerator will iterate.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @return the collation element iterator of the source using this as the
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* based Collator.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
virtual CollationElementIterator* createCollationElementIterator(
|
|
|
|
|
const CharacterIterator& source) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Compares a range of character data stored in two different strings based
|
|
|
|
|
* on the collation rules. Returns information about whether a string is
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* less than, greater than or equal to another string in a language.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* This can be overriden in a subclass.
|
|
|
|
|
* @param source the source string.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @param target the target string to be compared with the source string.
|
|
|
|
|
* @return the comparison result. GREATER if the source string is greater
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* than the target string, LESS if the source is less than the
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* target. Otherwise, returns EQUAL.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
virtual EComparisonResult compare(const UnicodeString& source,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
const UnicodeString& target) const;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Compares a range of character data stored in two different strings based
|
|
|
|
|
* on the collation rules up to the specified length. Returns information
|
|
|
|
|
* about whether a string is less than, greater than or equal to another
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* string in a language. This can be overriden in a subclass.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* @param source the source string.
|
|
|
|
|
* @param target the target string to be compared with the source string.
|
|
|
|
|
* @param length compares up to the specified length
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @return the comparison result. GREATER if the source string is greater
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* than the target string, LESS if the source is less than the
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* target. Otherwise, returns EQUAL.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
*/
|
|
|
|
|
virtual EComparisonResult compare(const UnicodeString& source,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
const UnicodeString& target,
|
|
|
|
|
int32_t length) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The comparison function compares the character data stored in two
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* different string arrays. Returns information about whether a string array
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* is less than, greater than or equal to another string array.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* <p>Example of use:
|
|
|
|
|
* <pre>
|
|
|
|
|
* . UErrorCode status = U_ZERO_ERROR;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* . Collator *myCollation =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* . Collator::createInstance(Locale::US, status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* . if (U_FAILURE(status)) return;
|
|
|
|
|
* . myCollation->setStrength(Collator::PRIMARY);
|
|
|
|
|
* . // result would be Collator::EQUAL ("abc" == "ABC")
|
|
|
|
|
* . // (no primary difference between "abc" and "ABC")
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* . Collator::UCollationResult result =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* . myCollation->compare(L"abc", 3, L"ABC", 3);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* . myCollation->setStrength(Collator::TERTIARY);
|
|
|
|
|
* . // result would be Collator::LESS (abc" <<< "ABC")
|
|
|
|
|
* . // (with tertiary difference between "abc" and "ABC")
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* . Collator::UCollationResult result =
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* . myCollation->compare(L"abc", 3, L"ABC", 3);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* </pre>
|
|
|
|
|
* @param source the source string array to be compared with.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @param sourceLength the length of the source string array. If this value
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* is equal to -1, the string array is null-terminated.
|
|
|
|
|
* @param target the string that is to be compared with the source string.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @param targetLength the length of the target string array. If this value
|
1999-12-28 23:57:50 +00:00
|
|
|
|
* is equal to -1, the string array is null-terminated.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @return Returns a byte value. GREATER if source is greater than target;
|
|
|
|
|
* EQUAL if source is equal to target; LESS if source is less than
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* target
|
|
|
|
|
*/
|
|
|
|
|
virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
|
2001-03-22 00:09:10 +00:00
|
|
|
|
const UChar* target, int32_t targetLength)
|
2001-01-18 00:22:38 +00:00
|
|
|
|
const;
|
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Transforms a specified region of the string into a series of characters
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* that can be compared with CollationKey.compare. Use a CollationKey when
|
|
|
|
|
* you need to do repeated comparisions on the same string. For a single
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* comparison the compare method will be faster.
|
|
|
|
|
* @param source the source string.
|
|
|
|
|
* @param key the transformed key of the source string.
|
|
|
|
|
* @param status the error code status.
|
|
|
|
|
* @return the transformed key.
|
|
|
|
|
* @see CollationKey
|
|
|
|
|
*/
|
|
|
|
|
virtual CollationKey& getCollationKey(const UnicodeString& source,
|
|
|
|
|
CollationKey& key,
|
|
|
|
|
UErrorCode& status) const;
|
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Transforms a specified region of the string into a series of characters
|
|
|
|
|
* that can be compared with CollationKey.compare. Use a CollationKey when
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* you need to do repeated comparisions on the same string. For a single
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* comparison the compare method will be faster.
|
|
|
|
|
* @param source the source string.
|
|
|
|
|
* @param key the transformed key of the source string.
|
|
|
|
|
* @param status the error code status.
|
|
|
|
|
* @return the transformed key.
|
|
|
|
|
* @see CollationKey
|
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
virtual CollationKey& getCollationKey(const UChar *source,
|
|
|
|
|
int32_t sourceLength,
|
|
|
|
|
CollationKey& key,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
UErrorCode& status) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates the hash code for the rule-based collation object.
|
|
|
|
|
* @return the hash code.
|
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
virtual int32_t hashCode(void) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the table-based rules for the collation object.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @return returns the collation rules that the table collation object was
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* created from.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
const UnicodeString& getRules(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Return the maximum length of any expansion sequences that end with the
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* specified comparison order.
|
|
|
|
|
* @param order a collation order returned by previous or next.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @return maximum size of the expansion sequences ending with the collation
|
|
|
|
|
* element or 1 if collation element does not occur at the end of
|
2001-03-03 04:06:43 +00:00
|
|
|
|
* any expansion sequence
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @see CollationElementIterator#getMaxExpansion
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
|
|
|
|
int32_t getMaxExpansion(int32_t order) const;
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
|
|
|
|
* method is to implement a simple version of RTTI, since not all C++
|
|
|
|
|
* compilers support genuine RTTI. Polymorphic operator==() and clone()
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* methods call this method.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @return The class ID for this object. All objects of a given class have
|
|
|
|
|
* the same class ID. Objects of other classes have different class
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* IDs.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
|
|
|
|
virtual UClassID getDynamicClassID(void) const
|
2001-03-22 00:09:10 +00:00
|
|
|
|
{
|
|
|
|
|
return RuleBasedCollator::getStaticClassID();
|
2001-01-18 00:22:38 +00:00
|
|
|
|
}
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Returns the class ID for this class. This is useful only for comparing to
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* a return value from getDynamicClassID(). For example:
|
|
|
|
|
* <pre>
|
|
|
|
|
* Base* polymorphic_pointer = createPolymorphicObject();
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* if (polymorphic_pointer->getDynamicClassID() ==
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Derived::getStaticClassID()) ...
|
|
|
|
|
* </pre>
|
|
|
|
|
* @return The class ID for all objects of this class.
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
static UClassID getStaticClassID(void)
|
|
|
|
|
{
|
|
|
|
|
return (UClassID)&fgClassID;
|
2001-01-18 00:22:38 +00:00
|
|
|
|
}
|
2000-05-18 21:25:51 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Returns the binary format of the class's rules. The format is that of
|
|
|
|
|
* .col files.
|
2000-05-18 21:25:51 +00:00
|
|
|
|
* @param length Returns the length of the data, in bytes
|
|
|
|
|
* @param status the error code status.
|
|
|
|
|
* @return memory, owned by the caller, of size 'length' bytes.
|
|
|
|
|
*/
|
|
|
|
|
uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
|
|
|
|
|
|
2000-11-17 23:32:32 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Returns current rules. Delta defines whether full rules are returned or
|
|
|
|
|
* just the tailoring.
|
|
|
|
|
* @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
|
2000-11-17 23:32:32 +00:00
|
|
|
|
* @return UnicodeString with rules
|
|
|
|
|
*/
|
|
|
|
|
UnicodeString getRules(UColRuleOption delta);
|
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Universal attribute setter
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param attr attribute type
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @param value attribute value
|
|
|
|
|
* @param status to indicate whether the operation went on smoothly or there were errors
|
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
UErrorCode &status);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Universal attribute getter.
|
|
|
|
|
* @param attr attribute type
|
|
|
|
|
* @param status to indicate whether the operation went on smoothly or there were errors
|
|
|
|
|
* @return attribute value
|
|
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
|
virtual UColAttributeValue getAttribute(UColAttribute attr,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
UErrorCode &status);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Thread safe cloning operation.
|
|
|
|
|
* @return pointer to the new clone, user should remove it.
|
|
|
|
|
*/
|
|
|
|
|
virtual Collator* safeClone(void);
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* String compare that uses user supplied character iteration. The idea is
|
|
|
|
|
* to prevent users from having to convert the whole string into UChar's
|
|
|
|
|
* before comparing since sometimes strings differ on first couple of
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* characters.
|
|
|
|
|
* @param coll Collator to be used for comparing
|
|
|
|
|
* @param source pointer to function for iterating over the first string
|
|
|
|
|
* @param target pointer to function for iterating over the second string
|
|
|
|
|
* @return The result of comparing the strings; one of UCOL_EQUAL,
|
|
|
|
|
* UCOL_GREATER, UCOL_LESS
|
|
|
|
|
*/
|
|
|
|
|
virtual EComparisonResult compare(ForwardCharacterIterator &source,
|
|
|
|
|
ForwardCharacterIterator &target);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the sort key as an array of bytes from an UnicodeString.
|
|
|
|
|
* @param source string to be processed.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param result buffer to store result in. If NULL, number of bytes needed
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* will be returned.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param resultLength length of the result buffer. If if not enough the
|
|
|
|
|
* buffer will be filled to capacity.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @return Number of bytes needed for storing the sort key
|
|
|
|
|
*/
|
|
|
|
|
virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
|
|
|
|
|
int32_t resultLength) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the sort key as an array of bytes from an UChar buffer.
|
|
|
|
|
* @param source string to be processed.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param sourceLength length of string to be processed. If -1, the string
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* is 0 terminated and length will be decided by the function.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param result buffer to store result in. If NULL, number of bytes needed
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* will be returned.
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* @param resultLength length of the result buffer. If if not enough the
|
|
|
|
|
* buffer will be filled to capacity.
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* @return Number of bytes needed for storing the sort key
|
|
|
|
|
*/
|
|
|
|
|
virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
|
|
|
|
|
uint8_t *result, int32_t resultLength) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines the minimum strength that will be use in comparison or
|
|
|
|
|
* transformation.
|
|
|
|
|
* <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
|
|
|
|
|
* <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
|
|
|
|
|
* are ignored.
|
|
|
|
|
* @return the current comparison level.
|
|
|
|
|
* @see RuleBasedCollator#setStrength
|
|
|
|
|
*/
|
|
|
|
|
virtual ECollationStrength getStrength(void) const;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the minimum strength to be used in comparison or transformation.
|
|
|
|
|
* <p>Example of use:
|
|
|
|
|
* <pre>
|
|
|
|
|
* . UErrorCode status = U_ZERO_ERROR;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* . Collator*myCollation = Collator::createInstance(Locale::US,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* status);
|
|
|
|
|
* . if (U_FAILURE(status)) return;
|
|
|
|
|
* . myCollation->setStrength(Collator::PRIMARY);
|
|
|
|
|
* . // result will be "abc" == "ABC"
|
|
|
|
|
* . // tertiary differences will be ignored
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* . Collator::ComparisonResult result = myCollation->compare("abc",
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* "ABC");
|
|
|
|
|
* </pre>
|
|
|
|
|
* @see RuleBasedCollator#getStrength
|
|
|
|
|
* @param newStrength the new comparison level.
|
|
|
|
|
* @stable
|
|
|
|
|
*/
|
|
|
|
|
virtual void setStrength(ECollationStrength newStrength);
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Set the decomposition mode of the Collator object. success is equal to
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* U_ILLEGAL_ARGUMENT_ERROR if error occurs.
|
|
|
|
|
* @param the new decomposition mode
|
|
|
|
|
* @see Collator#getDecomposition
|
|
|
|
|
*/
|
|
|
|
|
virtual void setDecomposition(Normalizer::EMode mode);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the decomposition mode of the Collator object.
|
|
|
|
|
* @return the decomposition mode
|
|
|
|
|
* @see Collator#setDecomposition
|
|
|
|
|
*/
|
|
|
|
|
virtual Normalizer::EMode getDecomposition(void) const;
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
private:
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// private static constants -----------------------------------------------
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
static const int32_t UNMAPPED;
|
|
|
|
|
static const int32_t CHARINDEX; // need look up in .commit()
|
|
|
|
|
static const int32_t EXPANDCHARINDEX; // Expand index follows
|
|
|
|
|
static const int32_t CONTRACTCHARINDEX; // contract indexes follow
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
static const int32_t PRIMARYORDERINCREMENT;
|
|
|
|
|
static const int32_t SECONDARYORDERINCREMENT;
|
|
|
|
|
static const int32_t TERTIARYORDERINCREMENT;
|
|
|
|
|
static const int32_t PRIMARYORDERMASK;
|
|
|
|
|
static const int32_t SECONDARYORDERMASK;
|
|
|
|
|
static const int32_t TERTIARYORDERMASK;
|
|
|
|
|
static const int32_t IGNORABLEMASK;
|
|
|
|
|
static const int32_t PRIMARYDIFFERENCEONLY;
|
|
|
|
|
static const int32_t SECONDARYDIFFERENCEONLY;
|
|
|
|
|
static const int32_t PRIMARYORDERSHIFT;
|
|
|
|
|
static const int32_t SECONDARYORDERSHIFT;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
static const int32_t COLELEMENTSTART;
|
|
|
|
|
static const int32_t PRIMARYLOWZEROMASK;
|
|
|
|
|
static const int32_t RESETSECONDARYTERTIARY;
|
|
|
|
|
static const int32_t RESETTERTIARY;
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
static const int32_t PRIMIGNORABLE;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
static const int16_t FILEID;
|
|
|
|
|
static const char *kFilenameSuffix;
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// private static variables -----------------------------------------------
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* static class id
|
|
|
|
|
*/
|
|
|
|
|
static char fgClassID;
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// private data members ---------------------------------------------------
|
2000-11-17 23:32:32 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
UBool dataIsOwned;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* c struct for collation. All initialisation for it has to be done through
|
|
|
|
|
* setUCollator().
|
|
|
|
|
*/
|
|
|
|
|
UCollator *ucollator;
|
|
|
|
|
|
2001-01-30 18:52:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* Rule UnicodeString
|
|
|
|
|
*/
|
|
|
|
|
UnicodeString *urulestring;
|
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// friend classes --------------------------------------------------------
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Streamer used to read/write binary collation data files.
|
|
|
|
|
*/
|
|
|
|
|
friend class RuleBasedCollatorStreamer;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Used to iterate over collation elements in a character source.
|
|
|
|
|
*/
|
|
|
|
|
friend class CollationElementIterator;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* Collator ONLY needs access to RuleBasedCollator(const Locale&,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* UErrorCode&)
|
|
|
|
|
*/
|
1999-12-28 23:57:50 +00:00
|
|
|
|
friend class Collator;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// private constructors --------------------------------------------------
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Default constructor
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
|
|
|
|
RuleBasedCollator();
|
|
|
|
|
|
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Constructor that takes in a UCollator struct
|
|
|
|
|
* @param collator UCollator struct
|
|
|
|
|
*/
|
2001-01-30 18:52:58 +00:00
|
|
|
|
RuleBasedCollator(UCollator *collator, UnicodeString *rule);
|
2001-01-18 00:22:38 +00:00
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
/**
|
2001-03-22 00:09:10 +00:00
|
|
|
|
* RuleBasedCollator constructor. This constructor takes a locale. The
|
|
|
|
|
* only caller of this class should be Collator::createInstance(). If
|
|
|
|
|
* createInstance() happens to know that the requested locale's collation is
|
|
|
|
|
* implemented as a RuleBasedCollator, it can then call this constructor.
|
|
|
|
|
* OTHERWISE IT SHOULDN'T, since this constructor ALWAYS RETURNS A VALID
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* COLLATION TABLE. It does this by falling back to defaults.
|
|
|
|
|
* @param desiredLocale locale used
|
|
|
|
|
* @param status error code status
|
1999-12-28 23:57:50 +00:00
|
|
|
|
*/
|
2001-01-18 00:22:38 +00:00
|
|
|
|
RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// private methods -------------------------------------------------------
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Creates the c struct for ucollator
|
|
|
|
|
* @param locale desired locale
|
|
|
|
|
* @param status error status
|
|
|
|
|
*/
|
|
|
|
|
void setUCollator(const Locale& locale, UErrorCode& status);
|
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Creates the c struct for ucollator
|
|
|
|
|
* @param locale desired locale name
|
|
|
|
|
* @param status error status
|
|
|
|
|
*/
|
|
|
|
|
void setUCollator(const char* locale, UErrorCode& status);
|
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Creates the c struct for ucollator
|
|
|
|
|
* @param collator new ucollator data
|
|
|
|
|
* @param status error status
|
|
|
|
|
*/
|
|
|
|
|
void setUCollator(UCollator *collator);
|
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Converts C's UCollationResult to EComparisonResult
|
|
|
|
|
* @param result member of the enum UComparisonResult
|
|
|
|
|
* @return EComparisonResult equivalent of UCollationResult
|
|
|
|
|
*/
|
|
|
|
|
Collator::EComparisonResult getEComparisonResult(
|
|
|
|
|
const UCollationResult &result) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Converts C's UCollationStrength to ECollationStrength
|
|
|
|
|
* @param strength member of the enum UCollationStrength
|
|
|
|
|
* @return ECollationStrength equivalent of UCollationStrength
|
|
|
|
|
*/
|
|
|
|
|
Collator::ECollationStrength getECollationStrength(
|
|
|
|
|
const UCollationStrength &strength) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2001-01-18 00:22:38 +00:00
|
|
|
|
* Converts C++'s ECollationStrength to UCollationStrength
|
|
|
|
|
* @param strength member of the enum ECollationStrength
|
|
|
|
|
* @return UCollationStrength equivalent of ECollationStrength
|
|
|
|
|
*/
|
|
|
|
|
UCollationStrength getUCollationStrength(
|
|
|
|
|
const Collator::ECollationStrength &strength) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
// inline method implementation ---------------------------------------------
|
2000-12-14 01:11:11 +00:00
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
inline UBool RuleBasedCollator::operator!=(const Collator& other) const
|
1999-12-28 23:57:50 +00:00
|
|
|
|
{
|
|
|
|
|
return !(*this == other);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
inline void RuleBasedCollator::setUCollator(const char *locale,
|
2001-01-18 00:22:38 +00:00
|
|
|
|
UErrorCode &status)
|
|
|
|
|
{
|
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
|
return;
|
|
|
|
|
if (ucollator && dataIsOwned)
|
|
|
|
|
ucol_close(ucollator);
|
|
|
|
|
ucollator = ucol_open(locale, &status);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
|
inline void RuleBasedCollator::setUCollator(const Locale &locale,
|
2001-02-05 19:53:37 +00:00
|
|
|
|
UErrorCode &status)
|
|
|
|
|
{
|
|
|
|
|
setUCollator(locale.getName(), status);
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-18 00:22:38 +00:00
|
|
|
|
inline void RuleBasedCollator::setUCollator(UCollator *collator)
|
|
|
|
|
{
|
|
|
|
|
if (ucollator && dataIsOwned)
|
|
|
|
|
ucol_close(ucollator);
|
|
|
|
|
ucollator = collator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
|
|
|
|
|
const UCollationResult &result) const
|
|
|
|
|
{
|
|
|
|
|
switch (result)
|
|
|
|
|
{
|
|
|
|
|
case UCOL_LESS :
|
|
|
|
|
return Collator::LESS;
|
|
|
|
|
case UCOL_EQUAL :
|
2001-03-22 00:09:10 +00:00
|
|
|
|
return Collator::EQUAL;
|
2001-02-10 02:55:38 +00:00
|
|
|
|
default :
|
|
|
|
|
return Collator::GREATER;
|
2001-01-18 00:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
|
|
|
|
|
const UCollationStrength &strength) const
|
2001-03-22 00:09:10 +00:00
|
|
|
|
{
|
2001-01-18 00:22:38 +00:00
|
|
|
|
switch (strength)
|
|
|
|
|
{
|
|
|
|
|
case UCOL_PRIMARY :
|
|
|
|
|
return Collator::PRIMARY;
|
|
|
|
|
case UCOL_SECONDARY :
|
|
|
|
|
return Collator::SECONDARY;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
case UCOL_TERTIARY :
|
2001-01-18 00:22:38 +00:00
|
|
|
|
return Collator::TERTIARY;
|
2001-02-10 02:55:38 +00:00
|
|
|
|
default :
|
|
|
|
|
return Collator::IDENTICAL;
|
2001-01-18 00:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline UCollationStrength RuleBasedCollator::getUCollationStrength(
|
|
|
|
|
const Collator::ECollationStrength &strength) const
|
2001-03-22 00:09:10 +00:00
|
|
|
|
{
|
2001-01-18 00:22:38 +00:00
|
|
|
|
switch (strength)
|
|
|
|
|
{
|
|
|
|
|
case Collator::PRIMARY :
|
|
|
|
|
return UCOL_PRIMARY;
|
|
|
|
|
case Collator::SECONDARY :
|
|
|
|
|
return UCOL_SECONDARY;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
case Collator::TERTIARY :
|
2001-01-18 00:22:38 +00:00
|
|
|
|
return UCOL_TERTIARY;
|
2001-02-10 02:55:38 +00:00
|
|
|
|
default :
|
|
|
|
|
return UCOL_IDENTICAL;
|
2001-01-18 00:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
|
#endif
|