BreakIterator* BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& status) { if (U_FAILURE(status)) { return NULL; } #if !UCONFIG_NO_SERVICE if (hasService()) { Locale actualLoc(""); BreakIterator *result = (BreakIterator*)gService->get(loc, kind, &actualLoc, status); // TODO: The way the service code works in ICU 2.8 is that if // there is a real registered break iterator, the actualLoc // will be populated, but if the handleDefault path is taken // (because nothing is registered that can handle the // requested locale) then the actualLoc comes back empty. In // that case, the returned object already has its actual/valid // locale data populated (by makeInstance, which is what // handleDefault calls), so we don't touch it. YES, A COMMENT // THIS LONG is a sign of bad code -- so the action item is to // revisit this in ICU 3.0 and clean it up/fix it/remove it. if (U_SUCCESS(status) && (result != NULL) && *actualLoc.getName() != 0) { U_LOCALE_BASED(locBased, *result); locBased.setLocaleIDs(actualLoc.getName(), actualLoc.getName()); } return result; } else #endif { return makeInstance(loc, kind, status); } }
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale, UErrorCode& status) { if (U_FAILURE(status)) return 0; if (desiredLocale.isBogus()) { // Locale constructed from malformed locale ID or language tag. status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } 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 NULL with U_FAILURE(status), or non-NULL with U_SUCCESS(status) } // The use of *coll in setAttributesFromKeywords can cause the NULL 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 NULL; } setAttributesFromKeywords(desiredLocale, *coll, status); if (U_FAILURE(status)) { delete coll; return NULL; } return coll; }
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); }
Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale, UErrorCode& status) { if (U_FAILURE(status)) return 0; if (desiredLocale.isBogus()) { // Locale constructed from malformed locale ID or language tag. status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } Collator* coll; #if !UCONFIG_NO_SERVICE if (hasService()) { Locale actualLoc; coll = (Collator*)gService->get(desiredLocale, &actualLoc, status); } else #endif { coll = makeInstance(desiredLocale, status); } setAttributesFromKeywords(desiredLocale, *coll, status); if (U_FAILURE(status)) { delete coll; return NULL; } return coll; }
UCollator* Collator::createUCollator(const char *loc, UErrorCode *status) { UCollator *result = 0; if (status && U_SUCCESS(*status) && hasService()) { Locale desiredLocale(loc); Collator *col = (Collator*)gService->get(desiredLocale, *status); RuleBasedCollator *rbc; if (col && (rbc = dynamic_cast<RuleBasedCollator *>(col))) { if (!rbc->dataIsOwned) { result = ucol_safeClone(rbc->ucollator, NULL, NULL, status); } else { result = rbc->ucollator; rbc->ucollator = NULL; // to prevent free on delete } } else { // should go in a function- ucol_initDelegate(delegate) result = (UCollator *)uprv_malloc(sizeof(UCollator)); if(result == NULL) { *status = U_MEMORY_ALLOCATION_ERROR; } else { uprv_memset(result, 0, sizeof(UCollator)); result->delegate = col; result->freeOnClose = TRUE; // do free on close. col = NULL; // to prevent free on delete. } } delete col; } return result; }
UnicodeString& Collator::getDisplayName(const Locale& objectLocale, const Locale& displayLocale, UnicodeString& name) { if (hasService()) { return gService->getDisplayName(objectLocale.getName(), name, displayLocale); } return objectLocale.getDisplayName(displayLocale, name); }
UBool U_EXPORT2 BreakIterator::unregister(URegistryKey key, UErrorCode& status) { if (U_SUCCESS(status)) { if (hasService()) { return gService->unregister(key, status); } status = U_MEMORY_ALLOCATION_ERROR; } return FALSE; }
UBool U_EXPORT2 Collator::unregister(URegistryKey key, UErrorCode& status) { if (U_SUCCESS(status)) { if (hasService()) { return gService->unregister(key, status); } status = U_ILLEGAL_ARGUMENT_ERROR; } return FALSE; }
UnicodeString& U_EXPORT2 Collator::getDisplayName(const Locale& objectLocale, const Locale& displayLocale, UnicodeString& name) { #if !UCONFIG_NO_SERVICE if (hasService()) { UnicodeString locNameStr; LocaleUtility::initNameFromLocale(objectLocale, locNameStr); return gService->getDisplayName(locNameStr, name, displayLocale); } #endif return objectLocale.getDisplayName(displayLocale, name); }
StringEnumeration* U_EXPORT2 Collator::getAvailableLocales(void) { #if !UCONFIG_NO_SERVICE if (hasService()) { return getService()->getAvailableLocales(); } #endif /* UCONFIG_NO_SERVICE */ UErrorCode status = U_ZERO_ERROR; if (isAvailableLocaleListInitialized(status)) { return new CollationLocaleListEnumeration(); } return NULL; }
int hasProtocol(HostAttributeEntry *host_entry, int ipprotocol, int protocol, int application) { int ret = SFTARGET_NOMATCH; ret = hasService(host_entry, ipprotocol, protocol, application); if (ret == SFTARGET_MATCH) return ret; ret = hasClient(host_entry, ipprotocol, protocol, application); if (ret == SFTARGET_MATCH) return ret; return ret; }
void ServiceManager::registerService(ServiceID const& serviceId, ServiceFactoryPtr factory, bool createOnDemand) { if(!factory) throw std::invalid_argument("\"factory\" cannot be NULL"); if(hasService(serviceId)) throw std::invalid_argument("A service with this \"serviceId\" already exists"); Mutex::scoped_lock lock(m_mutex); ServicePtr service = 0; if(!createOnDemand) service = factory->createInstance(); ServicePair serviceInfo = std::make_pair(factory, service); m_services.insert(std::make_pair(serviceId, serviceInfo)); }
ServiceManager::ServicePtr ServiceManager::queryForService(ServiceID const& serviceId) { ServicePtr ret = 0; if(hasService(serviceId)) { Mutex::scoped_lock lock(m_mutex); ServicePair &serv = m_services[serviceId]; if(!serv.second) { // Should we check if the creation succeeded??? serv.second = (serv.first)->createInstance(); } ret = serv.second; } return ret; }
UCollator* Collator::createUCollator(const char *loc, UErrorCode *status) { UCollator *result = 0; if (status && U_SUCCESS(*status) && hasService()) { Locale desiredLocale(loc); Collator *col = (Collator*)gService->get(desiredLocale, *status); if (col && col->getDynamicClassID() == RuleBasedCollator::getStaticClassID()) { RuleBasedCollator *rbc = (RuleBasedCollator *)col; if (!rbc->dataIsOwned) { result = ucol_safeClone(rbc->ucollator, NULL, NULL, status); } else { result = rbc->ucollator; rbc->ucollator = NULL; // to prevent free on delete } } delete col; } return result; }
bool GlobalService::require(const std::string servicename) { return hasService(servicename) || plugin::PluginLoader::Instance()->loadService(servicename, 0); // load globally. }
bool ServiceRegistry::hasUnresolvedService(std::string matchtag){ return hasService(matchtag, &unresolved); }
bool ServiceRegistry::hasService(std::string matchtag){ return hasService(matchtag, &services); }