Ejemplo n.º 1
0
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale,
                                   UErrorCode& status)
{
    if (U_FAILURE(status)) 
        return 0;
    
#if !UCONFIG_NO_SERVICE
    if (hasService()) {
        Locale actualLoc;
        Collator *result =
            (Collator*)gService->get(desiredLocale, &actualLoc, status);
        // Ugly Hack Alert! If the returned locale is empty (not root,
        // but empty -- getName() == "") then that means the service
        // returned a default object, not a "real" service object.  In
        // that case, the locale metadata (valid & actual) is setup
        // correctly already, and we don't want to overwrite it. (TODO
        // remove in 3.0) [aliu]
        if (*actualLoc.getName() != 0) {
            result->setLocales(desiredLocale, actualLoc, actualLoc);
        }
        return result;
    }
#endif
    return makeInstance(desiredLocale, status);
}
Ejemplo n.º 2
0
 virtual UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const {
     UnicodeString ar;
     if (actualReturn == NULL) {
         actualReturn = &ar;
     }
     Collator* result = (Collator*)ICULocaleService::getKey(key, actualReturn, status);
     // Ugly Hack Alert! If the actualReturn length is zero, this
     // means we got a default object, not a "real" service-created
     // object.  We don't call setLocales() on a default object,
     // because that will overwrite its correct built-in locale
     // metadata (valid & actual) with our incorrect data (all we
     // have is the requested locale). (TODO remove in 3.0) [aliu]
     if (result && actualReturn->length() > 0) {
         const LocaleKey& lkey = (const LocaleKey&)key;
         Locale canonicalLocale("");
         Locale currentLocale("");
         
         LocaleUtility::initLocaleFromName(*actualReturn, currentLocale);
         result->setLocales(lkey.canonicalLocale(canonicalLocale), currentLocale, currentLocale);
     }
     return result;
 }