/*
*******************************************************************************
-* Copyright (C) 2009-2012, International Business Machines Corporation and *
+* Copyright (C) 2009-2013, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
}
+AlphabeticIndex::AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status) {
+ init(status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (collator == NULL) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ collator_ = collator;
+ collatorPrimaryOnly_ = collator_->clone();
+ if (collatorPrimaryOnly_ == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ collatorPrimaryOnly_->setStrength(Collator::PRIMARY);
+ // Note: initialLabels_ is set to an empty UnicodeSet by init().
+ indexBuildRequired_ = TRUE;
+ firstScriptCharacters_ = firstStringsInScript(status);
+}
+
+
+
AlphabeticIndex::~AlphabeticIndex() {
uhash_close(alreadyIn_);
delete bucketList_;
// If we have no labels, hard-code a fallback default set of [A-Z]
// This case can occur with locales that don't have exemplar character data, including root.
// A no-labels situation will cause other problems; it needs to be avoided.
+ //
+ // TODO: This case should be handled by having an underflow label only.
if (labelSet.isEmpty()) {
labelSet.add((UChar32)0x41, (UChar32)0x5A);
}
/*
*******************************************************************************
*
-* Copyright (C) 2011-2012 International Business Machines
+* Copyright (C) 2011-2013 International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
AlphabeticIndex(const Locale &locale, UErrorCode &status);
+ /**
+ * Construct an AlphabeticIndex that uses a specific collator.
+ *
+ * The index will be created with no labels; the addLabels() function must be called
+ * after creation to add the desired labels to the index.
+ *
+ * The index adopts the collator, and is responsible for deleting it.
+ * The caller should make no further use of the collator after creating the index.
+ *
+ * @param collator The collator to use to order the contents of this index.
+ * @param status Error code, will be set with the reason if the
+ * operation fails.
+ * @draft ICU 51
+ */
+ AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
/**
* Add Labels to this Index. The labels are additions to those
//printf("getBucketCount() == %d\n", lc);
delete index;
+ // Constructor from a Collator
+ //
+ status = U_ZERO_ERROR;
+ RuleBasedCollator *coll = dynamic_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChinese(), status));
+ TEST_CHECK_STATUS;
+ TEST_ASSERT(coll != NULL);
+ index = new AlphabeticIndex(coll, status);
+ TEST_CHECK_STATUS;
+ TEST_ASSERT(coll == &index->getCollator());
+ // TODO: The bucket count for an index built from a collator should be one, the underflow label.
+ // The current implementation adds A-Z if the index is otherwise empty.
+ // TEST_ASSERT(1 == index->getBucketCount(status));
+ TEST_ASSERT(28 == index->getBucketCount(status));
+ TEST_CHECK_STATUS;
+ delete index;
+
+
// addLabels()
status = U_ZERO_ERROR;