ICU 75.1 75.1
Loading...
Searching...
No Matches
alphaindex.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5*
6* Copyright (C) 2011-2014 International Business Machines
7* Corporation and others. All Rights Reserved.
8*
9*******************************************************************************
10*/
11
12#ifndef INDEXCHARS_H
13#define INDEXCHARS_H
14
15#include "unicode/utypes.h"
16
17#if U_SHOW_CPLUSPLUS_API
18
19#include "unicode/uobject.h"
20#include "unicode/locid.h"
21#include "unicode/unistr.h"
22
23#if !UCONFIG_NO_COLLATION
24
31
70
71
72struct UHashtable;
74
75U_NAMESPACE_BEGIN
76
77// Forward Declarations
78
79class BucketList;
80class Collator;
81class RuleBasedCollator;
82class StringEnumeration;
83class UnicodeSet;
84class UVector;
85
193public:
202 class U_I18N_API Bucket : public UObject {
203 public:
208 virtual ~Bucket();
209
216 const UnicodeString &getLabel() const { return label_; }
223 UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
224
225 private:
226 friend class AlphabeticIndex;
227 friend class BucketList;
228
229 UnicodeString label_;
230 UnicodeString lowerBoundary_;
231 UAlphabeticIndexLabelType labelType_;
232 Bucket *displayBucket_;
233 int32_t displayIndex_;
234 UVector *records_; // Records are owned by the inputList_ vector.
235
236 Bucket(const UnicodeString &label, // Parameter strings are copied.
239 };
240
252 public:
258
266
277 int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
278
286 const Bucket *getBucket(int32_t index) const;
287
288 private:
289 friend class AlphabeticIndex;
290
292 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
293
294 BucketList *buckets_;
295 Collator *collatorPrimaryOnly_;
296 };
297
311
327
339
354
360
368
381 virtual const RuleBasedCollator &getCollator() const;
382
383
393 virtual const UnicodeString &getInflowLabel() const;
394
407
408
416 virtual const UnicodeString &getOverflowLabel() const;
417
418
429
437 virtual const UnicodeString &getUnderflowLabel() const;
438
449
450
458 virtual int32_t getMaxLabelCount() const;
459
473
474
491 virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
492
502
503
513
514
524
525
526
540
541
548 virtual int32_t getBucketIndex() const;
549
550
563
572 virtual const UnicodeString &getBucketLabel() const;
573
582
592
593
603
616
625 virtual const UnicodeString &getRecordName() const;
626
627
636 virtual const void *getRecordData() const;
637
638
646
647private:
652 AlphabeticIndex(const AlphabeticIndex &other) = delete;
653
657 AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;}
658
663 virtual bool operator==(const AlphabeticIndex& other) const;
664
669 virtual bool operator!=(const AlphabeticIndex& other) const;
670
671 // Common initialization, for use from all constructors.
672 void init(const Locale *locale, UErrorCode &status);
673
678 void addIndexExemplars(const Locale &locale, UErrorCode &status);
682 UBool addChineseIndexCharacters(UErrorCode &errorCode);
683
684 UVector *firstStringsInScript(UErrorCode &status);
685
686 static UnicodeString separated(const UnicodeString &item);
687
693 void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
694 BucketList *createBucketList(UErrorCode &errorCode) const;
695 void initBuckets(UErrorCode &errorCode);
696 void clearBuckets();
697 void internalResetBucketIterator();
698
699public:
700
701 // The Record is declared public only to allow access from
702 // implementation code written in plain C.
703 // It is not intended for public use.
704
705#ifndef U_HIDE_INTERNAL_API
712 struct Record: public UMemory {
713 const UnicodeString name_;
714 const void *data_;
715 Record(const UnicodeString &name, const void *data);
716 ~Record();
717 };
719#endif /* U_HIDE_INTERNAL_API */
720
721private:
722
728 UVector *inputList_;
729
730 int32_t labelsIterIndex_; // Index of next item to return.
731 int32_t itemsIterIndex_;
732 Bucket *currentBucket_; // While an iteration of the index in underway,
733 // point to the bucket for the current label.
734 // nullptr when no iteration underway.
735
736 int32_t maxLabelCount_; // Limit on # of labels permitted in the index.
737
738 UnicodeSet *initialLabels_; // Initial (unprocessed) set of Labels. Union
739 // of those explicitly set by the user plus
740 // those from locales. Raw values, before
741 // crunching into bucket labels.
742
743 UVector *firstCharsInScripts_; // The first character from each script,
744 // in collation order.
745
746 RuleBasedCollator *collator_;
747 RuleBasedCollator *collatorPrimaryOnly_;
748
749 // Lazy evaluated: null means that we have not built yet.
750 BucketList *buckets_;
751
752 UnicodeString inflowLabel_;
753 UnicodeString overflowLabel_;
754 UnicodeString underflowLabel_;
755 UnicodeString overflowComparisonString_;
756
757 UnicodeString emptyString_;
758};
759
760U_NAMESPACE_END
761
762#endif // !UCONFIG_NO_COLLATION
763
764#endif /* U_SHOW_CPLUSPLUS_API */
765
766#endif
UAlphabeticIndexLabelType
Constants for Alphabetic Index Label Types.
Definition alphaindex.h:38
@ U_ALPHAINDEX_OVERFLOW
Overflow Label.
Definition alphaindex.h:68
@ U_ALPHAINDEX_UNDERFLOW
Underflow Label.
Definition alphaindex.h:51
@ 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
Inflow Label.
Definition alphaindex.h:61
An index "bucket" with a label string and type.
Definition alphaindex.h:202
UAlphabeticIndexLabelType getLabelType() const
Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
Definition alphaindex.h:223
const UnicodeString & getLabel() const
Returns the label string.
Definition alphaindex.h:216
virtual ~Bucket()
Destructor.
Immutable, thread-safe version of AlphabeticIndex.
Definition alphaindex.h:251
int32_t getBucketCount() const
Returns the number of index buckets and labels, including underflow/inflow/overflow.
const Bucket * getBucket(int32_t index) const
Returns the index-th bucket.
int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const
Finds the index bucket for the given name and returns the number of that bucket.
virtual ~ImmutableIndex()
Destructor.
AlphabeticIndex supports the creation of a UI index appropriate for a given language.
Definition alphaindex.h:192
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...
virtual const void * getRecordData() const
Return the data pointer of the Record currently being iterated over.
virtual UBool nextRecord(UErrorCode &status)
Advance to the next record in the current Bucket.
virtual const RuleBasedCollator & getCollator() const
Get the Collator that establishes the ordering of the items in this index.
virtual AlphabeticIndex & addLabels(const UnicodeSet &additions, UErrorCode &status)
Add Labels to this Index.
AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status)
Construct an AlphabeticIndex that uses a specific collator.
virtual int32_t getRecordCount(UErrorCode &status)
Get the total number of Records in this index, that is, the number of <name, data> pairs added.
virtual ~AlphabeticIndex()
Destructor.
virtual AlphabeticIndex & addRecord(const UnicodeString &name, const void *data, UErrorCode &status)
Add a record to the index.
virtual const UnicodeString & getUnderflowLabel() const
Get the special label used for items that sort before the first normal label, and that would not othe...
virtual AlphabeticIndex & resetRecordIterator()
Reset the Record iterator position to before the first Record in the current Bucket.
virtual const UnicodeString & getBucketLabel() const
Return the name of the Label of the current bucket from an iteration over the buckets.
virtual const UnicodeString & getRecordName() const
Get the name of the current Record.
virtual const UnicodeString & getInflowLabel() const
Get the default label used for abbreviated buckets between other index characters.
virtual UBool nextBucket(UErrorCode &status)
Advance the iteration over the Buckets of this index.
AlphabeticIndex(const Locale &locale, UErrorCode &status)
Construct an AlphabeticIndex object for the specified locale.
virtual AlphabeticIndex & clearRecords(UErrorCode &status)
Remove all Records from the Index.
ImmutableIndex * buildImmutableIndex(UErrorCode &errorCode)
Builds an immutable, thread-safe version of this instance, without data records.
virtual AlphabeticIndex & setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status)
Set the default label used for abbreviated buckets between other index characters.
virtual AlphabeticIndex & setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status)
Set a limit on the number of labels permitted in the index.
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...
virtual int32_t getBucketIndex() const
Get the zero based index of the current Bucket from an iteration over the Buckets of this index.
virtual AlphabeticIndex & addLabels(const Locale &locale, UErrorCode &status)
Add the index characters from a Locale to the index.
virtual const UnicodeString & getOverflowLabel() const
Get the special label used for items that sort after the last normal label, and that would not otherw...
virtual AlphabeticIndex & resetBucketIterator(UErrorCode &status)
Reset the Bucket iteration for this index.
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...
virtual int32_t getBucketRecordCount() const
Get the number of <name, data> Records in the current Bucket.
virtual int32_t getBucketCount(UErrorCode &status)
Get the number of labels in this index.
virtual UAlphabeticIndexLabelType getBucketLabelType() const
Return the type of the label for the current Bucket (selected by the iteration over Buckets....
virtual int32_t getMaxLabelCount() const
Get the limit on the number of labels permitted in the index.
The Collator class performs locale-sensitive string comparison.
Definition coll.h:167
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:115
UMemory is the common ICU base class.
Definition uobject.h:115
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:285
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
C++ API: Locale ID object.
struct UHashtable UHashtable
Definition msgfmt.h:43
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:86
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:85
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:415
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301