2 ******************************************************************************
3 * Copyright (C) 1996-2013, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ******************************************************************************
10 * \brief C++ API: RuleBasedCollator class provides the simple implementation of Collator.
16 * Created by: Helena Shih
18 * Modification History:
20 * Date Name Description
21 * 2/5/97 aliu Added streamIn and streamOut methods. Added
22 * constructor which reads RuleBasedCollator object from
23 * a binary file. Added writeToFile method which streams
24 * RuleBasedCollator out to a binary file. The streamIn
25 * and streamOut methods use istream and ostream objects
27 * 2/12/97 aliu Modified to use TableCollationData sub-object to
28 * hold invariant data.
29 * 2/13/97 aliu Moved several methods into this class from Collation.
30 * Added a private RuleBasedCollator(Locale&) constructor,
31 * to be used by Collator::createDefault(). General
33 * 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
34 * constructor and getDynamicClassID.
35 * 3/5/97 aliu Modified constructFromFile() to add parameter
36 * specifying whether or not binary loading is to be
37 * attempted. This is required for dynamic rule loading.
38 * 05/07/97 helena Added memory allocation error detection.
39 * 6/17/97 helena Added IDENTICAL strength for compare, changed getRules to
40 * use MergeCollation::getPattern.
41 * 6/20/97 helena Java class name change.
42 * 8/18/97 helena Added internal API documentation.
43 * 09/03/97 helena Added createCollationKeyValues().
44 * 02/10/98 damiba Added compare with "length" parameter
45 * 08/05/98 erm Synched with 1.2 version of RuleBasedCollator.java
46 * 04/23/99 stephen Removed EDecompositionMode, merged with
48 * 06/14/99 stephen Removed kResourceBundleSuffix
49 * 11/02/99 helena Collator performance enhancements. Eliminates the
50 * UnicodeString construction and special case for NO_OP.
51 * 11/23/99 srl More performance enhancements. Updates to NormalizerIterator
52 * internal state management.
53 * 12/15/99 aliu Update to support Thai collation. Move NormalizerIterator
54 * to implementation file.
55 * 01/29/01 synwee Modified into a C++ wrapper which calls C API
62 #include "unicode/utypes.h"
65 #if !UCONFIG_NO_COLLATION
67 #include "unicode/coll.h"
68 #include "unicode/ucol.h"
69 #include "unicode/sortkey.h"
70 #include "unicode/normlzr.h"
81 class CollationElementIterator
;
84 * The RuleBasedCollator class provides the simple implementation of
85 * Collator, using data-driven tables. The user can create a customized
86 * table-based collation.
88 * <em>Important: </em>The ICU collation service has been reimplemented
89 * in order to achieve better performance and UCA compliance.
90 * For details, see the
91 * <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm">
92 * collation design document</a>.
94 * RuleBasedCollator is a thin C++ wrapper over the C implementation.
96 * For more information about the collation service see
97 * <a href="http://icu-project.org/userguide/Collate_Intro.html">the users guide</a>.
99 * Collation service provides correct sorting orders for most locales supported in ICU.
100 * If specific data for a locale is not available, the orders eventually falls back
101 * to the <a href="http://www.unicode.org/unicode/reports/tr10/">UCA sort order</a>.
103 * Sort ordering may be customized by providing your own set of rules. For more on
104 * this subject see the <a href="http://icu-project.org/userguide/Collate_Customization.html">
105 * Collation customization</a> section of the users guide.
107 * Note, RuleBasedCollator is not to be subclassed.
109 * @version 2.0 11/15/2001
111 class U_I18N_API RuleBasedCollator
: public Collator
115 // constructor -------------------------------------------------------------
118 * RuleBasedCollator constructor. This takes the table rules and builds a
119 * collation table out of them. Please see RuleBasedCollator class
120 * description for more details on the collation rule syntax.
121 * @param rules the collation rules to build the collation table from.
122 * @param status reporting a success or an error.
126 RuleBasedCollator(const UnicodeString
& rules
, UErrorCode
& status
);
129 * RuleBasedCollator constructor. This takes the table rules and builds a
130 * collation table out of them. Please see RuleBasedCollator class
131 * description for more details on the collation rule syntax.
132 * @param rules the collation rules to build the collation table from.
133 * @param collationStrength default strength for comparison
134 * @param status reporting a success or an error.
138 RuleBasedCollator(const UnicodeString
& rules
,
139 ECollationStrength collationStrength
,
143 * RuleBasedCollator constructor. This takes the table rules and builds a
144 * collation table out of them. Please see RuleBasedCollator class
145 * description for more details on the collation rule syntax.
146 * @param rules the collation rules to build the collation table from.
147 * @param decompositionMode the normalisation mode
148 * @param status reporting a success or an error.
152 RuleBasedCollator(const UnicodeString
& rules
,
153 UColAttributeValue decompositionMode
,
157 * RuleBasedCollator constructor. This takes the table rules and builds a
158 * collation table out of them. Please see RuleBasedCollator class
159 * description for more details on the collation rule syntax.
160 * @param rules the collation rules to build the collation table from.
161 * @param collationStrength default strength for comparison
162 * @param decompositionMode the normalisation mode
163 * @param status reporting a success or an error.
167 RuleBasedCollator(const UnicodeString
& rules
,
168 ECollationStrength collationStrength
,
169 UColAttributeValue decompositionMode
,
174 * @param other the RuleBasedCollator object to be copied
178 RuleBasedCollator(const RuleBasedCollator
& other
);
181 /** Opens a collator from a collator binary image created using
182 * cloneBinary. Binary image used in instantiation of the
183 * collator remains owned by the user and should stay around for
184 * the lifetime of the collator. The API also takes a base collator
185 * which usualy should be UCA.
186 * @param bin binary image owned by the user and required through the
187 * lifetime of the collator
188 * @param length size of the image. If negative, the API will try to
189 * figure out the length of the image
190 * @param base fallback collator, usually UCA. Base is required to be
191 * present through the lifetime of the collator. Currently
193 * @param status for catching errors
194 * @return newly created collator
198 RuleBasedCollator(const uint8_t *bin
, int32_t length
,
199 const RuleBasedCollator
*base
,
201 // destructor --------------------------------------------------------------
207 virtual ~RuleBasedCollator();
209 // public methods ----------------------------------------------------------
212 * Assignment operator.
213 * @param other other RuleBasedCollator object to compare with.
216 RuleBasedCollator
& operator=(const RuleBasedCollator
& other
);
219 * Returns true if argument is the same as this object.
220 * @param other Collator object to be compared.
221 * @return true if arguments is the same as this object.
224 virtual UBool
operator==(const Collator
& other
) const;
227 * Makes a copy of this object.
228 * @return a copy of this object, owned by the caller
231 virtual Collator
* clone(void) const;
234 * Creates a collation element iterator for the source string. The caller of
235 * this method is responsible for the memory management of the return
237 * @param source the string over which the CollationElementIterator will
239 * @return the collation element iterator of the source string using this as
240 * the based Collator.
243 virtual CollationElementIterator
* createCollationElementIterator(
244 const UnicodeString
& source
) const;
247 * Creates a collation element iterator for the source. The caller of this
248 * method is responsible for the memory management of the returned pointer.
249 * @param source the CharacterIterator which produces the characters over
250 * which the CollationElementItgerator will iterate.
251 * @return the collation element iterator of the source using this as the
255 virtual CollationElementIterator
* createCollationElementIterator(
256 const CharacterIterator
& source
) const;
258 // Make deprecated versions of Collator::compare() visible.
259 using Collator::compare
;
262 * The comparison function compares the character data stored in two
263 * different strings. Returns information about whether a string is less
264 * than, greater than or equal to another string.
265 * @param source the source string to be compared with.
266 * @param target the string that is to be compared with the source string.
267 * @param status possible error code
268 * @return Returns an enum value. UCOL_GREATER if source is greater
269 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
273 virtual UCollationResult
compare(const UnicodeString
& source
,
274 const UnicodeString
& target
,
275 UErrorCode
&status
) const;
278 * Does the same thing as compare but limits the comparison to a specified
280 * @param source the source string to be compared with.
281 * @param target the string that is to be compared with the source string.
282 * @param length the length the comparison is limited to
283 * @param status possible error code
284 * @return Returns an enum value. UCOL_GREATER if source (up to the specified
285 * length) is greater than target; UCOL_EQUAL if source (up to specified
286 * length) is equal to target; UCOL_LESS if source (up to the specified
287 * length) is less than target.
290 virtual UCollationResult
compare(const UnicodeString
& source
,
291 const UnicodeString
& target
,
293 UErrorCode
&status
) const;
296 * The comparison function compares the character data stored in two
297 * different string arrays. Returns information about whether a string array
298 * is less than, greater than or equal to another string array.
299 * @param source the source string array to be compared with.
300 * @param sourceLength the length of the source string array. If this value
301 * is equal to -1, the string array is null-terminated.
302 * @param target the string that is to be compared with the source string.
303 * @param targetLength the length of the target string array. If this value
304 * is equal to -1, the string array is null-terminated.
305 * @param status possible error code
306 * @return Returns an enum value. UCOL_GREATER if source is greater
307 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source is less
311 virtual UCollationResult
compare(const UChar
* source
, int32_t sourceLength
,
312 const UChar
* target
, int32_t targetLength
,
313 UErrorCode
&status
) const;
316 * Compares two strings using the Collator.
317 * Returns whether the first one compares less than/equal to/greater than
319 * This version takes UCharIterator input.
320 * @param sIter the first ("source") string iterator
321 * @param tIter the second ("target") string iterator
322 * @param status ICU status
323 * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER
326 virtual UCollationResult
compare(UCharIterator
&sIter
,
327 UCharIterator
&tIter
,
328 UErrorCode
&status
) const;
331 * Transforms a specified region of the string into a series of characters
332 * that can be compared with CollationKey.compare. Use a CollationKey when
333 * you need to do repeated comparisions on the same string. For a single
334 * comparison the compare method will be faster.
335 * @param source the source string.
336 * @param key the transformed key of the source string.
337 * @param status the error code status.
338 * @return the transformed key.
342 virtual CollationKey
& getCollationKey(const UnicodeString
& source
,
344 UErrorCode
& status
) const;
347 * Transforms a specified region of the string into a series of characters
348 * that can be compared with CollationKey.compare. Use a CollationKey when
349 * you need to do repeated comparisions on the same string. For a single
350 * comparison the compare method will be faster.
351 * @param source the source string.
352 * @param sourceLength the length of the source string.
353 * @param key the transformed key of the source string.
354 * @param status the error code status.
355 * @return the transformed key.
359 virtual CollationKey
& getCollationKey(const UChar
*source
,
360 int32_t sourceLength
,
362 UErrorCode
& status
) const;
365 * Generates the hash code for the rule-based collation object.
366 * @return the hash code.
369 virtual int32_t hashCode(void) const;
372 * Gets the locale of the Collator
373 * @param type can be either requested, valid or actual locale. For more
374 * information see the definition of ULocDataLocaleType in
376 * @param status the error code status.
377 * @return locale where the collation data lives. If the collator
378 * was instantiated from rules, locale is empty.
379 * @deprecated ICU 2.8 likely to change in ICU 3.0, based on feedback
381 virtual Locale
getLocale(ULocDataLocaleType type
, UErrorCode
& status
) const;
384 * Gets the tailoring rules for this collator.
385 * @return the collation tailoring from which this collator was created
388 const UnicodeString
& getRules(void) const;
391 * Gets the version information for a Collator.
392 * @param info the version # information, the result will be filled in
395 virtual void getVersion(UVersionInfo info
) const;
397 #ifndef U_HIDE_DEPRECATED_API
399 * Returns the maximum length of any expansion sequences that end with the
400 * specified comparison order.
402 * This is specific to the kind of collation element values and sequences
403 * returned by the CollationElementIterator.
404 * Call CollationElementIterator::getMaxExpansion() instead.
406 * @param order a collation order returned by CollationElementIterator::previous
407 * or CollationElementIterator::next.
408 * @return maximum size of the expansion sequences ending with the collation
409 * element, or 1 if the collation element does not occur at the end of
410 * any expansion sequence
411 * @see CollationElementIterator#getMaxExpansion
412 * @deprecated ICU 51 Use CollationElementIterator::getMaxExpansion() instead.
414 int32_t getMaxExpansion(int32_t order
) const;
415 #endif /* U_HIDE_DEPRECATED_API */
418 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
419 * method is to implement a simple version of RTTI, since not all C++
420 * compilers support genuine RTTI. Polymorphic operator==() and clone()
421 * methods call this method.
422 * @return The class ID for this object. All objects of a given class have
423 * the same class ID. Objects of other classes have different class
427 virtual UClassID
getDynamicClassID(void) const;
430 * Returns the class ID for this class. This is useful only for comparing to
431 * a return value from getDynamicClassID(). For example:
433 * Base* polymorphic_pointer = createPolymorphicObject();
434 * if (polymorphic_pointer->getDynamicClassID() ==
435 * Derived::getStaticClassID()) ...
437 * @return The class ID for all objects of this class.
440 static UClassID U_EXPORT2
getStaticClassID(void);
443 * Returns the binary format of the class's rules. The format is that of
445 * @param length Returns the length of the data, in bytes
446 * @param status the error code status.
447 * @return memory, owned by the caller, of size 'length' bytes.
450 uint8_t *cloneRuleData(int32_t &length
, UErrorCode
&status
);
453 /** Creates a binary image of a collator. This binary image can be stored and
454 * later used to instantiate a collator using ucol_openBinary.
455 * This API supports preflighting.
456 * @param buffer a fill-in buffer to receive the binary image
457 * @param capacity capacity of the destination buffer
458 * @param status for catching errors
459 * @return size of the image
460 * @see ucol_openBinary
463 int32_t cloneBinary(uint8_t *buffer
, int32_t capacity
, UErrorCode
&status
);
466 * Returns current rules. Delta defines whether full rules are returned or
467 * just the tailoring.
469 * getRules(void) should normally be used instead.
470 * See http://userguide.icu-project.org/collation/customization#TOC-Building-on-Existing-Locales
471 * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
472 * @param buffer UnicodeString to store the result rules
474 * @see UCOL_FULL_RULES
476 void getRules(UColRuleOption delta
, UnicodeString
&buffer
);
479 * Universal attribute setter
480 * @param attr attribute type
481 * @param value attribute value
482 * @param status to indicate whether the operation went on smoothly or there were errors
485 virtual void setAttribute(UColAttribute attr
, UColAttributeValue value
,
489 * Universal attribute getter.
490 * @param attr attribute type
491 * @param status to indicate whether the operation went on smoothly or there were errors
492 * @return attribute value
495 virtual UColAttributeValue
getAttribute(UColAttribute attr
,
496 UErrorCode
&status
) const;
499 * Sets the variable top to a collation element value of a string supplied.
500 * @param varTop one or more (if contraction) UChars to which the variable top should be set
501 * @param len length of variable top string. If -1 it is considered to be zero terminated.
502 * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
503 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such a contraction<br>
504 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
505 * @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
508 virtual uint32_t setVariableTop(const UChar
*varTop
, int32_t len
, UErrorCode
&status
);
511 * Sets the variable top to a collation element value of a string supplied.
512 * @param varTop an UnicodeString size 1 or more (if contraction) of UChars to which the variable top should be set
513 * @param status error code. If error code is set, the return value is undefined. Errors set by this function are: <br>
514 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such a contraction<br>
515 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more than two bytes
516 * @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
519 virtual uint32_t setVariableTop(const UnicodeString
&varTop
, UErrorCode
&status
);
522 * Sets the variable top to a collation element value supplied. Variable top is set to the upper 16 bits.
523 * Lower 16 bits are ignored.
524 * @param varTop CE value, as returned by setVariableTop or ucol)getVariableTop
525 * @param status error code (not changed by function)
528 virtual void setVariableTop(uint32_t varTop
, UErrorCode
&status
);
531 * Gets the variable top value of a Collator.
532 * Lower 16 bits are undefined and should be ignored.
533 * @param status error code (not changed by function). If error code is set, the return value is undefined.
536 virtual uint32_t getVariableTop(UErrorCode
&status
) const;
539 * Get an UnicodeSet that contains all the characters and sequences tailored in
541 * @param status error code of the operation
542 * @return a pointer to a UnicodeSet object containing all the
543 * code points and sequences that may sort differently than
544 * in the UCA. The object must be disposed of by using delete
547 virtual UnicodeSet
*getTailoredSet(UErrorCode
&status
) const;
550 * Get the sort key as an array of bytes from an UnicodeString.
551 * @param source string to be processed.
552 * @param result buffer to store result in. If NULL, number of bytes needed
554 * @param resultLength length of the result buffer. If if not enough the
555 * buffer will be filled to capacity.
556 * @return Number of bytes needed for storing the sort key
559 virtual int32_t getSortKey(const UnicodeString
& source
, uint8_t *result
,
560 int32_t resultLength
) const;
563 * Get the sort key as an array of bytes from an UChar buffer.
564 * @param source string to be processed.
565 * @param sourceLength length of string to be processed. If -1, the string
566 * is 0 terminated and length will be decided by the function.
567 * @param result buffer to store result in. If NULL, number of bytes needed
569 * @param resultLength length of the result buffer. If if not enough the
570 * buffer will be filled to capacity.
571 * @return Number of bytes needed for storing the sort key
574 virtual int32_t getSortKey(const UChar
*source
, int32_t sourceLength
,
575 uint8_t *result
, int32_t resultLength
) const;
578 * Retrieves the reordering codes for this collator.
579 * @param dest The array to fill with the script ordering.
580 * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
581 * will only return the length of the result without writing any of the result string (pre-flighting).
582 * @param status A reference to an error code value, which must not indicate
583 * a failure before the function call.
584 * @return The length of the script ordering array.
585 * @see ucol_setReorderCodes
586 * @see Collator#getEquivalentReorderCodes
587 * @see Collator#setReorderCodes
590 virtual int32_t getReorderCodes(int32_t *dest
,
591 int32_t destCapacity
,
592 UErrorCode
& status
) const;
595 * Sets the ordering of scripts for this collator.
596 * @param reorderCodes An array of script codes in the new order. This can be NULL if the
597 * length is also set to 0. An empty array will clear any reordering codes on the collator.
598 * @param reorderCodesLength The length of reorderCodes.
599 * @param status error code
600 * @see Collator#getReorderCodes
601 * @see Collator#getEquivalentReorderCodes
604 virtual void setReorderCodes(const int32_t* reorderCodes
,
605 int32_t reorderCodesLength
,
606 UErrorCode
& status
) ;
609 * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
610 * codes will be grouped and must reorder together.
611 * @param reorderCode The reorder code to determine equivalence for.
612 * @param dest The array to fill with the script equivalene reordering codes.
613 * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the
614 * function will only return the length of the result without writing any of the result
615 * string (pre-flighting).
616 * @param status A reference to an error code value, which must not indicate
617 * a failure before the function call.
618 * @return The length of the of the reordering code equivalence array.
619 * @see ucol_setReorderCodes
620 * @see Collator#getReorderCodes
621 * @see Collator#setReorderCodes
624 static int32_t U_EXPORT2
getEquivalentReorderCodes(int32_t reorderCode
,
626 int32_t destCapacity
,
631 // private static constants -----------------------------------------------
634 /* need look up in .commit() */
635 CHARINDEX
= 0x70000000,
636 /* Expand index follows */
637 EXPANDCHARINDEX
= 0x7E000000,
638 /* contract indexes follows */
639 CONTRACTCHARINDEX
= 0x7F000000,
640 /* unmapped character values */
641 UNMAPPED
= 0xFFFFFFFF,
642 /* primary strength increment */
643 PRIMARYORDERINCREMENT
= 0x00010000,
644 /* secondary strength increment */
645 SECONDARYORDERINCREMENT
= 0x00000100,
646 /* tertiary strength increment */
647 TERTIARYORDERINCREMENT
= 0x00000001,
648 /* mask off anything but primary order */
649 PRIMARYORDERMASK
= 0xffff0000,
650 /* mask off anything but secondary order */
651 SECONDARYORDERMASK
= 0x0000ff00,
652 /* mask off anything but tertiary order */
653 TERTIARYORDERMASK
= 0x000000ff,
654 /* mask off ignorable char order */
655 IGNORABLEMASK
= 0x0000ffff,
656 /* use only the primary difference */
657 PRIMARYDIFFERENCEONLY
= 0xffff0000,
658 /* use only the primary and secondary difference */
659 SECONDARYDIFFERENCEONLY
= 0xffffff00,
660 /* primary order shift */
661 PRIMARYORDERSHIFT
= 16,
662 /* secondary order shift */
663 SECONDARYORDERSHIFT
= 8,
664 /* starting value for collation elements */
665 COLELEMENTSTART
= 0x02020202,
666 /* testing mask for primary low element */
667 PRIMARYLOWZEROMASK
= 0x00FF0000,
668 /* reseting value for secondaries and tertiaries */
669 RESETSECONDARYTERTIARY
= 0x00000202,
670 /* reseting value for tertiaries */
671 RESETTERTIARY
= 0x00000002,
673 PRIMIGNORABLE
= 0x0202
676 // private data members ---------------------------------------------------
680 UBool isWriteThroughAlias
;
683 * c struct for collation. All initialisation for it has to be done through
686 UCollator
*ucollator
;
691 UnicodeString urulestring
;
693 // friend classes --------------------------------------------------------
696 * Used to iterate over collation elements in a character source.
698 friend class CollationElementIterator
;
701 * Collator ONLY needs access to RuleBasedCollator(const Locale&,
704 friend class Collator
;
707 * Searching over collation elements in a character source
709 friend class StringSearch
;
711 // private constructors --------------------------------------------------
714 * Default constructor
719 * RuleBasedCollator constructor. This constructor takes a locale. The
720 * only caller of this class should be Collator::createInstance(). If
721 * createInstance() happens to know that the requested locale's collation is
722 * implemented as a RuleBasedCollator, it can then call this constructor.
723 * OTHERWISE IT SHOULDN'T, since this constructor ALWAYS RETURNS A VALID
724 * COLLATION TABLE. It does this by falling back to defaults.
725 * @param desiredLocale locale used
726 * @param status error code status
728 RuleBasedCollator(const Locale
& desiredLocale
, UErrorCode
& status
);
731 * common constructor implementation
733 * @param rules the collation rules to build the collation table from.
734 * @param collationStrength default strength for comparison
735 * @param decompositionMode the normalisation mode
736 * @param status reporting a success or an error.
739 construct(const UnicodeString
& rules
,
740 UColAttributeValue collationStrength
,
741 UColAttributeValue decompositionMode
,
744 // private methods -------------------------------------------------------
747 * Creates the c struct for ucollator
748 * @param locale desired locale
749 * @param status error status
751 void setUCollator(const Locale
& locale
, UErrorCode
& status
);
754 * Creates the c struct for ucollator
755 * @param locale desired locale name
756 * @param status error status
758 void setUCollator(const char* locale
, UErrorCode
& status
);
761 * Creates the c struct for ucollator. This used internally by StringSearch.
762 * Hence the responsibility of cleaning up the ucollator is not done by
763 * this RuleBasedCollator. The isDataOwned flag is set to FALSE.
764 * @param collator new ucollator data
766 void setUCollator(UCollator
*collator
);
769 #ifndef U_HIDE_INTERNAL_API
771 * Get UCollator data struct. Used only by StringSearch & intltest.
772 * @return UCollator data struct
775 const UCollator
* getUCollator();
776 #endif /* U_HIDE_INTERNAL_API */
780 * Used internally by registraton to define the requested and valid locales.
781 * @param requestedLocale the requsted locale
782 * @param validLocale the valid locale
783 * @param actualLocale the actual locale
786 virtual void setLocales(const Locale
& requestedLocale
, const Locale
& validLocale
, const Locale
& actualLocale
);
789 // if not owned and not a write through alias, copy the ucollator
790 void checkOwned(void);
792 // utility to init rule string used by checkOwned and construct
793 void setRuleStringFromCollator();
796 /** Get the short definition string for a collator. This internal API harvests the collator's
797 * locale and the attribute set and produces a string that can be used for opening
798 * a collator with the same properties using the ucol_openFromShortString API.
799 * This string will be normalized.
800 * The structure and the syntax of the string is defined in the "Naming collators"
801 * section of the users guide:
802 * http://icu-project.org/userguide/Collate_Concepts.html#Naming_Collators
803 * This function supports preflighting.
805 * This is internal, and intended to be used with delegate converters.
807 * @param locale a locale that will appear as a collators locale in the resulting
808 * short string definition. If NULL, the locale will be harvested
810 * @param buffer space to hold the resulting string
811 * @param capacity capacity of the buffer
812 * @param status for returning errors. All the preflighting errors are featured
813 * @return length of the resulting string
814 * @see ucol_openFromShortString
815 * @see ucol_normalizeShortDefinitionString
816 * @see ucol_getShortDefinitionString
819 virtual int32_t internalGetShortDefinitionString(const char *locale
,
822 UErrorCode
&status
) const;
825 // inline method implementation ---------------------------------------------
827 inline void RuleBasedCollator::setUCollator(const Locale
&locale
,
830 setUCollator(locale
.getName(), status
);
834 inline void RuleBasedCollator::setUCollator(UCollator
*collator
)
837 if (ucollator
&& dataIsOwned
) {
838 ucol_close(ucollator
);
840 ucollator
= collator
;
842 isWriteThroughAlias
= TRUE
;
843 setRuleStringFromCollator();
846 inline const UCollator
* RuleBasedCollator::getUCollator()
853 #endif /* #if !UCONFIG_NO_COLLATION */