|
||||
File indexing completed on 2025-01-18 10:13:02
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************* 0005 * 0006 * Copyright (C) 2011-2014 International Business Machines 0007 * Corporation and others. All Rights Reserved. 0008 * 0009 ******************************************************************************* 0010 */ 0011 0012 #ifndef INDEXCHARS_H 0013 #define INDEXCHARS_H 0014 0015 #include "unicode/utypes.h" 0016 0017 #if U_SHOW_CPLUSPLUS_API 0018 0019 #include "unicode/uobject.h" 0020 #include "unicode/locid.h" 0021 #include "unicode/unistr.h" 0022 0023 #if !UCONFIG_NO_COLLATION 0024 0025 /** 0026 * \file 0027 * \brief C++ API: Index Characters 0028 */ 0029 0030 U_CDECL_BEGIN 0031 0032 /** 0033 * Constants for Alphabetic Index Label Types. 0034 * The form of these enum constants anticipates having a plain C API 0035 * for Alphabetic Indexes that will also use them. 0036 * @stable ICU 4.8 0037 */ 0038 typedef enum UAlphabeticIndexLabelType { 0039 /** 0040 * Normal Label, typically the starting letter of the names 0041 * in the bucket with this label. 0042 * @stable ICU 4.8 0043 */ 0044 U_ALPHAINDEX_NORMAL = 0, 0045 0046 /** 0047 * Underflow Label. The bucket with this label contains names 0048 * in scripts that sort before any of the bucket labels in this index. 0049 * @stable ICU 4.8 0050 */ 0051 U_ALPHAINDEX_UNDERFLOW = 1, 0052 0053 /** 0054 * Inflow Label. The bucket with this label contains names 0055 * in scripts that sort between two of the bucket labels in this index. 0056 * Inflow labels are created when an index contains normal labels for 0057 * multiple scripts, and skips other scripts that sort between some of the 0058 * included scripts. 0059 * @stable ICU 4.8 0060 */ 0061 U_ALPHAINDEX_INFLOW = 2, 0062 0063 /** 0064 * Overflow Label. The bucket with this label contains names in scripts 0065 * that sort after all of the bucket labels in this index. 0066 * @stable ICU 4.8 0067 */ 0068 U_ALPHAINDEX_OVERFLOW = 3 0069 } UAlphabeticIndexLabelType; 0070 0071 0072 struct UHashtable; 0073 U_CDECL_END 0074 0075 U_NAMESPACE_BEGIN 0076 0077 // Forward Declarations 0078 0079 class BucketList; 0080 class Collator; 0081 class RuleBasedCollator; 0082 class StringEnumeration; 0083 class UnicodeSet; 0084 class UVector; 0085 0086 /** 0087 * AlphabeticIndex supports the creation of a UI index appropriate for a given language. 0088 * It can support either direct use, or use with a client that doesn't support localized collation. 0089 * The following is an example of what an index might look like in a UI: 0090 * 0091 * <pre> 0092 * <b>... A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ...</b> 0093 * 0094 * <b>A</b> 0095 * Addison 0096 * Albertson 0097 * Azensky 0098 * <b>B</b> 0099 * Baker 0100 * ... 0101 * </pre> 0102 * 0103 * The class can generate a list of labels for use as a UI "index", that is, a list of 0104 * clickable characters (or character sequences) that allow the user to see a segment 0105 * (bucket) of a larger "target" list. That is, each label corresponds to a bucket in 0106 * the target list, where everything in the bucket is greater than or equal to the character 0107 * (according to the locale's collation). Strings can be added to the index; 0108 * they will be in sorted order in the right bucket. 0109 * <p> 0110 * The class also supports having buckets for strings before the first (underflow), 0111 * after the last (overflow), and between scripts (inflow). For example, if the index 0112 * is constructed with labels for Russian and English, Greek characters would fall 0113 * into an inflow bucket between the other two scripts. 0114 * <p> 0115 * The AlphabeticIndex class is not intended for public subclassing. 0116 * 0117 * <p><em>Note:</em> If you expect to have a lot of ASCII or Latin characters 0118 * as well as characters from the user's language, 0119 * then it is a good idea to call addLabels(Locale::getEnglish(), status).</p> 0120 * 0121 * <h2>Direct Use</h2> 0122 * <p>The following shows an example of building an index directly. 0123 * The "show..." methods below are just to illustrate usage. 0124 * 0125 * <pre> 0126 * // Create a simple index. "Item" is assumed to be an application 0127 * // defined type that the application's UI and other processing knows about, 0128 * // and that has a name. 0129 * 0130 * UErrorCode status = U_ZERO_ERROR; 0131 * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status); 0132 * index->addLabels(additionalLocale, status); 0133 * for (Item *item in some source of Items ) { 0134 * index->addRecord(item->name(), item, status); 0135 * } 0136 * ... 0137 * // Show index at top. We could skip or gray out empty buckets 0138 * 0139 * while (index->nextBucket(status)) { 0140 * if (showAll || index->getBucketRecordCount() != 0) { 0141 * showLabelAtTop(UI, index->getBucketLabel()); 0142 * } 0143 * } 0144 * ... 0145 * // Show the buckets with their contents, skipping empty buckets 0146 * 0147 * index->resetBucketIterator(status); 0148 * while (index->nextBucket(status)) { 0149 * if (index->getBucketRecordCount() != 0) { 0150 * showLabelInList(UI, index->getBucketLabel()); 0151 * while (index->nextRecord(status)) { 0152 * showIndexedItem(UI, static_cast<Item *>(index->getRecordData())) 0153 * </pre> 0154 * 0155 * The caller can build different UIs using this class. 0156 * For example, an index character could be omitted or grayed-out 0157 * if its bucket is empty. Small buckets could also be combined based on size, such as: 0158 * 0159 * <pre> 0160 * <b>... A-F G-N O-Z ...</b> 0161 * </pre> 0162 * 0163 * <h2>Client Support</h2> 0164 * <p>Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself, 0165 * to support sorting on a client that doesn't support AlphabeticIndex functionality. 0166 * 0167 * <p>The ImmutableIndex is both immutable and thread-safe. 0168 * The corresponding AlphabeticIndex methods are not thread-safe because 0169 * they "lazily" build the index buckets. 0170 * <ul> 0171 * <li>ImmutableIndex.getBucket(index) provides random access to all 0172 * buckets and their labels and label types. 0173 * <li>The AlphabeticIndex bucket iterator or ImmutableIndex.getBucket(0..getBucketCount-1) 0174 * can be used to get a list of the labels, 0175 * such as "...", "A", "B",..., and send that list to the client. 0176 * <li>When the client has a new name, it sends that name to the server. 0177 * The server needs to call the following methods, 0178 * and communicate the bucketIndex and collationKey back to the client. 0179 * 0180 * <pre> 0181 * int32_t bucketIndex = index.getBucketIndex(name, status); 0182 * const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel(); // optional 0183 * int32_t skLength = collator.getSortKey(name, sk, skCapacity); 0184 * </pre> 0185 * 0186 * <li>The client would put the name (and associated information) into its bucket for bucketIndex. The sort key sk is a 0187 * sequence of bytes that can be compared with a binary compare, and produce the right localized result.</li> 0188 * </ul> 0189 * 0190 * @stable ICU 4.8 0191 */ 0192 class U_I18N_API AlphabeticIndex: public UObject { 0193 public: 0194 /** 0195 * An index "bucket" with a label string and type. 0196 * It is referenced by getBucketIndex(), 0197 * and returned by ImmutableIndex.getBucket(). 0198 * 0199 * The Bucket class is not intended for public subclassing. 0200 * @stable ICU 51 0201 */ 0202 class U_I18N_API Bucket : public UObject { 0203 public: 0204 /** 0205 * Destructor. 0206 * @stable ICU 51 0207 */ 0208 virtual ~Bucket(); 0209 0210 /** 0211 * Returns the label string. 0212 * 0213 * @return the label string for the bucket 0214 * @stable ICU 51 0215 */ 0216 const UnicodeString &getLabel() const { return label_; } 0217 /** 0218 * Returns whether this bucket is a normal, underflow, overflow, or inflow bucket. 0219 * 0220 * @return the bucket label type 0221 * @stable ICU 51 0222 */ 0223 UAlphabeticIndexLabelType getLabelType() const { return labelType_; } 0224 0225 private: 0226 friend class AlphabeticIndex; 0227 friend class BucketList; 0228 0229 UnicodeString label_; 0230 UnicodeString lowerBoundary_; 0231 UAlphabeticIndexLabelType labelType_; 0232 Bucket *displayBucket_; 0233 int32_t displayIndex_; 0234 UVector *records_; // Records are owned by the inputList_ vector. 0235 0236 Bucket(const UnicodeString &label, // Parameter strings are copied. 0237 const UnicodeString &lowerBoundary, 0238 UAlphabeticIndexLabelType type); 0239 }; 0240 0241 /** 0242 * Immutable, thread-safe version of AlphabeticIndex. 0243 * This class provides thread-safe methods for bucketing, 0244 * and random access to buckets and their properties, 0245 * but does not offer adding records to the index. 0246 * 0247 * The ImmutableIndex class is not intended for public subclassing. 0248 * 0249 * @stable ICU 51 0250 */ 0251 class U_I18N_API ImmutableIndex : public UObject { 0252 public: 0253 /** 0254 * Destructor. 0255 * @stable ICU 51 0256 */ 0257 virtual ~ImmutableIndex(); 0258 0259 /** 0260 * Returns the number of index buckets and labels, including underflow/inflow/overflow. 0261 * 0262 * @return the number of index buckets 0263 * @stable ICU 51 0264 */ 0265 int32_t getBucketCount() const; 0266 0267 /** 0268 * Finds the index bucket for the given name and returns the number of that bucket. 0269 * Use getBucket() to get the bucket's properties. 0270 * 0271 * @param name the string to be sorted into an index bucket 0272 * @param errorCode Error code, will be set with the reason if the 0273 * operation fails. 0274 * @return the bucket number for the name 0275 * @stable ICU 51 0276 */ 0277 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const; 0278 0279 /** 0280 * Returns the index-th bucket. Returns nullptr if the index is out of range. 0281 * 0282 * @param index bucket number 0283 * @return the index-th bucket 0284 * @stable ICU 51 0285 */ 0286 const Bucket *getBucket(int32_t index) const; 0287 0288 private: 0289 friend class AlphabeticIndex; 0290 0291 ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly) 0292 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {} 0293 0294 BucketList *buckets_; 0295 Collator *collatorPrimaryOnly_; 0296 }; 0297 0298 /** 0299 * Construct an AlphabeticIndex object for the specified locale. If the locale's 0300 * data does not include index characters, a set of them will be 0301 * synthesized based on the locale's exemplar characters. The locale 0302 * determines the sorting order for both the index characters and the 0303 * user item names appearing under each Index character. 0304 * 0305 * @param locale the desired locale. 0306 * @param status Error code, will be set with the reason if the construction 0307 * of the AlphabeticIndex object fails. 0308 * @stable ICU 4.8 0309 */ 0310 AlphabeticIndex(const Locale &locale, UErrorCode &status); 0311 0312 /** 0313 * Construct an AlphabeticIndex that uses a specific collator. 0314 * 0315 * The index will be created with no labels; the addLabels() function must be called 0316 * after creation to add the desired labels to the index. 0317 * 0318 * The index adopts the collator, and is responsible for deleting it. 0319 * The caller should make no further use of the collator after creating the index. 0320 * 0321 * @param collator The collator to use to order the contents of this index. 0322 * @param status Error code, will be set with the reason if the 0323 * operation fails. 0324 * @stable ICU 51 0325 */ 0326 AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status); 0327 0328 /** 0329 * Add Labels to this Index. The labels are additions to those 0330 * that are already in the index; they do not replace the existing 0331 * ones. 0332 * @param additions The additional characters to add to the index, such as A-Z. 0333 * @param status Error code, will be set with the reason if the 0334 * operation fails. 0335 * @return this, for chaining 0336 * @stable ICU 4.8 0337 */ 0338 virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status); 0339 0340 /** 0341 * Add the index characters from a Locale to the index. The labels 0342 * are added to those that are already in the index; they do not replace the 0343 * existing index characters. The collation order for this index is not 0344 * changed; it remains that of the locale that was originally specified 0345 * when creating this Index. 0346 * 0347 * @param locale The locale whose index characters are to be added. 0348 * @param status Error code, will be set with the reason if the 0349 * operation fails. 0350 * @return this, for chaining 0351 * @stable ICU 4.8 0352 */ 0353 virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status); 0354 0355 /** 0356 * Destructor 0357 * @stable ICU 4.8 0358 */ 0359 virtual ~AlphabeticIndex(); 0360 0361 /** 0362 * Builds an immutable, thread-safe version of this instance, without data records. 0363 * 0364 * @return an immutable index instance 0365 * @stable ICU 51 0366 */ 0367 ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode); 0368 0369 /** 0370 * Get the Collator that establishes the ordering of the items in this index. 0371 * Ownership of the collator remains with the AlphabeticIndex instance. 0372 * 0373 * The returned collator is a reference to the internal collator used by this 0374 * index. It may be safely used to compare the names of items or to get 0375 * sort keys for names. However if any settings need to be changed, 0376 * or other non-const methods called, a cloned copy must be made first. 0377 * 0378 * @return The collator 0379 * @stable ICU 4.8 0380 */ 0381 virtual const RuleBasedCollator &getCollator() const; 0382 0383 0384 /** 0385 * Get the default label used for abbreviated buckets *between* other index characters. 0386 * For example, consider the labels when Latin (X Y Z) and Greek (Α Β Γ) are used: 0387 * 0388 * X Y Z ... Α Β Γ. 0389 * 0390 * @return inflow label 0391 * @stable ICU 4.8 0392 */ 0393 virtual const UnicodeString &getInflowLabel() const; 0394 0395 /** 0396 * Set the default label used for abbreviated buckets <i>between</i> other index characters. 0397 * An inflow label will be automatically inserted if two otherwise-adjacent label characters 0398 * are from different scripts, e.g. Latin and Cyrillic, and a third script, e.g. Greek, 0399 * sorts between the two. The default inflow character is an ellipsis (...) 0400 * 0401 * @param inflowLabel the new Inflow label. 0402 * @param status Error code, will be set with the reason if the operation fails. 0403 * @return this 0404 * @stable ICU 4.8 0405 */ 0406 virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status); 0407 0408 0409 /** 0410 * Get the special label used for items that sort after the last normal label, 0411 * and that would not otherwise have an appropriate label. 0412 * 0413 * @return the overflow label 0414 * @stable ICU 4.8 0415 */ 0416 virtual const UnicodeString &getOverflowLabel() const; 0417 0418 0419 /** 0420 * Set the label used for items that sort after the last normal label, 0421 * and that would not otherwise have an appropriate label. 0422 * 0423 * @param overflowLabel the new overflow label. 0424 * @param status Error code, will be set with the reason if the operation fails. 0425 * @return this 0426 * @stable ICU 4.8 0427 */ 0428 virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status); 0429 0430 /** 0431 * Get the special label used for items that sort before the first normal label, 0432 * and that would not otherwise have an appropriate label. 0433 * 0434 * @return underflow label 0435 * @stable ICU 4.8 0436 */ 0437 virtual const UnicodeString &getUnderflowLabel() const; 0438 0439 /** 0440 * Set the label used for items that sort before the first normal label, 0441 * and that would not otherwise have an appropriate label. 0442 * 0443 * @param underflowLabel the new underflow label. 0444 * @param status Error code, will be set with the reason if the operation fails. 0445 * @return this 0446 * @stable ICU 4.8 0447 */ 0448 virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status); 0449 0450 0451 /** 0452 * Get the limit on the number of labels permitted in the index. 0453 * The number does not include over, under and inflow labels. 0454 * 0455 * @return maxLabelCount maximum number of labels. 0456 * @stable ICU 4.8 0457 */ 0458 virtual int32_t getMaxLabelCount() const; 0459 0460 /** 0461 * Set a limit on the number of labels permitted in the index. 0462 * The number does not include over, under and inflow labels. 0463 * Currently, if the number is exceeded, then every 0464 * nth item is removed to bring the count down. 0465 * A more sophisticated mechanism may be available in the future. 0466 * 0467 * @param maxLabelCount the maximum number of labels. 0468 * @param status error code 0469 * @return This, for chaining 0470 * @stable ICU 4.8 0471 */ 0472 virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status); 0473 0474 0475 /** 0476 * Add a record to the index. Each record will be associated with an index Bucket 0477 * based on the record's name. The list of records for each bucket will be sorted 0478 * based on the collation ordering of the names in the index's locale. 0479 * Records with duplicate names are permitted; they will be kept in the order 0480 * that they were added. 0481 * 0482 * @param name The display name for the Record. The Record will be placed in 0483 * a bucket based on this name. 0484 * @param data An optional pointer to user data associated with this 0485 * item. When iterating the contents of a bucket, both the 0486 * data pointer the name will be available for each Record. 0487 * @param status Error code, will be set with the reason if the operation fails. 0488 * @return This, for chaining. 0489 * @stable ICU 4.8 0490 */ 0491 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status); 0492 0493 /** 0494 * Remove all Records from the Index. The set of Buckets, which define the headings under 0495 * which records are classified, is not altered. 0496 * 0497 * @param status Error code, will be set with the reason if the operation fails. 0498 * @return This, for chaining. 0499 * @stable ICU 4.8 0500 */ 0501 virtual AlphabeticIndex &clearRecords(UErrorCode &status); 0502 0503 0504 /** Get the number of labels in this index. 0505 * Note: may trigger lazy index construction. 0506 * 0507 * @param status Error code, will be set with the reason if the operation fails. 0508 * @return The number of labels in this index, including any under, over or 0509 * in-flow labels. 0510 * @stable ICU 4.8 0511 */ 0512 virtual int32_t getBucketCount(UErrorCode &status); 0513 0514 0515 /** Get the total number of Records in this index, that is, the number 0516 * of <name, data> pairs added. 0517 * 0518 * @param status Error code, will be set with the reason if the operation fails. 0519 * @return The number of records in this index, that is, the total number 0520 * of (name, data) items added with addRecord(). 0521 * @stable ICU 4.8 0522 */ 0523 virtual int32_t getRecordCount(UErrorCode &status); 0524 0525 0526 0527 /** 0528 * Given the name of a record, return the zero-based index of the Bucket 0529 * in which the item should appear. The name need not be in the index. 0530 * A Record will not be added to the index by this function. 0531 * Bucket numbers are zero-based, in Bucket iteration order. 0532 * 0533 * @param itemName The name whose bucket position in the index is to be determined. 0534 * @param status Error code, will be set with the reason if the operation fails. 0535 * @return The bucket number for this name. 0536 * @stable ICU 4.8 0537 * 0538 */ 0539 virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status); 0540 0541 0542 /** 0543 * Get the zero based index of the current Bucket from an iteration 0544 * over the Buckets of this index. Return -1 if no iteration is in process. 0545 * @return the index of the current Bucket 0546 * @stable ICU 4.8 0547 */ 0548 virtual int32_t getBucketIndex() const; 0549 0550 0551 /** 0552 * Advance the iteration over the Buckets of this index. Return false if 0553 * there are no more Buckets. 0554 * 0555 * @param status Error code, will be set with the reason if the operation fails. 0556 * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while 0557 * an enumeration of its contents are in process. 0558 * 0559 * @return true if success, false if at end of iteration 0560 * @stable ICU 4.8 0561 */ 0562 virtual UBool nextBucket(UErrorCode &status); 0563 0564 /** 0565 * Return the name of the Label of the current bucket from an iteration over the buckets. 0566 * If the iteration is before the first Bucket (nextBucket() has not been called), 0567 * or after the last, return an empty string. 0568 * 0569 * @return the bucket label. 0570 * @stable ICU 4.8 0571 */ 0572 virtual const UnicodeString &getBucketLabel() const; 0573 0574 /** 0575 * Return the type of the label for the current Bucket (selected by the 0576 * iteration over Buckets.) 0577 * 0578 * @return the label type. 0579 * @stable ICU 4.8 0580 */ 0581 virtual UAlphabeticIndexLabelType getBucketLabelType() const; 0582 0583 /** 0584 * Get the number of <name, data> Records in the current Bucket. 0585 * If the current bucket iteration position is before the first label or after the 0586 * last, return 0. 0587 * 0588 * @return the number of Records. 0589 * @stable ICU 4.8 0590 */ 0591 virtual int32_t getBucketRecordCount() const; 0592 0593 0594 /** 0595 * Reset the Bucket iteration for this index. The next call to nextBucket() 0596 * will restart the iteration at the first label. 0597 * 0598 * @param status Error code, will be set with the reason if the operation fails. 0599 * @return this, for chaining. 0600 * @stable ICU 4.8 0601 */ 0602 virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status); 0603 0604 /** 0605 * Advance to the next record in the current Bucket. 0606 * When nextBucket() is called, Record iteration is reset to just before the 0607 * first Record in the new Bucket. 0608 * 0609 * @param status Error code, will be set with the reason if the operation fails. 0610 * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while 0611 * an enumeration of its contents are in process. 0612 * @return true if successful, false when the iteration advances past the last item. 0613 * @stable ICU 4.8 0614 */ 0615 virtual UBool nextRecord(UErrorCode &status); 0616 0617 /** 0618 * Get the name of the current Record. 0619 * Return an empty string if the Record iteration position is before first 0620 * or after the last. 0621 * 0622 * @return The name of the current index item. 0623 * @stable ICU 4.8 0624 */ 0625 virtual const UnicodeString &getRecordName() const; 0626 0627 0628 /** 0629 * Return the data pointer of the Record currently being iterated over. 0630 * Return nullptr if the current iteration position before the first item in this Bucket, 0631 * or after the last. 0632 * 0633 * @return The current Record's data pointer. 0634 * @stable ICU 4.8 0635 */ 0636 virtual const void *getRecordData() const; 0637 0638 0639 /** 0640 * Reset the Record iterator position to before the first Record in the current Bucket. 0641 * 0642 * @return This, for chaining. 0643 * @stable ICU 4.8 0644 */ 0645 virtual AlphabeticIndex &resetRecordIterator(); 0646 0647 private: 0648 /** 0649 * No Copy constructor. 0650 * @internal (private) 0651 */ 0652 AlphabeticIndex(const AlphabeticIndex &other) = delete; 0653 0654 /** 0655 * No assignment. 0656 */ 0657 AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;} 0658 0659 /** 0660 * No Equality operators. 0661 * @internal (private) 0662 */ 0663 virtual bool operator==(const AlphabeticIndex& other) const; 0664 0665 /** 0666 * Inequality operator. 0667 * @internal (private) 0668 */ 0669 virtual bool operator!=(const AlphabeticIndex& other) const; 0670 0671 // Common initialization, for use from all constructors. 0672 void init(const Locale *locale, UErrorCode &status); 0673 0674 /** 0675 * This method is called to get the index exemplars. Normally these come from the locale directly, 0676 * but if they aren't available, we have to synthesize them. 0677 */ 0678 void addIndexExemplars(const Locale &locale, UErrorCode &status); 0679 /** 0680 * Add Chinese index characters from the tailoring. 0681 */ 0682 UBool addChineseIndexCharacters(UErrorCode &errorCode); 0683 0684 UVector *firstStringsInScript(UErrorCode &status); 0685 0686 static UnicodeString separated(const UnicodeString &item); 0687 0688 /** 0689 * Determine the best labels to use. 0690 * This is based on the exemplars, but we also process to make sure that they are unique, 0691 * and sort differently, and that the overall list is small enough. 0692 */ 0693 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const; 0694 BucketList *createBucketList(UErrorCode &errorCode) const; 0695 void initBuckets(UErrorCode &errorCode); 0696 void clearBuckets(); 0697 void internalResetBucketIterator(); 0698 0699 public: 0700 0701 // The Record is declared public only to allow access from 0702 // implementation code written in plain C. 0703 // It is not intended for public use. 0704 0705 #ifndef U_HIDE_INTERNAL_API 0706 /** 0707 * A (name, data) pair, to be sorted by name into one of the index buckets. 0708 * The user data is not used by the index implementation. 0709 * \cond 0710 * @internal 0711 */ 0712 struct Record: public UMemory { 0713 const UnicodeString name_; 0714 const void *data_; 0715 Record(const UnicodeString &name, const void *data); 0716 ~Record(); 0717 }; 0718 /** \endcond */ 0719 #endif /* U_HIDE_INTERNAL_API */ 0720 0721 private: 0722 0723 /** 0724 * Holds all user records before they are distributed into buckets. 0725 * Type of contents is (Record *) 0726 * @internal (private) 0727 */ 0728 UVector *inputList_; 0729 0730 int32_t labelsIterIndex_; // Index of next item to return. 0731 int32_t itemsIterIndex_; 0732 Bucket *currentBucket_; // While an iteration of the index in underway, 0733 // point to the bucket for the current label. 0734 // nullptr when no iteration underway. 0735 0736 int32_t maxLabelCount_; // Limit on # of labels permitted in the index. 0737 0738 UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union 0739 // of those explicitly set by the user plus 0740 // those from locales. Raw values, before 0741 // crunching into bucket labels. 0742 0743 UVector *firstCharsInScripts_; // The first character from each script, 0744 // in collation order. 0745 0746 RuleBasedCollator *collator_; 0747 RuleBasedCollator *collatorPrimaryOnly_; 0748 0749 // Lazy evaluated: null means that we have not built yet. 0750 BucketList *buckets_; 0751 0752 UnicodeString inflowLabel_; 0753 UnicodeString overflowLabel_; 0754 UnicodeString underflowLabel_; 0755 UnicodeString overflowComparisonString_; 0756 0757 UnicodeString emptyString_; 0758 }; 0759 0760 U_NAMESPACE_END 0761 0762 #endif // !UCONFIG_NO_COLLATION 0763 0764 #endif /* U_SHOW_CPLUSPLUS_API */ 0765 0766 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |