OLD | NEW |
1 /* | 1 /* |
2 ****************************************************************************** | 2 ****************************************************************************** |
3 * Copyright (C) 1996-2013, International Business Machines Corporation and | 3 * Copyright (C) 1996-2014, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ****************************************************************************** | 5 ****************************************************************************** |
6 */ | 6 */ |
7 | 7 |
8 /** | 8 /** |
9 * \file | 9 * \file |
10 * \brief C++ API: RuleBasedCollator class provides the simple implementation of
Collator. | 10 * \brief C++ API: The RuleBasedCollator class implements the Collator abstract
base class. |
11 */ | 11 */ |
12 | 12 |
13 /** | 13 /** |
14 * File tblcoll.h | 14 * File tblcoll.h |
15 * | 15 * |
16 * Created by: Helena Shih | 16 * Created by: Helena Shih |
17 * | 17 * |
18 * Modification History: | 18 * Modification History: |
19 * | 19 * |
20 * Date Name Description | 20 * Date Name Description |
(...skipping 26 matching lines...) Expand all Loading... |
47 * Normalizer::EMode | 47 * Normalizer::EMode |
48 * 06/14/99 stephen Removed kResourceBundleSuffix | 48 * 06/14/99 stephen Removed kResourceBundleSuffix |
49 * 11/02/99 helena Collator performance enhancements. Eliminates the | 49 * 11/02/99 helena Collator performance enhancements. Eliminates the |
50 * UnicodeString construction and special case for NO_OP
. | 50 * UnicodeString construction and special case for NO_OP
. |
51 * 11/23/99 srl More performance enhancements. Updates to NormalizerI
terator | 51 * 11/23/99 srl More performance enhancements. Updates to NormalizerI
terator |
52 * internal state management. | 52 * internal state management. |
53 * 12/15/99 aliu Update to support Thai collation. Move NormalizerIte
rator | 53 * 12/15/99 aliu Update to support Thai collation. Move NormalizerIte
rator |
54 * to implementation file. | 54 * to implementation file. |
55 * 01/29/01 synwee Modified into a C++ wrapper which calls C API | 55 * 01/29/01 synwee Modified into a C++ wrapper which calls C API |
56 * (ucol.h) | 56 * (ucol.h) |
| 57 * 2012-2014 markus Rewritten in C++ again. |
57 */ | 58 */ |
58 | 59 |
59 #ifndef TBLCOLL_H | 60 #ifndef TBLCOLL_H |
60 #define TBLCOLL_H | 61 #define TBLCOLL_H |
61 | 62 |
62 #include "unicode/utypes.h" | 63 #include "unicode/utypes.h" |
63 | 64 |
64 | |
65 #if !UCONFIG_NO_COLLATION | 65 #if !UCONFIG_NO_COLLATION |
66 | 66 |
67 #include "unicode/coll.h" | 67 #include "unicode/coll.h" |
| 68 #include "unicode/locid.h" |
| 69 #include "unicode/uiter.h" |
68 #include "unicode/ucol.h" | 70 #include "unicode/ucol.h" |
69 #include "unicode/sortkey.h" | |
70 #include "unicode/normlzr.h" | |
71 | 71 |
72 U_NAMESPACE_BEGIN | 72 U_NAMESPACE_BEGIN |
73 | 73 |
| 74 struct CollationCacheEntry; |
| 75 struct CollationData; |
| 76 struct CollationSettings; |
| 77 struct CollationTailoring; |
74 /** | 78 /** |
75 * @stable ICU 2.0 | 79 * @stable ICU 2.0 |
76 */ | 80 */ |
77 class StringSearch; | 81 class StringSearch; |
78 /** | 82 /** |
79 * @stable ICU 2.0 | 83 * @stable ICU 2.0 |
80 */ | 84 */ |
81 class CollationElementIterator; | 85 class CollationElementIterator; |
| 86 class CollationKey; |
| 87 class SortKeyByteSink; |
| 88 class UnicodeSet; |
| 89 class UnicodeString; |
| 90 class UVector64; |
82 | 91 |
83 /** | 92 /** |
84 * The RuleBasedCollator class provides the simple implementation of | 93 * The RuleBasedCollator class provides the implementation of |
85 * Collator, using data-driven tables. The user can create a customized | 94 * Collator, using data-driven tables. The user can create a customized |
86 * table-based collation. | 95 * table-based collation. |
87 * <P> | |
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/collati
on/ICU_collation_design.htm"> | |
92 * collation design document</a>. | |
93 * <p> | |
94 * RuleBasedCollator is a thin C++ wrapper over the C implementation. | |
95 * <p> | 96 * <p> |
96 * For more information about the collation service see | 97 * For more information about the collation service see |
97 * <a href="http://icu-project.org/userguide/Collate_Intro.html">the users guide
</a>. | 98 * <a href="http://userguide.icu-project.org/collation">the User Guide</a>. |
98 * <p> | 99 * <p> |
99 * Collation service provides correct sorting orders for most locales supported
in ICU. | 100 * 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 b
ack | 101 * If specific data for a locale is not available, the orders eventually falls b
ack |
101 * to the <a href="http://www.unicode.org/unicode/reports/tr10/">UCA sort order<
/a>. | 102 * to the <a href="http://www.unicode.org/reports/tr35/tr35-collation.html#Root_
Collation">CLDR root sort order</a>. |
102 * <p> | 103 * <p> |
103 * Sort ordering may be customized by providing your own set of rules. For more
on | 104 * 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_Custom
ization.html"> | 105 * this subject see the <a href="http://userguide.icu-project.org/collation/cust
omization"> |
105 * Collation customization</a> section of the users guide. | 106 * Collation Customization</a> section of the User Guide. |
106 * <p> | 107 * <p> |
107 * Note, RuleBasedCollator is not to be subclassed. | 108 * Note, RuleBasedCollator is not to be subclassed. |
108 * @see Collator | 109 * @see Collator |
109 * @version 2.0 11/15/2001 | |
110 */ | 110 */ |
111 class U_I18N_API RuleBasedCollator : public Collator | 111 class U_I18N_API RuleBasedCollator : public Collator { |
112 { | |
113 public: | 112 public: |
114 | |
115 // constructor ------------------------------------------------------------- | |
116 | |
117 /** | 113 /** |
118 * RuleBasedCollator constructor. This takes the table rules and builds a | 114 * RuleBasedCollator constructor. This takes the table rules and builds a |
119 * collation table out of them. Please see RuleBasedCollator class | 115 * collation table out of them. Please see RuleBasedCollator class |
120 * description for more details on the collation rule syntax. | 116 * description for more details on the collation rule syntax. |
121 * @param rules the collation rules to build the collation table from. | 117 * @param rules the collation rules to build the collation table from. |
122 * @param status reporting a success or an error. | 118 * @param status reporting a success or an error. |
123 * @see Locale | |
124 * @stable ICU 2.0 | 119 * @stable ICU 2.0 |
125 */ | 120 */ |
126 RuleBasedCollator(const UnicodeString& rules, UErrorCode& status); | 121 RuleBasedCollator(const UnicodeString& rules, UErrorCode& status); |
127 | 122 |
128 /** | 123 /** |
129 * RuleBasedCollator constructor. This takes the table rules and builds a | 124 * RuleBasedCollator constructor. This takes the table rules and builds a |
130 * collation table out of them. Please see RuleBasedCollator class | 125 * collation table out of them. Please see RuleBasedCollator class |
131 * description for more details on the collation rule syntax. | 126 * description for more details on the collation rule syntax. |
132 * @param rules the collation rules to build the collation table from. | 127 * @param rules the collation rules to build the collation table from. |
133 * @param collationStrength default strength for comparison | 128 * @param collationStrength strength for comparison |
134 * @param status reporting a success or an error. | 129 * @param status reporting a success or an error. |
135 * @see Locale | |
136 * @stable ICU 2.0 | 130 * @stable ICU 2.0 |
137 */ | 131 */ |
138 RuleBasedCollator(const UnicodeString& rules, | 132 RuleBasedCollator(const UnicodeString& rules, |
139 ECollationStrength collationStrength, | 133 ECollationStrength collationStrength, |
140 UErrorCode& status); | 134 UErrorCode& status); |
141 | 135 |
142 /** | 136 /** |
143 * RuleBasedCollator constructor. This takes the table rules and builds a | 137 * RuleBasedCollator constructor. This takes the table rules and builds a |
144 * collation table out of them. Please see RuleBasedCollator class | 138 * collation table out of them. Please see RuleBasedCollator class |
145 * description for more details on the collation rule syntax. | 139 * description for more details on the collation rule syntax. |
146 * @param rules the collation rules to build the collation table from. | 140 * @param rules the collation rules to build the collation table from. |
147 * @param decompositionMode the normalisation mode | 141 * @param decompositionMode the normalisation mode |
148 * @param status reporting a success or an error. | 142 * @param status reporting a success or an error. |
149 * @see Locale | |
150 * @stable ICU 2.0 | 143 * @stable ICU 2.0 |
151 */ | 144 */ |
152 RuleBasedCollator(const UnicodeString& rules, | 145 RuleBasedCollator(const UnicodeString& rules, |
153 UColAttributeValue decompositionMode, | 146 UColAttributeValue decompositionMode, |
154 UErrorCode& status); | 147 UErrorCode& status); |
155 | 148 |
156 /** | 149 /** |
157 * RuleBasedCollator constructor. This takes the table rules and builds a | 150 * RuleBasedCollator constructor. This takes the table rules and builds a |
158 * collation table out of them. Please see RuleBasedCollator class | 151 * collation table out of them. Please see RuleBasedCollator class |
159 * description for more details on the collation rule syntax. | 152 * description for more details on the collation rule syntax. |
160 * @param rules the collation rules to build the collation table from. | 153 * @param rules the collation rules to build the collation table from. |
161 * @param collationStrength default strength for comparison | 154 * @param collationStrength strength for comparison |
162 * @param decompositionMode the normalisation mode | 155 * @param decompositionMode the normalisation mode |
163 * @param status reporting a success or an error. | 156 * @param status reporting a success or an error. |
164 * @see Locale | |
165 * @stable ICU 2.0 | 157 * @stable ICU 2.0 |
166 */ | 158 */ |
167 RuleBasedCollator(const UnicodeString& rules, | 159 RuleBasedCollator(const UnicodeString& rules, |
168 ECollationStrength collationStrength, | 160 ECollationStrength collationStrength, |
169 UColAttributeValue decompositionMode, | 161 UColAttributeValue decompositionMode, |
170 UErrorCode& status); | 162 UErrorCode& status); |
171 | 163 |
| 164 #ifndef U_HIDE_INTERNAL_API |
| 165 /** |
| 166 * TODO: document & propose as public API |
| 167 * @internal |
| 168 */ |
| 169 RuleBasedCollator(const UnicodeString &rules, |
| 170 UParseError &parseError, UnicodeString &reason, |
| 171 UErrorCode &errorCode); |
| 172 #endif /* U_HIDE_INTERNAL_API */ |
| 173 |
172 /** | 174 /** |
173 * Copy constructor. | 175 * Copy constructor. |
174 * @param other the RuleBasedCollator object to be copied | 176 * @param other the RuleBasedCollator object to be copied |
175 * @see Locale | |
176 * @stable ICU 2.0 | 177 * @stable ICU 2.0 |
177 */ | 178 */ |
178 RuleBasedCollator(const RuleBasedCollator& other); | 179 RuleBasedCollator(const RuleBasedCollator& other); |
179 | 180 |
180 | 181 |
181 /** Opens a collator from a collator binary image created using | 182 /** Opens a collator from a collator binary image created using |
182 * cloneBinary. Binary image used in instantiation of the | 183 * cloneBinary. Binary image used in instantiation of the |
183 * collator remains owned by the user and should stay around for | 184 * 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 * the lifetime of the collator. The API also takes a base collator |
185 * which usualy should be UCA. | 186 * which must be the root collator. |
186 * @param bin binary image owned by the user and required through the | 187 * @param bin binary image owned by the user and required through the |
187 * lifetime of the collator | 188 * lifetime of the collator |
188 * @param length size of the image. If negative, the API will try to | 189 * @param length size of the image. If negative, the API will try to |
189 * figure out the length of the image | 190 * figure out the length of the image |
190 * @param base fallback collator, usually UCA. Base is required to be | 191 * @param base Base collator, for lookup of untailored characters. |
191 * present through the lifetime of the collator. Currently | 192 * Must be the root collator, must not be NULL. |
192 * it cannot be NULL. | 193 * The base is required to be present through the lifetime of th
e collator. |
193 * @param status for catching errors | 194 * @param status for catching errors |
194 * @return newly created collator | 195 * @return newly created collator |
195 * @see cloneBinary | 196 * @see cloneBinary |
196 * @stable ICU 3.4 | 197 * @stable ICU 3.4 |
197 */ | 198 */ |
198 RuleBasedCollator(const uint8_t *bin, int32_t length, | 199 RuleBasedCollator(const uint8_t *bin, int32_t length, |
199 const RuleBasedCollator *base, | 200 const RuleBasedCollator *base, |
200 UErrorCode &status); | 201 UErrorCode &status); |
201 // destructor -------------------------------------------------------------- | |
202 | 202 |
203 /** | 203 /** |
204 * Destructor. | 204 * Destructor. |
205 * @stable ICU 2.0 | 205 * @stable ICU 2.0 |
206 */ | 206 */ |
207 virtual ~RuleBasedCollator(); | 207 virtual ~RuleBasedCollator(); |
208 | 208 |
209 // public methods ---------------------------------------------------------- | |
210 | |
211 /** | 209 /** |
212 * Assignment operator. | 210 * Assignment operator. |
213 * @param other other RuleBasedCollator object to compare with. | 211 * @param other other RuleBasedCollator object to copy from. |
214 * @stable ICU 2.0 | 212 * @stable ICU 2.0 |
215 */ | 213 */ |
216 RuleBasedCollator& operator=(const RuleBasedCollator& other); | 214 RuleBasedCollator& operator=(const RuleBasedCollator& other); |
217 | 215 |
218 /** | 216 /** |
219 * Returns true if argument is the same as this object. | 217 * Returns true if argument is the same as this object. |
220 * @param other Collator object to be compared. | 218 * @param other Collator object to be compared. |
221 * @return true if arguments is the same as this object. | 219 * @return true if arguments is the same as this object. |
222 * @stable ICU 2.0 | 220 * @stable ICU 2.0 |
223 */ | 221 */ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 * than, greater than or equal to another string. | 262 * than, greater than or equal to another string. |
265 * @param source the source string to be compared with. | 263 * @param source the source string to be compared with. |
266 * @param target the string that is to be compared with the source string. | 264 * @param target the string that is to be compared with the source string. |
267 * @param status possible error code | 265 * @param status possible error code |
268 * @return Returns an enum value. UCOL_GREATER if source is greater | 266 * @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 | 267 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source
is less |
270 * than target | 268 * than target |
271 * @stable ICU 2.6 | 269 * @stable ICU 2.6 |
272 **/ | 270 **/ |
273 virtual UCollationResult compare(const UnicodeString& source, | 271 virtual UCollationResult compare(const UnicodeString& source, |
274 const UnicodeString& target, | 272 const UnicodeString& target, |
275 UErrorCode &status) const; | 273 UErrorCode &status) const; |
276 | 274 |
277 /** | 275 /** |
278 * Does the same thing as compare but limits the comparison to a specified | 276 * Does the same thing as compare but limits the comparison to a specified |
279 * length | 277 * length |
280 * @param source the source string to be compared with. | 278 * @param source the source string to be compared with. |
281 * @param target the string that is to be compared with the source string. | 279 * @param target the string that is to be compared with the source string. |
282 * @param length the length the comparison is limited to | 280 * @param length the length the comparison is limited to |
283 * @param status possible error code | 281 * @param status possible error code |
284 * @return Returns an enum value. UCOL_GREATER if source (up to the specified
| 282 * @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 specif
ied | 283 * length) is greater than target; UCOL_EQUAL if source (up to specif
ied |
286 * length) is equal to target; UCOL_LESS if source (up to the specifi
ed | 284 * length) is equal to target; UCOL_LESS if source (up to the specifi
ed |
287 * length) is less than target. | 285 * length) is less than target. |
288 * @stable ICU 2.6 | 286 * @stable ICU 2.6 |
289 */ | 287 */ |
290 virtual UCollationResult compare(const UnicodeString& source, | 288 virtual UCollationResult compare(const UnicodeString& source, |
291 const UnicodeString& target, | 289 const UnicodeString& target, |
292 int32_t length, | 290 int32_t length, |
293 UErrorCode &status) const; | 291 UErrorCode &status) const; |
294 | 292 |
295 /** | 293 /** |
296 * The comparison function compares the character data stored in two | 294 * The comparison function compares the character data stored in two |
297 * different string arrays. Returns information about whether a string array | 295 * different string arrays. Returns information about whether a string array |
298 * is less than, greater than or equal to another string array. | 296 * is less than, greater than or equal to another string array. |
299 * @param source the source string array to be compared with. | 297 * @param source the source string array to be compared with. |
300 * @param sourceLength the length of the source string array. If this value | 298 * @param sourceLength the length of the source string array. If this value |
301 * is equal to -1, the string array is null-terminated. | 299 * is equal to -1, the string array is null-terminated. |
302 * @param target the string that is to be compared with the source string. | 300 * @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 | 301 * @param targetLength the length of the target string array. If this value |
304 * is equal to -1, the string array is null-terminated. | 302 * is equal to -1, the string array is null-terminated. |
305 * @param status possible error code | 303 * @param status possible error code |
306 * @return Returns an enum value. UCOL_GREATER if source is greater | 304 * @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 | 305 * than target; UCOL_EQUAL if source is equal to target; UCOL_LESS if source
is less |
308 * than target | 306 * than target |
309 * @stable ICU 2.6 | 307 * @stable ICU 2.6 |
310 */ | 308 */ |
311 virtual UCollationResult compare(const UChar* source, int32_t sourceLength, | 309 virtual UCollationResult compare(const UChar* source, int32_t sourceLength, |
312 const UChar* target, int32_t targetLength, | 310 const UChar* target, int32_t targetLength, |
313 UErrorCode &status) const; | 311 UErrorCode &status) const; |
314 | 312 |
315 /** | 313 /** |
316 * Compares two strings using the Collator. | 314 * Compares two strings using the Collator. |
317 * Returns whether the first one compares less than/equal to/greater than | 315 * Returns whether the first one compares less than/equal to/greater than |
318 * the second one. | 316 * the second one. |
319 * This version takes UCharIterator input. | 317 * This version takes UCharIterator input. |
320 * @param sIter the first ("source") string iterator | 318 * @param sIter the first ("source") string iterator |
321 * @param tIter the second ("target") string iterator | 319 * @param tIter the second ("target") string iterator |
322 * @param status ICU status | 320 * @param status ICU status |
323 * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER | 321 * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER |
324 * @stable ICU 4.2 | 322 * @stable ICU 4.2 |
325 */ | 323 */ |
326 virtual UCollationResult compare(UCharIterator &sIter, | 324 virtual UCollationResult compare(UCharIterator &sIter, |
327 UCharIterator &tIter, | 325 UCharIterator &tIter, |
328 UErrorCode &status) const; | 326 UErrorCode &status) const; |
329 | 327 |
330 /** | 328 /** |
331 * Transforms a specified region of the string into a series of characters | 329 * Compares two UTF-8 strings using the Collator. |
332 * that can be compared with CollationKey.compare. Use a CollationKey when | 330 * Returns whether the first one compares less than/equal to/greater than |
333 * you need to do repeated comparisions on the same string. For a single | 331 * the second one. |
334 * comparison the compare method will be faster. | 332 * This version takes UTF-8 input. |
335 * @param source the source string. | 333 * Note that a StringPiece can be implicitly constructed |
336 * @param key the transformed key of the source string. | 334 * from a std::string or a NUL-terminated const char * string. |
337 * @param status the error code status. | 335 * @param source the first UTF-8 string |
338 * @return the transformed key. | 336 * @param target the second UTF-8 string |
339 * @see CollationKey | 337 * @param status ICU status |
340 * @stable ICU 2.0 | 338 * @return UCOL_LESS, UCOL_EQUAL or UCOL_GREATER |
341 */ | 339 * @stable ICU 51 |
| 340 */ |
| 341 virtual UCollationResult compareUTF8(const StringPiece &source, |
| 342 const StringPiece &target, |
| 343 UErrorCode &status) const; |
| 344 |
| 345 /** |
| 346 * Transforms the string into a series of characters |
| 347 * that can be compared with CollationKey.compare(). |
| 348 * |
| 349 * Note that sort keys are often less efficient than simply doing comparison
. |
| 350 * For more details, see the ICU User Guide. |
| 351 * |
| 352 * @param source 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. |
| 356 * @see CollationKey |
| 357 * @stable ICU 2.0 |
| 358 */ |
342 virtual CollationKey& getCollationKey(const UnicodeString& source, | 359 virtual CollationKey& getCollationKey(const UnicodeString& source, |
343 CollationKey& key, | 360 CollationKey& key, |
344 UErrorCode& status) const; | 361 UErrorCode& status) const; |
345 | 362 |
346 /** | 363 /** |
347 * Transforms a specified region of the string into a series of characters | 364 * Transforms a specified region of the string into a series of characters |
348 * that can be compared with CollationKey.compare. Use a CollationKey when | 365 * that can be compared with CollationKey.compare. |
349 * you need to do repeated comparisions on the same string. For a single | 366 * |
350 * comparison the compare method will be faster. | 367 * Note that sort keys are often less efficient than simply doing comparison
. |
351 * @param source the source string. | 368 * For more details, see the ICU User Guide. |
352 * @param sourceLength the length of the source string. | 369 * |
353 * @param key the transformed key of the source string. | 370 * @param source the source string. |
354 * @param status the error code status. | 371 * @param sourceLength the length of the source string. |
355 * @return the transformed key. | 372 * @param key the transformed key of the source string. |
356 * @see CollationKey | 373 * @param status the error code status. |
357 * @stable ICU 2.0 | 374 * @return the transformed key. |
358 */ | 375 * @see CollationKey |
| 376 * @stable ICU 2.0 |
| 377 */ |
359 virtual CollationKey& getCollationKey(const UChar *source, | 378 virtual CollationKey& getCollationKey(const UChar *source, |
360 int32_t sourceLength, | 379 int32_t sourceLength, |
361 CollationKey& key, | 380 CollationKey& key, |
362 UErrorCode& status) const; | 381 UErrorCode& status) const; |
363 | 382 |
364 /** | 383 /** |
365 * Generates the hash code for the rule-based collation object. | 384 * Generates the hash code for the rule-based collation object. |
366 * @return the hash code. | 385 * @return the hash code. |
367 * @stable ICU 2.0 | 386 * @stable ICU 2.0 |
368 */ | 387 */ |
369 virtual int32_t hashCode(void) const; | 388 virtual int32_t hashCode() const; |
370 | 389 |
371 /** | 390 /** |
372 * Gets the locale of the Collator | 391 * Gets the locale of the Collator |
373 * @param type can be either requested, valid or actual locale. For more | 392 * @param type can be either requested, valid or actual locale. For more |
374 * information see the definition of ULocDataLocaleType in | 393 * information see the definition of ULocDataLocaleType in |
375 * uloc.h | 394 * uloc.h |
376 * @param status the error code status. | 395 * @param status the error code status. |
377 * @return locale where the collation data lives. If the collator | 396 * @return locale where the collation data lives. If the collator |
378 * was instantiated from rules, locale is empty. | 397 * was instantiated from rules, locale is empty. |
379 * @deprecated ICU 2.8 likely to change in ICU 3.0, based on feedback | 398 * @deprecated ICU 2.8 likely to change in ICU 3.0, based on feedback |
380 */ | 399 */ |
381 virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; | 400 virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; |
382 | 401 |
383 /** | 402 /** |
384 * Gets the tailoring rules for this collator. | 403 * Gets the tailoring rules for this collator. |
385 * @return the collation tailoring from which this collator was created | 404 * @return the collation tailoring from which this collator was created |
386 * @stable ICU 2.0 | 405 * @stable ICU 2.0 |
387 */ | 406 */ |
388 const UnicodeString& getRules(void) const; | 407 const UnicodeString& getRules() const; |
389 | 408 |
390 /** | 409 /** |
391 * Gets the version information for a Collator. | 410 * Gets the version information for a Collator. |
392 * @param info the version # information, the result will be filled in | 411 * @param info the version # information, the result will be filled in |
393 * @stable ICU 2.0 | 412 * @stable ICU 2.0 |
394 */ | 413 */ |
395 virtual void getVersion(UVersionInfo info) const; | 414 virtual void getVersion(UVersionInfo info) const; |
396 | 415 |
397 #ifndef U_HIDE_DEPRECATED_API | 416 #ifndef U_HIDE_DEPRECATED_API |
398 /** | 417 /** |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 /** | 462 /** |
444 * Do not use this method: The caller and the ICU library might use differen
t heaps. | 463 * Do not use this method: The caller and the ICU library might use differen
t heaps. |
445 * Use cloneBinary() instead which writes to caller-provided memory. | 464 * Use cloneBinary() instead which writes to caller-provided memory. |
446 * | 465 * |
447 * Returns a binary format of this collator. | 466 * Returns a binary format of this collator. |
448 * @param length Returns the length of the data, in bytes | 467 * @param length Returns the length of the data, in bytes |
449 * @param status the error code status. | 468 * @param status the error code status. |
450 * @return memory, owned by the caller, of size 'length' bytes. | 469 * @return memory, owned by the caller, of size 'length' bytes. |
451 * @deprecated ICU 52. Use cloneBinary() instead. | 470 * @deprecated ICU 52. Use cloneBinary() instead. |
452 */ | 471 */ |
453 uint8_t *cloneRuleData(int32_t &length, UErrorCode &status); | 472 uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const; |
454 #endif /* U_HIDE_DEPRECATED_API */ | 473 #endif /* U_HIDE_DEPRECATED_API */ |
455 | 474 |
456 /** Creates a binary image of a collator. This binary image can be stored an
d | 475 /** Creates a binary image of a collator. This binary image can be stored an
d |
457 * later used to instantiate a collator using ucol_openBinary. | 476 * later used to instantiate a collator using ucol_openBinary. |
458 * This API supports preflighting. | 477 * This API supports preflighting. |
459 * @param buffer a fill-in buffer to receive the binary image | 478 * @param buffer a fill-in buffer to receive the binary image |
460 * @param capacity capacity of the destination buffer | 479 * @param capacity capacity of the destination buffer |
461 * @param status for catching errors | 480 * @param status for catching errors |
462 * @return size of the image | 481 * @return size of the image |
463 * @see ucol_openBinary | 482 * @see ucol_openBinary |
464 * @stable ICU 3.4 | 483 * @stable ICU 3.4 |
465 */ | 484 */ |
466 int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status); | 485 int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) c
onst; |
467 | 486 |
468 /** | 487 /** |
469 * Returns current rules. Delta defines whether full rules are returned or | 488 * Returns current rules. Delta defines whether full rules are returned or |
470 * just the tailoring. | 489 * just the tailoring. |
471 * | 490 * |
472 * getRules(void) should normally be used instead. | 491 * getRules(void) should normally be used instead. |
473 * See http://userguide.icu-project.org/collation/customization#TOC-Building
-on-Existing-Locales | 492 * See http://userguide.icu-project.org/collation/customization#TOC-Building
-on-Existing-Locales |
474 * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES. | 493 * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES. |
475 * @param buffer UnicodeString to store the result rules | 494 * @param buffer UnicodeString to store the result rules |
476 * @stable ICU 2.2 | 495 * @stable ICU 2.2 |
477 * @see UCOL_FULL_RULES | 496 * @see UCOL_FULL_RULES |
478 */ | 497 */ |
479 void getRules(UColRuleOption delta, UnicodeString &buffer); | 498 void getRules(UColRuleOption delta, UnicodeString &buffer) const; |
480 | 499 |
481 /** | 500 /** |
482 * Universal attribute setter | 501 * Universal attribute setter |
483 * @param attr attribute type | 502 * @param attr attribute type |
484 * @param value attribute value | 503 * @param value attribute value |
485 * @param status to indicate whether the operation went on smoothly or there
were errors | 504 * @param status to indicate whether the operation went on smoothly or there
were errors |
486 * @stable ICU 2.2 | 505 * @stable ICU 2.2 |
487 */ | 506 */ |
488 virtual void setAttribute(UColAttribute attr, UColAttributeValue value, | 507 virtual void setAttribute(UColAttribute attr, UColAttributeValue value, |
489 UErrorCode &status); | 508 UErrorCode &status); |
490 | 509 |
491 /** | 510 /** |
492 * Universal attribute getter. | 511 * Universal attribute getter. |
493 * @param attr attribute type | 512 * @param attr attribute type |
494 * @param status to indicate whether the operation went on smoothly or there
were errors | 513 * @param status to indicate whether the operation went on smoothly or there
were errors |
495 * @return attribute value | 514 * @return attribute value |
496 * @stable ICU 2.2 | 515 * @stable ICU 2.2 |
497 */ | 516 */ |
498 virtual UColAttributeValue getAttribute(UColAttribute attr, | 517 virtual UColAttributeValue getAttribute(UColAttribute attr, |
499 UErrorCode &status) const; | 518 UErrorCode &status) const; |
500 | 519 |
501 /** | 520 /** |
502 * Sets the variable top to a collation element value of a string supplied. | 521 * Sets the variable top to the top of the specified reordering group. |
| 522 * The variable top determines the highest-sorting character |
| 523 * which is affected by UCOL_ALTERNATE_HANDLING. |
| 524 * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has
no effect. |
| 525 * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATIO
N, |
| 526 * UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY; |
| 527 * or UCOL_REORDER_CODE_DEFAULT to restore the default max vari
able group |
| 528 * @param errorCode Standard ICU error code. Its input value must |
| 529 * pass the U_SUCCESS() test, or else the function returns |
| 530 * immediately. Check for U_FAILURE() on output or use with |
| 531 * function chaining. (See User Guide for details.) |
| 532 * @return *this |
| 533 * @see getMaxVariable |
| 534 * @draft ICU 53 |
| 535 */ |
| 536 virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCod
e); |
| 537 |
| 538 /** |
| 539 * Returns the maximum reordering group whose characters are affected by UCO
L_ALTERNATE_HANDLING. |
| 540 * @return the maximum variable reordering group. |
| 541 * @see setMaxVariable |
| 542 * @draft ICU 53 |
| 543 */ |
| 544 virtual UColReorderCode getMaxVariable() const; |
| 545 |
| 546 /** |
| 547 * Sets the variable top to the primary weight of the specified string. |
| 548 * |
| 549 * Beginning with ICU 53, the variable top is pinned to |
| 550 * the top of one of the supported reordering groups, |
| 551 * and it must not be beyond the last of those groups. |
| 552 * See setMaxVariable(). |
503 * @param varTop one or more (if contraction) UChars to which the variable t
op should be set | 553 * @param varTop one or more (if contraction) UChars to which the variable t
op should be set |
504 * @param len length of variable top string. If -1 it is considered to be ze
ro terminated. | 554 * @param len length of variable top string. If -1 it is considered to be ze
ro terminated. |
505 * @param status error code. If error code is set, the return value is undef
ined. Errors set by this function are: <br> | 555 * @param status error code. If error code is set, the return value is undef
ined. Errors set by this function are: <br> |
506 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there i
s no such a contraction<br> | 556 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there i
s no such contraction<br> |
507 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more
than two bytes | 557 * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond |
508 * @return a 32 bit value containing the value of the variable top in upper
16 bits. Lower 16 bits are undefined | 558 * the last reordering group supported by setMaxVariable() |
509 * @stable ICU 2.0 | 559 * @return variable top primary weight |
| 560 * @deprecated ICU 53 Call setMaxVariable() instead. |
510 */ | 561 */ |
511 virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode
&status); | 562 virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode
&status); |
512 | 563 |
513 /** | 564 /** |
514 * Sets the variable top to a collation element value of a string supplied. | 565 * Sets the variable top to the primary weight of the specified string. |
515 * @param varTop an UnicodeString size 1 or more (if contraction) of UChars
to which the variable top should be set | 566 * |
| 567 * Beginning with ICU 53, the variable top is pinned to |
| 568 * the top of one of the supported reordering groups, |
| 569 * and it must not be beyond the last of those groups. |
| 570 * See setMaxVariable(). |
| 571 * @param varTop a UnicodeString size 1 or more (if contraction) of UChars t
o which the variable top should be set |
516 * @param status error code. If error code is set, the return value is undef
ined. Errors set by this function are: <br> | 572 * @param status error code. If error code is set, the return value is undef
ined. Errors set by this function are: <br> |
517 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there i
s no such a contraction<br> | 573 * U_CE_NOT_FOUND_ERROR if more than one character was passed and there i
s no such contraction<br> |
518 * U_PRIMARY_TOO_LONG_ERROR if the primary for the variable top has more
than two bytes | 574 * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond |
519 * @return a 32 bit value containing the value of the variable top in upper
16 bits. Lower 16 bits are undefined | 575 * the last reordering group supported by setMaxVariable() |
520 * @stable ICU 2.0 | 576 * @return variable top primary weight |
| 577 * @deprecated ICU 53 Call setMaxVariable() instead. |
521 */ | 578 */ |
522 virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &sta
tus); | 579 virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &sta
tus); |
523 | 580 |
524 /** | 581 /** |
525 * Sets the variable top to a collation element value supplied. Variable top
is set to the upper 16 bits. | 582 * Sets the variable top to the specified primary weight. |
526 * Lower 16 bits are ignored. | 583 * |
527 * @param varTop CE value, as returned by setVariableTop or ucol)getVariable
Top | 584 * Beginning with ICU 53, the variable top is pinned to |
528 * @param status error code (not changed by function) | 585 * the top of one of the supported reordering groups, |
529 * @stable ICU 2.0 | 586 * and it must not be beyond the last of those groups. |
| 587 * See setMaxVariable(). |
| 588 * @param varTop primary weight, as returned by setVariableTop or ucol_getVa
riableTop |
| 589 * @param status error code |
| 590 * @deprecated ICU 53 Call setMaxVariable() instead. |
530 */ | 591 */ |
531 virtual void setVariableTop(uint32_t varTop, UErrorCode &status); | 592 virtual void setVariableTop(uint32_t varTop, UErrorCode &status); |
532 | 593 |
533 /** | 594 /** |
534 * Gets the variable top value of a Collator. | 595 * Gets the variable top value of a Collator. |
535 * Lower 16 bits are undefined and should be ignored. | |
536 * @param status error code (not changed by function). If error code is set,
the return value is undefined. | 596 * @param status error code (not changed by function). If error code is set,
the return value is undefined. |
| 597 * @return the variable top primary weight |
| 598 * @see getMaxVariable |
537 * @stable ICU 2.0 | 599 * @stable ICU 2.0 |
538 */ | 600 */ |
539 virtual uint32_t getVariableTop(UErrorCode &status) const; | 601 virtual uint32_t getVariableTop(UErrorCode &status) const; |
540 | 602 |
541 /** | 603 /** |
542 * Get an UnicodeSet that contains all the characters and sequences tailored
in | 604 * Get a UnicodeSet that contains all the characters and sequences tailored
in |
543 * this collator. | 605 * this collator. |
544 * @param status error code of the operation | 606 * @param status error code of the operation |
545 * @return a pointer to a UnicodeSet object containing all the | 607 * @return a pointer to a UnicodeSet object containing all the |
546 * code points and sequences that may sort differently than | 608 * code points and sequences that may sort differently than |
547 * in the UCA. The object must be disposed of by using delete | 609 * in the root collator. The object must be disposed of by using del
ete |
548 * @stable ICU 2.4 | 610 * @stable ICU 2.4 |
549 */ | 611 */ |
550 virtual UnicodeSet *getTailoredSet(UErrorCode &status) const; | 612 virtual UnicodeSet *getTailoredSet(UErrorCode &status) const; |
551 | 613 |
552 /** | 614 /** |
553 * Get the sort key as an array of bytes from an UnicodeString. | 615 * Get the sort key as an array of bytes from a UnicodeString. |
| 616 * |
| 617 * Note that sort keys are often less efficient than simply doing comparison
. |
| 618 * For more details, see the ICU User Guide. |
| 619 * |
554 * @param source string to be processed. | 620 * @param source string to be processed. |
555 * @param result buffer to store result in. If NULL, number of bytes needed | 621 * @param result buffer to store result in. If NULL, number of bytes needed |
556 * will be returned. | 622 * will be returned. |
557 * @param resultLength length of the result buffer. If if not enough the | 623 * @param resultLength length of the result buffer. If if not enough the |
558 * buffer will be filled to capacity. | 624 * buffer will be filled to capacity. |
559 * @return Number of bytes needed for storing the sort key | 625 * @return Number of bytes needed for storing the sort key |
560 * @stable ICU 2.0 | 626 * @stable ICU 2.0 |
561 */ | 627 */ |
562 virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result, | 628 virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result, |
563 int32_t resultLength) const; | 629 int32_t resultLength) const; |
564 | 630 |
565 /** | 631 /** |
566 * Get the sort key as an array of bytes from an UChar buffer. | 632 * Get the sort key as an array of bytes from a UChar buffer. |
| 633 * |
| 634 * Note that sort keys are often less efficient than simply doing comparison
. |
| 635 * For more details, see the ICU User Guide. |
| 636 * |
567 * @param source string to be processed. | 637 * @param source string to be processed. |
568 * @param sourceLength length of string to be processed. If -1, the string | 638 * @param sourceLength length of string to be processed. If -1, the string |
569 * is 0 terminated and length will be decided by the function. | 639 * is 0 terminated and length will be decided by the function. |
570 * @param result buffer to store result in. If NULL, number of bytes needed | 640 * @param result buffer to store result in. If NULL, number of bytes needed |
571 * will be returned. | 641 * will be returned. |
572 * @param resultLength length of the result buffer. If if not enough the | 642 * @param resultLength length of the result buffer. If if not enough the |
573 * buffer will be filled to capacity. | 643 * buffer will be filled to capacity. |
574 * @return Number of bytes needed for storing the sort key | 644 * @return Number of bytes needed for storing the sort key |
575 * @stable ICU 2.2 | 645 * @stable ICU 2.2 |
576 */ | 646 */ |
(...skipping 25 matching lines...) Expand all Loading... |
602 * @param status error code | 672 * @param status error code |
603 * @see Collator#getReorderCodes | 673 * @see Collator#getReorderCodes |
604 * @see Collator#getEquivalentReorderCodes | 674 * @see Collator#getEquivalentReorderCodes |
605 * @stable ICU 4.8 | 675 * @stable ICU 4.8 |
606 */ | 676 */ |
607 virtual void setReorderCodes(const int32_t* reorderCodes, | 677 virtual void setReorderCodes(const int32_t* reorderCodes, |
608 int32_t reorderCodesLength, | 678 int32_t reorderCodesLength, |
609 UErrorCode& status) ; | 679 UErrorCode& status) ; |
610 | 680 |
611 /** | 681 /** |
612 * Retrieves the reorder codes that are grouped with the given reorder code.
Some reorder | 682 * Implements ucol_strcollUTF8(). |
613 * codes will be grouped and must reorder together. | 683 * @internal |
614 * @param reorderCode The reorder code to determine equivalence for. | |
615 * @param dest The array to fill with the script equivalene reordering codes
. | |
616 * @param destCapacity The length of dest. If it is 0, then dest may be NULL
and the | |
617 * function will only return the length of the result without writing any of
the result | |
618 * string (pre-flighting). | |
619 * @param status A reference to an error code value, which must not indicate
| |
620 * a failure before the function call. | |
621 * @return The length of the of the reordering code equivalence array. | |
622 * @see ucol_setReorderCodes | |
623 * @see Collator#getReorderCodes | |
624 * @see Collator#setReorderCodes | |
625 * @stable ICU 4.8 | |
626 */ | 684 */ |
627 static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode, | 685 virtual UCollationResult internalCompareUTF8( |
628 int32_t* dest, | 686 const char *left, int32_t leftLength, |
629 int32_t destCapacity, | 687 const char *right, int32_t rightLength, |
630 UErrorCode& status); | 688 UErrorCode &errorCode) const; |
631 | 689 |
632 private: | 690 /** Get the short definition string for a collator. This internal API harves
ts the collator's |
633 | 691 * locale and the attribute set and produces a string that can be used for
opening |
634 // private static constants ----------------------------------------------- | 692 * a collator with the same attributes using the ucol_openFromShortString A
PI. |
635 | 693 * This string will be normalized. |
636 enum { | 694 * The structure and the syntax of the string is defined in the "Naming col
lators" |
637 /* need look up in .commit() */ | 695 * section of the users guide: |
638 CHARINDEX = 0x70000000, | 696 * http://userguide.icu-project.org/collation/concepts#TOC-Collator-naming-
scheme |
639 /* Expand index follows */ | 697 * This function supports preflighting. |
640 EXPANDCHARINDEX = 0x7E000000, | 698 * |
641 /* contract indexes follows */ | 699 * This is internal, and intended to be used with delegate converters. |
642 CONTRACTCHARINDEX = 0x7F000000, | 700 * |
643 /* unmapped character values */ | 701 * @param locale a locale that will appear as a collators locale in the res
ulting |
644 UNMAPPED = 0xFFFFFFFF, | 702 * short string definition. If NULL, the locale will be harve
sted |
645 /* primary strength increment */ | 703 * from the collator. |
646 PRIMARYORDERINCREMENT = 0x00010000, | 704 * @param buffer space to hold the resulting string |
647 /* secondary strength increment */ | 705 * @param capacity capacity of the buffer |
648 SECONDARYORDERINCREMENT = 0x00000100, | 706 * @param status for returning errors. All the preflighting errors are feat
ured |
649 /* tertiary strength increment */ | 707 * @return length of the resulting string |
650 TERTIARYORDERINCREMENT = 0x00000001, | 708 * @see ucol_openFromShortString |
651 /* mask off anything but primary order */ | 709 * @see ucol_normalizeShortDefinitionString |
652 PRIMARYORDERMASK = 0xffff0000, | 710 * @see ucol_getShortDefinitionString |
653 /* mask off anything but secondary order */ | 711 * @internal |
654 SECONDARYORDERMASK = 0x0000ff00, | 712 */ |
655 /* mask off anything but tertiary order */ | 713 virtual int32_t internalGetShortDefinitionString(const char *locale, |
656 TERTIARYORDERMASK = 0x000000ff, | 714 char *buffer, |
657 /* mask off ignorable char order */ | 715 int32_t capacity, |
658 IGNORABLEMASK = 0x0000ffff, | 716 UErrorCode &status) const; |
659 /* use only the primary difference */ | |
660 PRIMARYDIFFERENCEONLY = 0xffff0000, | |
661 /* use only the primary and secondary difference */ | |
662 SECONDARYDIFFERENCEONLY = 0xffffff00, | |
663 /* primary order shift */ | |
664 PRIMARYORDERSHIFT = 16, | |
665 /* secondary order shift */ | |
666 SECONDARYORDERSHIFT = 8, | |
667 /* starting value for collation elements */ | |
668 COLELEMENTSTART = 0x02020202, | |
669 /* testing mask for primary low element */ | |
670 PRIMARYLOWZEROMASK = 0x00FF0000, | |
671 /* reseting value for secondaries and tertiaries */ | |
672 RESETSECONDARYTERTIARY = 0x00000202, | |
673 /* reseting value for tertiaries */ | |
674 RESETTERTIARY = 0x00000002, | |
675 | |
676 PRIMIGNORABLE = 0x0202 | |
677 }; | |
678 | |
679 // private data members --------------------------------------------------- | |
680 | |
681 UBool dataIsOwned; | |
682 | |
683 UBool isWriteThroughAlias; | |
684 | 717 |
685 /** | 718 /** |
686 * c struct for collation. All initialisation for it has to be done through | 719 * Implements ucol_nextSortKeyPart(). |
687 * setUCollator(). | 720 * @internal |
688 */ | 721 */ |
689 UCollator *ucollator; | 722 virtual int32_t internalNextSortKeyPart( |
| 723 UCharIterator *iter, uint32_t state[2], |
| 724 uint8_t *dest, int32_t count, UErrorCode &errorCode) const; |
690 | 725 |
691 /** | 726 /** |
692 * Rule UnicodeString | 727 * Only for use in ucol_openRules(). |
693 */ | 728 * @internal |
694 UnicodeString urulestring; | |
695 | |
696 // friend classes -------------------------------------------------------- | |
697 | |
698 /** | |
699 * Used to iterate over collation elements in a character source. | |
700 */ | |
701 friend class CollationElementIterator; | |
702 | |
703 /** | |
704 * Collator ONLY needs access to RuleBasedCollator(const Locale&, | |
705 * UErrorCode&) | |
706 */ | |
707 friend class Collator; | |
708 | |
709 /** | |
710 * Searching over collation elements in a character source | |
711 */ | |
712 friend class StringSearch; | |
713 | |
714 // private constructors -------------------------------------------------- | |
715 | |
716 /** | |
717 * Default constructor | |
718 */ | 729 */ |
719 RuleBasedCollator(); | 730 RuleBasedCollator(); |
720 | 731 |
| 732 #ifndef U_HIDE_INTERNAL_API |
721 /** | 733 /** |
722 * RuleBasedCollator constructor. This constructor takes a locale. The | 734 * Implements ucol_getLocaleByType(). |
723 * only caller of this class should be Collator::createInstance(). If | 735 * Needed because the lifetime of the locale ID string must match that of th
e collator. |
724 * createInstance() happens to know that the requested locale's collation is | 736 * getLocale() returns a copy of a Locale, with minimal lifetime in a C wrap
per. |
725 * implemented as a RuleBasedCollator, it can then call this constructor. | 737 * @internal |
726 * OTHERWISE IT SHOULDN'T, since this constructor ALWAYS RETURNS A VALID | |
727 * COLLATION TABLE. It does this by falling back to defaults. | |
728 * @param desiredLocale locale used | |
729 * @param status error code status | |
730 */ | 738 */ |
731 RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status); | 739 const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCo
de) const; |
732 | 740 |
733 /** | 741 /** |
734 * common constructor implementation | 742 * Implements ucol_getContractionsAndExpansions(). |
735 * | 743 * Gets this collator's sets of contraction strings and/or |
736 * @param rules the collation rules to build the collation table from. | 744 * characters and strings that map to multiple collation elements (expansion
s). |
737 * @param collationStrength default strength for comparison | 745 * If addPrefixes is TRUE, then contractions that are expressed as |
738 * @param decompositionMode the normalisation mode | 746 * prefix/pre-context rules are included. |
739 * @param status reporting a success or an error. | 747 * @param contractions if not NULL, the set to hold the contractions |
| 748 * @param expansions if not NULL, the set to hold the expansions |
| 749 * @param addPrefixes include prefix contextual mappings |
| 750 * @param errorCode in/out ICU error code |
| 751 * @internal |
740 */ | 752 */ |
741 void | 753 void internalGetContractionsAndExpansions( |
742 construct(const UnicodeString& rules, | 754 UnicodeSet *contractions, UnicodeSet *expansions, |
743 UColAttributeValue collationStrength, | 755 UBool addPrefixes, UErrorCode &errorCode) const; |
744 UColAttributeValue decompositionMode, | |
745 UErrorCode& status); | |
746 | |
747 // private methods ------------------------------------------------------- | |
748 | 756 |
749 /** | 757 /** |
750 * Creates the c struct for ucollator | 758 * Adds the contractions that start with character c to the set. |
751 * @param locale desired locale | 759 * Ignores prefixes. Used by AlphabeticIndex. |
752 * @param status error status | 760 * @internal |
753 */ | 761 */ |
754 void setUCollator(const Locale& locale, UErrorCode& status); | 762 void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCo
de) const; |
755 | 763 |
756 /** | 764 /** |
757 * Creates the c struct for ucollator | 765 * Implements from-rule constructors, and ucol_openRules(). |
758 * @param locale desired locale name | 766 * @internal |
759 * @param status error status | 767 */ |
760 */ | 768 void internalBuildTailoring( |
761 void setUCollator(const char* locale, UErrorCode& status); | 769 const UnicodeString &rules, |
| 770 int32_t strength, |
| 771 UColAttributeValue decompositionMode, |
| 772 UParseError *outParseError, UnicodeString *outReason, |
| 773 UErrorCode &errorCode); |
| 774 |
| 775 /** @internal */ |
| 776 static inline RuleBasedCollator *rbcFromUCollator(UCollator *uc) { |
| 777 return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc)); |
| 778 } |
| 779 /** @internal */ |
| 780 static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc)
{ |
| 781 return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc)); |
| 782 } |
762 | 783 |
763 /** | 784 /** |
764 * Creates the c struct for ucollator. This used internally by StringSearch. | 785 * Appends the CEs for the string to the vector. |
765 * Hence the responsibility of cleaning up the ucollator is not done by | 786 * @internal for tests & tools |
766 * this RuleBasedCollator. The isDataOwned flag is set to FALSE. | 787 */ |
767 * @param collator new ucollator data | 788 void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &er
rorCode) const; |
768 */ | 789 #endif // U_HIDE_INTERNAL_API |
769 void setUCollator(UCollator *collator); | |
770 | |
771 public: | |
772 #ifndef U_HIDE_INTERNAL_API | |
773 /** | |
774 * Get UCollator data struct. Used only by StringSearch & intltest. | |
775 * @return UCollator data struct | |
776 * @internal | |
777 */ | |
778 const UCollator * getUCollator(); | |
779 #endif /* U_HIDE_INTERNAL_API */ | |
780 | 790 |
781 protected: | 791 protected: |
782 /** | 792 /** |
783 * Used internally by registraton to define the requested and valid locales. | 793 * Used internally by registration to define the requested and valid locales. |
784 * @param requestedLocale the requsted locale | 794 * @param requestedLocale the requested locale |
785 * @param validLocale the valid locale | 795 * @param validLocale the valid locale |
786 * @param actualLocale the actual locale | 796 * @param actualLocale the actual locale |
787 * @internal | 797 * @internal |
788 */ | 798 */ |
789 virtual void setLocales(const Locale& requestedLocale, const Locale& validLo
cale, const Locale& actualLocale); | 799 virtual void setLocales(const Locale& requestedLocale, const Locale& validLo
cale, const Locale& actualLocale); |
790 | 800 |
791 private: | 801 private: |
792 // if not owned and not a write through alias, copy the ucollator | 802 friend class CollationElementIterator; |
793 void checkOwned(void); | 803 friend class Collator; |
794 | 804 |
795 // utility to init rule string used by checkOwned and construct | 805 RuleBasedCollator(const CollationCacheEntry *entry); |
796 void setRuleStringFromCollator(); | |
797 | 806 |
798 public: | 807 /** |
799 /** Get the short definition string for a collator. This internal API harves
ts the collator's | 808 * Enumeration of attributes that are relevant for short definition strings |
800 * locale and the attribute set and produces a string that can be used for
opening | 809 * (e.g., ucol_getShortDefinitionString()). |
801 * a collator with the same properties using the ucol_openFromShortString A
PI. | 810 * Effectively extends UColAttribute. |
802 * This string will be normalized. | 811 */ |
803 * The structure and the syntax of the string is defined in the "Naming col
lators" | 812 enum Attributes { |
804 * section of the users guide: | 813 ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT, |
805 * http://icu-project.org/userguide/Collate_Concepts.html#Naming_Collators | 814 ATTR_LIMIT |
806 * This function supports preflighting. | 815 }; |
807 * | 816 |
808 * This is internal, and intended to be used with delegate converters. | 817 void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode); |
| 818 |
| 819 // Both lengths must be <0 or else both must be >=0. |
| 820 UCollationResult doCompare(const UChar *left, int32_t leftLength, |
| 821 const UChar *right, int32_t rightLength, |
| 822 UErrorCode &errorCode) const; |
| 823 UCollationResult doCompare(const uint8_t *left, int32_t leftLength, |
| 824 const uint8_t *right, int32_t rightLength, |
| 825 UErrorCode &errorCode) const; |
| 826 |
| 827 void writeSortKey(const UChar *s, int32_t length, |
| 828 SortKeyByteSink &sink, UErrorCode &errorCode) const; |
| 829 |
| 830 void writeIdenticalLevel(const UChar *s, const UChar *limit, |
| 831 SortKeyByteSink &sink, UErrorCode &errorCode) const
; |
| 832 |
| 833 const CollationSettings &getDefaultSettings() const; |
| 834 |
| 835 void setAttributeDefault(int32_t attribute) { |
| 836 explicitlySetAttributes &= ~((uint32_t)1 << attribute); |
| 837 } |
| 838 void setAttributeExplicitly(int32_t attribute) { |
| 839 explicitlySetAttributes |= (uint32_t)1 << attribute; |
| 840 } |
| 841 UBool attributeHasBeenSetExplicitly(int32_t attribute) const { |
| 842 // assert(0 <= attribute < ATTR_LIMIT); |
| 843 return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) !=
0); |
| 844 } |
| 845 |
| 846 /** |
| 847 * Tests whether a character is "unsafe" for use as a collation starting poi
nt. |
809 * | 848 * |
810 * @param locale a locale that will appear as a collators locale in the res
ulting | 849 * @param c code point or code unit |
811 * short string definition. If NULL, the locale will be harve
sted | 850 * @return TRUE if c is unsafe |
812 * from the collator. | 851 * @see CollationElementIterator#setOffset(int) |
813 * @param buffer space to hold the resulting string | |
814 * @param capacity capacity of the buffer | |
815 * @param status for returning errors. All the preflighting errors are feat
ured | |
816 * @return length of the resulting string | |
817 * @see ucol_openFromShortString | |
818 * @see ucol_normalizeShortDefinitionString | |
819 * @see ucol_getShortDefinitionString | |
820 * @internal | |
821 */ | 852 */ |
822 virtual int32_t internalGetShortDefinitionString(const char *locale, | 853 UBool isUnsafe(UChar32 c) const; |
823 char *buffer, | 854 |
824 int32_t capacity, | 855 static void computeMaxExpansions(const CollationTailoring *t, UErrorCode &er
rorCode); |
825 UErrorCode &status) const; | 856 UBool initMaxExpansions(UErrorCode &errorCode) const; |
| 857 |
| 858 void setFastLatinOptions(CollationSettings &ownedSettings) const; |
| 859 |
| 860 const CollationData *data; |
| 861 const CollationSettings *settings; // reference-counted |
| 862 const CollationTailoring *tailoring; // alias of cacheEntry->tailoring |
| 863 const CollationCacheEntry *cacheEntry; // reference-counted |
| 864 Locale validLocale; |
| 865 uint32_t explicitlySetAttributes; |
| 866 |
| 867 UBool actualLocaleIsSameAsValid; |
826 }; | 868 }; |
827 | 869 |
828 // inline method implementation --------------------------------------------- | |
829 | |
830 inline void RuleBasedCollator::setUCollator(const Locale &locale, | |
831 UErrorCode &status) | |
832 { | |
833 setUCollator(locale.getName(), status); | |
834 } | |
835 | |
836 | |
837 inline void RuleBasedCollator::setUCollator(UCollator *collator) | |
838 { | |
839 | |
840 if (ucollator && dataIsOwned) { | |
841 ucol_close(ucollator); | |
842 } | |
843 ucollator = collator; | |
844 dataIsOwned = FALSE; | |
845 isWriteThroughAlias = TRUE; | |
846 setRuleStringFromCollator(); | |
847 } | |
848 | |
849 #ifndef U_HIDE_INTERNAL_API | |
850 inline const UCollator * RuleBasedCollator::getUCollator() | |
851 { | |
852 return ucollator; | |
853 } | |
854 #endif /* U_HIDE_INTERNAL_API */ | |
855 | |
856 U_NAMESPACE_END | 870 U_NAMESPACE_END |
857 | 871 |
858 #endif /* #if !UCONFIG_NO_COLLATION */ | 872 #endif // !UCONFIG_NO_COLLATION |
859 | 873 #endif // TBLCOLL_H |
860 #endif | |
OLD | NEW |