/** * File coll.cpp * * Created by: Helena Shih * * Modification History: * * Date Name Description * 2/5/97 aliu Modified createDefault to load collation data from * binary files when possible. Added related methods * createCollationFromFile, chopLocale, createPathName. * 2/11/97 aliu Added methods addToCache, findInCache, which implement * a Collation cache. Modified createDefault to look in * cache first, and also to store newly created Collation * objects in the cache. Modified to not use gLocPath. * 2/12/97 aliu Modified to create objects from RuleBasedCollator cache. * Moved cache out of Collation class. * 2/13/97 aliu Moved several methods out of this class and into * RuleBasedCollator, with modifications. Modified * createDefault() to call new RuleBasedCollator(Locale&) * constructor. General clean up and documentation. * 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy * constructor. * 05/06/97 helena Added memory allocation error detection. * 05/08/97 helena Added createInstance(). * 6/20/97 helena Java class name change. * 04/23/99 stephen Removed EDecompositionMode, merged with * Normalizer::EMode * 11/23/9 srl Inlining of some critical functions * 01/29/01 synwee Modified into a C++ wrapper calling C APIs (ucol.h) * 2012-2014 markus Rewritten in C++ again.
*/
UObject*
ICUCollatorFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const { if (handlesKey(key, status)) { const LocaleKey& lkey = static_cast<const LocaleKey&>(key);
Locale loc; // make sure the requested locale is correct // default LocaleFactory uses currentLocale since that's the one vetted by handlesKey // but for ICU rb resources we use the actual one since it will fallback again
lkey.canonicalLocale(loc);
virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualID, UErrorCode& status) const override { const LocaleKey* lkey = dynamic_cast<const LocaleKey*>(&key);
U_ASSERT(lkey != nullptr); if (actualID) { // Ugly Hack Alert! We return an empty actualID to signal // to callers that this is a default object, not a "real" // service-created object. (TODO remove in 3.0) [aliu]
actualID->truncate(0);
}
Locale loc("");
lkey->canonicalLocale(loc); return Collator::makeInstance(loc, status);
}
staticvoid U_CALLCONV
initAvailableLocaleList(UErrorCode &status) {
U_ASSERT(availableLocaleListCount == 0);
U_ASSERT(availableLocaleList == nullptr); // for now, there is a hardcoded list, so just walk through that list and set it up.
UResourceBundle *index = nullptr;
StackUResourceBundle installed;
int32_t i = 0;
index = ures_openDirect(U_ICUDATA_COLL, "res_index", &status);
ures_getByKey(index, "InstalledLocales", installed.getAlias(), &status);
if(U_SUCCESS(status)) {
availableLocaleListCount = ures_getSize(installed.getAlias());
availableLocaleList = new Locale[availableLocaleListCount];
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale,
UErrorCode& status)
{ if (U_FAILURE(status)) return nullptr; if (desiredLocale.isBogus()) { // Locale constructed from malformed locale ID or language tag.
status = U_ILLEGAL_ARGUMENT_ERROR; return nullptr;
}
Collator* coll; #if !UCONFIG_NO_SERVICE if (hasService()) {
Locale actualLoc;
coll = (Collator*)gService->get(desiredLocale, &actualLoc, status);
} else #endif
{
coll = makeInstance(desiredLocale, status); // Either returns nullptr with U_FAILURE(status), or non-nullptr with U_SUCCESS(status)
} // The use of *coll in setAttributesFromKeywords can cause the nullptr check to be // optimized out of the delete even though setAttributesFromKeywords returns // immediately if U_FAILURE(status), so we add a check here. if (U_FAILURE(status)) { return nullptr;
}
setAttributesFromKeywords(desiredLocale, *coll, status); if (U_FAILURE(status)) { delete coll; return nullptr;
} return coll;
}
Collator* Collator::makeInstance(const Locale& desiredLocale, UErrorCode& status) { const CollationCacheEntry *entry = CollationLoader::loadTailoring(desiredLocale, status); if (U_SUCCESS(status)) {
Collator *result = new RuleBasedCollator(entry); if (result != nullptr) { // Both the unified cache's get() and the RBC constructor // did addRef(). Undo one of them.
entry->removeRef(); return result;
}
status = U_MEMORY_ALLOCATION_ERROR;
} if (entry != nullptr) { // Undo the addRef() from the cache.get().
entry->removeRef();
} return nullptr;
}
UCollationResult Collator::compare(UCharIterator &/*sIter*/,
UCharIterator &/*tIter*/,
UErrorCode &status) const { if(U_SUCCESS(status)) { // Not implemented in the base class.
status = U_UNSUPPORTED_ERROR;
} return UCOL_EQUAL;
}
// this API ignores registered collators, since it returns an // array of indefinite lifetime const Locale* U_EXPORT2 Collator::getAvailableLocales(int32_t& count)
{
UErrorCode status = U_ZERO_ERROR;
Locale *result = nullptr;
count = 0; if (isAvailableLocaleListInitialized(status))
{
result = availableLocaleList;
count = availableLocaleListCount;
} return result;
}
/* This is useless information */ /*void Collator::getVersion(UVersionInfo versionInfo) const { if (versionInfo!=nullptr) uprv_memcpy(versionInfo, fVersion, U_MAX_VERSION_LENGTH); }
*/
/** * Default constructor. * Constructor is different from the old default Collator constructor. * The task for determining the default collation strength and normalization mode * is left to the child class.
*/
Collator::Collator()
: UObject()
{
}
/** * Constructor. * Empty constructor, does not handle the arguments. * This constructor is done for backward compatibility with 1.7 and 1.8. * The task for handling the argument collation strength and normalization * mode is left to the child class. * @param collationStrength collation strength * @param decompositionMode * @deprecated 2.4 use the default constructor instead
*/
Collator::Collator(UCollationStrength, UNormalizationMode )
: UObject()
{
}
bool Collator::operator==(const Collator& other) const
{ // Subclasses: Call this method and then add more specific checks. returntypeid(*this) == typeid(other);
}
UnicodeSet *Collator::getTailoredSet(UErrorCode &status) const
{ if(U_FAILURE(status)) { return nullptr;
} // everything can be changed returnnew UnicodeSet(0, 0x10FFFF);
}
// -------------------------------------
#if !UCONFIG_NO_SERVICE
URegistryKey U_EXPORT2
Collator::registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status)
{ if (U_SUCCESS(status)) { // Set the collator locales while registering so that createInstance() // need not guess whether the collator's locales are already set properly // (as they are by the data loader).
toAdopt->setLocales(locale, locale, locale); return getService()->registerInstance(toAdopt, locale, status);
} return nullptr;
}
// -------------------------------------
class CFactory : public LocaleKeyFactory { private:
CollatorFactory* _delegate;
Hashtable* _ids;
public:
CFactory(CollatorFactory* delegate, UErrorCode& status)
: LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
, _delegate(delegate)
, _ids(nullptr)
{ if (U_SUCCESS(status)) {
int32_t count = 0;
_ids = new Hashtable(status); if (_ids) { const UnicodeString * idlist = _delegate->getSupportedIDs(count, status); for (int i = 0; i < count; ++i) {
_ids->put(idlist[i], (void*)this, status); if (U_FAILURE(status)) { delete _ids;
_ids = nullptr; return;
}
}
} else {
status = U_MEMORY_ALLOCATION_ERROR;
}
}
}
// UCollator private data members ----------------------------------------
/* This is useless information */ /*const UVersionInfo Collator::fVersion = {1, 1, 0, 0};*/
// -------------------------------------
U_NAMESPACE_END
#endif/* #if !UCONFIG_NO_COLLATION */
/* eof */
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.18Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.