alphaindex.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
*
* Copyright (C) 2011-2014 International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
*/
#ifndef INDEXCHARS_H
#define INDEXCHARS_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#include "unicode/uobject.h"
#include "unicode/locid.h"
#include "unicode/unistr.h"
#if !UCONFIG_NO_COLLATION
U_CDECL_BEGIN
typedef enum UAlphabeticIndexLabelType {
U_ALPHAINDEX_NORMAL = 0,
U_ALPHAINDEX_UNDERFLOW = 1,
U_ALPHAINDEX_INFLOW = 2,
U_ALPHAINDEX_OVERFLOW = 3
} UAlphabeticIndexLabelType;
struct UHashtable;
U_CDECL_END
U_NAMESPACE_BEGIN
// Forward Declarations
class BucketList;
class Collator;
class RuleBasedCollator;
class StringEnumeration;
class UnicodeSet;
class UVector;
class U_I18N_API AlphabeticIndex: public UObject {
public:
class U_I18N_API Bucket : public UObject {
public:
virtual ~Bucket();
const UnicodeString &getLabel() const { return label_; }
UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
private:
friend class AlphabeticIndex;
friend class BucketList;
UnicodeString label_;
UnicodeString lowerBoundary_;
UAlphabeticIndexLabelType labelType_;
Bucket *displayBucket_;
int32_t displayIndex_;
UVector *records_; // Records are owned by the inputList_ vector.
Bucket(const UnicodeString &label, // Parameter strings are copied.
const UnicodeString &lowerBoundary,
UAlphabeticIndexLabelType type);
};
class U_I18N_API ImmutableIndex : public UObject {
public:
virtual ~ImmutableIndex();
int32_t getBucketCount() const;
int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
const Bucket *getBucket(int32_t index) const;
private:
friend class AlphabeticIndex;
ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
: buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
BucketList *buckets_;
Collator *collatorPrimaryOnly_;
};
AlphabeticIndex(const Locale &locale, UErrorCode &status);
AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
virtual ~AlphabeticIndex();
ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
virtual const RuleBasedCollator &getCollator() const;
virtual const UnicodeString &getInflowLabel() const;
virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
virtual const UnicodeString &getOverflowLabel() const;
virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
virtual const UnicodeString &getUnderflowLabel() const;
virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
virtual int32_t getMaxLabelCount() const;
virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
virtual AlphabeticIndex &clearRecords(UErrorCode &status);
virtual int32_t getBucketCount(UErrorCode &status);
virtual int32_t getRecordCount(UErrorCode &status);
virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
virtual int32_t getBucketIndex() const;
virtual UBool nextBucket(UErrorCode &status);
virtual const UnicodeString &getBucketLabel() const;
virtual UAlphabeticIndexLabelType getBucketLabelType() const;
virtual int32_t getBucketRecordCount() const;
virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
virtual UBool nextRecord(UErrorCode &status);
virtual const UnicodeString &getRecordName() const;
virtual const void *getRecordData() const;
virtual AlphabeticIndex &resetRecordIterator();
private:
AlphabeticIndex(const AlphabeticIndex &other) = delete;
AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;}
virtual bool operator==(const AlphabeticIndex& other) const;
virtual bool operator!=(const AlphabeticIndex& other) const;
// Common initialization, for use from all constructors.
void init(const Locale *locale, UErrorCode &status);
void addIndexExemplars(const Locale &locale, UErrorCode &status);
UBool addChineseIndexCharacters(UErrorCode &errorCode);
UVector *firstStringsInScript(UErrorCode &status);
static UnicodeString separated(const UnicodeString &item);
void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
BucketList *createBucketList(UErrorCode &errorCode) const;
void initBuckets(UErrorCode &errorCode);
void clearBuckets();
void internalResetBucketIterator();
public:
// The Record is declared public only to allow access from
// implementation code written in plain C.
// It is not intended for public use.
#ifndef U_HIDE_INTERNAL_API
struct Record: public UMemory {
const UnicodeString name_;
const void *data_;
Record(const UnicodeString &name, const void *data);
~Record();
};
#endif /* U_HIDE_INTERNAL_API */
private:
UVector *inputList_;
int32_t labelsIterIndex_; // Index of next item to return.
int32_t itemsIterIndex_;
Bucket *currentBucket_; // While an iteration of the index in underway,
// point to the bucket for the current label.
// nullptr when no iteration underway.
int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
// of those explicitly set by the user plus
// those from locales. Raw values, before
// crunching into bucket labels.
UVector *firstCharsInScripts_; // The first character from each script,
// in collation order.
RuleBasedCollator *collator_;
RuleBasedCollator *collatorPrimaryOnly_;
// Lazy evaluated: null means that we have not built yet.
BucketList *buckets_;
UnicodeString inflowLabel_;
UnicodeString overflowLabel_;
UnicodeString underflowLabel_;
UnicodeString overflowComparisonString_;
UnicodeString emptyString_;
};
U_NAMESPACE_END
#endif // !UCONFIG_NO_COLLATION
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
UAlphabeticIndexLabelType
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition alphaindex.h:38
U_ALPHAINDEX_OVERFLOW
@ U_ALPHAINDEX_OVERFLOW
Overflow Label.
Definition alphaindex.h:68
U_ALPHAINDEX_UNDERFLOW
@ U_ALPHAINDEX_UNDERFLOW
Underflow Label.
Definition alphaindex.h:51
U_ALPHAINDEX_NORMAL
@ U_ALPHAINDEX_NORMAL
Normal Label, typically the starting letter of the names in the bucket with this label.
Definition alphaindex.h:44
U_ALPHAINDEX_INFLOW
@ U_ALPHAINDEX_INFLOW
Inflow Label.
Definition alphaindex.h:61
icu::AlphabeticIndex::Bucket
An index "bucket" with a label string and type.
Definition alphaindex.h:202
icu::AlphabeticIndex::Bucket::getLabelType
UAlphabeticIndexLabelType getLabelType() const
Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
Definition alphaindex.h:223
icu::AlphabeticIndex::Bucket::getLabel
const UnicodeString & getLabel() const
Returns the label string.
Definition alphaindex.h:216
icu::AlphabeticIndex::Bucket::~Bucket
virtual ~Bucket()
Destructor.
icu::AlphabeticIndex::ImmutableIndex
Immutable, thread-safe version of AlphabeticIndex.
Definition alphaindex.h:251
icu::AlphabeticIndex::ImmutableIndex::getBucketCount
int32_t getBucketCount() const
Returns the number of index buckets and labels, including underflow/inflow/overflow.
icu::AlphabeticIndex::ImmutableIndex::getBucket
const Bucket * getBucket(int32_t index) const
Returns the index-th bucket.
icu::AlphabeticIndex::ImmutableIndex::getBucketIndex
int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const
Finds the index bucket for the given name and returns the number of that bucket.
icu::AlphabeticIndex::ImmutableIndex::~ImmutableIndex
virtual ~ImmutableIndex()
Destructor.
icu::AlphabeticIndex
AlphabeticIndex supports the creation of a UI index appropriate for a given language.
Definition alphaindex.h:192
icu::AlphabeticIndex::setOverflowLabel
virtual AlphabeticIndex & setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status)
Set the label used for items that sort after the last normal label, and that would not otherwise have...
icu::AlphabeticIndex::getRecordData
virtual const void * getRecordData() const
Return the data pointer of the Record currently being iterated over.
icu::AlphabeticIndex::nextRecord
virtual UBool nextRecord(UErrorCode &status)
Advance to the next record in the current Bucket.
icu::AlphabeticIndex::getCollator
virtual const RuleBasedCollator & getCollator() const
Get the Collator that establishes the ordering of the items in this index.
icu::AlphabeticIndex::addLabels
virtual AlphabeticIndex & addLabels(const UnicodeSet &additions, UErrorCode &status)
Add Labels to this Index.
icu::AlphabeticIndex::AlphabeticIndex
AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status)
Construct an AlphabeticIndex that uses a specific collator.
icu::AlphabeticIndex::getRecordCount
virtual int32_t getRecordCount(UErrorCode &status)
Get the total number of Records in this index, that is, the number of <name, data> pairs added.
icu::AlphabeticIndex::~AlphabeticIndex
virtual ~AlphabeticIndex()
Destructor.
icu::AlphabeticIndex::addRecord
virtual AlphabeticIndex & addRecord(const UnicodeString &name, const void *data, UErrorCode &status)
Add a record to the index.
icu::AlphabeticIndex::getUnderflowLabel
virtual const UnicodeString & getUnderflowLabel() const
Get the special label used for items that sort before the first normal label, and that would not othe...
icu::AlphabeticIndex::resetRecordIterator
virtual AlphabeticIndex & resetRecordIterator()
Reset the Record iterator position to before the first Record in the current Bucket.
icu::AlphabeticIndex::getBucketLabel
virtual const UnicodeString & getBucketLabel() const
Return the name of the Label of the current bucket from an iteration over the buckets.
icu::AlphabeticIndex::getRecordName
virtual const UnicodeString & getRecordName() const
Get the name of the current Record.
icu::AlphabeticIndex::getInflowLabel
virtual const UnicodeString & getInflowLabel() const
Get the default label used for abbreviated buckets between other index characters.
icu::AlphabeticIndex::nextBucket
virtual UBool nextBucket(UErrorCode &status)
Advance the iteration over the Buckets of this index.
icu::AlphabeticIndex::AlphabeticIndex
AlphabeticIndex(const Locale &locale, UErrorCode &status)
Construct an AlphabeticIndex object for the specified locale.
icu::AlphabeticIndex::clearRecords
virtual AlphabeticIndex & clearRecords(UErrorCode &status)
Remove all Records from the Index.
icu::AlphabeticIndex::buildImmutableIndex
ImmutableIndex * buildImmutableIndex(UErrorCode &errorCode)
Builds an immutable, thread-safe version of this instance, without data records.
icu::AlphabeticIndex::setInflowLabel
virtual AlphabeticIndex & setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status)
Set the default label used for abbreviated buckets between other index characters.
icu::AlphabeticIndex::setMaxLabelCount
virtual AlphabeticIndex & setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status)
Set a limit on the number of labels permitted in the index.
icu::AlphabeticIndex::getBucketIndex
virtual int32_t getBucketIndex(const UnicodeString &itemName, UErrorCode &status)
Given the name of a record, return the zero-based index of the Bucket in which the item should appear...
icu::AlphabeticIndex::getBucketIndex
virtual int32_t getBucketIndex() const
Get the zero based index of the current Bucket from an iteration over the Buckets of this index.
icu::AlphabeticIndex::addLabels
virtual AlphabeticIndex & addLabels(const Locale &locale, UErrorCode &status)
Add the index characters from a Locale to the index.
icu::AlphabeticIndex::getOverflowLabel
virtual const UnicodeString & getOverflowLabel() const
Get the special label used for items that sort after the last normal label, and that would not otherw...
icu::AlphabeticIndex::resetBucketIterator
virtual AlphabeticIndex & resetBucketIterator(UErrorCode &status)
Reset the Bucket iteration for this index.
icu::AlphabeticIndex::setUnderflowLabel
virtual AlphabeticIndex & setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status)
Set the label used for items that sort before the first normal label, and that would not otherwise ha...
icu::AlphabeticIndex::getBucketRecordCount
virtual int32_t getBucketRecordCount() const
Get the number of <name, data> Records in the current Bucket.
icu::AlphabeticIndex::getBucketCount
virtual int32_t getBucketCount(UErrorCode &status)
Get the number of labels in this index.
icu::AlphabeticIndex::getBucketLabelType
virtual UAlphabeticIndexLabelType getBucketLabelType() const
Return the type of the label for the current Bucket (selected by the iteration over Buckets....
icu::AlphabeticIndex::getMaxLabelCount
virtual int32_t getMaxLabelCount() const
Get the limit on the number of labels permitted in the index.
icu::Collator
The Collator class performs locale-sensitive string comparison.
Definition coll.h:173
icu::LocalPointerBase
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Definition localpointer.h:68
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:115
icu::UMemory
UMemory is the common ICU base class.
Definition uobject.h:115
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:285
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
locid.h
C++ API: Locale ID object.
UHashtable
struct UHashtable UHashtable
Definition msgfmt.h:43
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition stringpiece.h:346
U_CDECL_END
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:86
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
U_CDECL_BEGIN
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:85
unistr.h
C++ API: Unicode String.
uobject.h
C++ API: Common ICU base class UObject.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316