/* ******************************************************************************* * * Copyright (C) 2011 International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* */ #ifndef INDEXCHARS_H #define INDEXCHARS_H #include "unicode/utypes.h" #include "unicode/uobject.h" #include "unicode/locid.h" /** * \file * \brief C++ API: Index Characters */ U_CDECL_BEGIN /** * Constants for Alphabetic Index Label Types. * The form of these enum constants anticipates having a plain C API * for Alphabetic Indexes that will also use them. * @draft ICU 4.8 */ typedef enum UAlphabeticIndexLabelType { /** * Normal Label, typically the starting letter of the names * in the bucket with this label. * @draft ICU 4.8 */ U_ALPHAINDEX_NORMAL = 0, /** * Undeflow Label. The bucket with this label contains names * in scripts that sort before any of the bucket labels in this index. * @draft ICU 4.8 */ U_ALPHAINDEX_UNDERFLOW = 1, /** * Inflow Label. The bucket with this label contains names * in scripts that sort between two of the bucket labels in this index. * Inflow labels are created when an index contains normal labels for * multiple scripts, and skips other scripts that sort between some of the * included scripts. * @draft ICU 4.8 */ U_ALPHAINDEX_INFLOW = 2, /** * Overflow Label. Te bucket with this label contains names in scripts * that sort after all of the bucket labels in this index. * @draft ICU 4.8 */ U_ALPHAINDEX_OVERFLOW = 3 } UAlphabeticIndexLabelType; struct UHashtable; U_CDECL_END U_NAMESPACE_BEGIN // Forward Declarations class Collator; class RuleBasedCollator; class StringEnumeration; class UnicodeSet; class UVector; /** * class AlphabeticIndex supports the creation of a UI index appropriate for a given language, such as: * *
 *  ... 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 \u00C6 \u00D8 \u00C5 ...
 *
 *  A
 *     Addison
 *     Albertson
 *     Azensky
 *  B
 *     Baker
 *  ...
 * 
* * The class can generate a list of labels for use as a UI "index", that is, a list of * clickable characters (or character sequences) that allow the user to see a segment * (bucket) of a larger "target" list. That is, each label corresponds to a bucket in * the target list, where everything in the bucket is greater than or equal to the character * (according to the locale's collation). Strings can be added to the index; * they will be in sorted order in the right bucket. *

* The class also supports having buckets for strings before the first (underflow), * after the last (overflow), and between scripts (inflow). For example, if the index * is constructed with labels for Russian and English, Greek characters would fall * into an inflow bucket between the other two scripts. *

* The AlphabeticIndex class is not intended for public subclassing. *

* Example *

* The "show..." methods below are just to illustrate usage. * *

 * // Create a simple index.  "Item" is assumed to be an application
 * // defined type that the application's UI and other processing knows about,
 * //  and that has a name.
 *
 * UErrorCode status = U_ZERO_ERROR;
 * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status);
 * index->addLabels(additionalLocale, status);
 * for (Item *item in some source of Items ) {
 *     index->addRecord(item->name(), item, status);
 * }
 * ...
 * // Show index at top. We could skip or gray out empty buckets
 *
 * while (index->nextBucket(status)) {
 *     if (showAll || index->getBucketRecordCount() != 0) {
 *         showLabelAtTop(UI, index->getBucketLabel());
 *     }
 * }
 *  ...
 * // Show the buckets with their contents, skipping empty buckets
 *
 * index->resetBucketIterator(status);
 * while (index->nextBucket(status)) {
 *    if (index->getBucketRecordCount() != 0) {
 *        showLabelInList(UI, index->getBucketLabel());
 *        while (index->nextRecord(status)) {
 *            showIndexedItem(UI, static_cast(index->getRecordData()))
 * 
* * The caller can build different UIs using this class. * For example, an index character could be omitted or grayed-out * if its bucket is empty. Small buckets could also be combined based on size, such as: * *
 * ... A-F G-N O-Z ...
 * 
* *

* Notes: *