11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 31cb0ef41Sopenharmony_ci/** 41cb0ef41Sopenharmony_ci ******************************************************************************* 51cb0ef41Sopenharmony_ci * Copyright (C) 2001-2014, International Business Machines Corporation and * 61cb0ef41Sopenharmony_ci * others. All Rights Reserved. * 71cb0ef41Sopenharmony_ci ******************************************************************************* 81cb0ef41Sopenharmony_ci * 91cb0ef41Sopenharmony_ci ******************************************************************************* 101cb0ef41Sopenharmony_ci */ 111cb0ef41Sopenharmony_ci#include "unicode/utypes.h" 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci#if !UCONFIG_NO_SERVICE 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci#include "unicode/resbund.h" 161cb0ef41Sopenharmony_ci#include "uresimp.h" 171cb0ef41Sopenharmony_ci#include "cmemory.h" 181cb0ef41Sopenharmony_ci#include "servloc.h" 191cb0ef41Sopenharmony_ci#include "ustrfmt.h" 201cb0ef41Sopenharmony_ci#include "uhash.h" 211cb0ef41Sopenharmony_ci#include "charstr.h" 221cb0ef41Sopenharmony_ci#include "ucln_cmn.h" 231cb0ef41Sopenharmony_ci#include "uassert.h" 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci#define UNDERSCORE_CHAR ((char16_t)0x005f) 261cb0ef41Sopenharmony_ci#define AT_SIGN_CHAR ((char16_t)64) 271cb0ef41Sopenharmony_ci#define PERIOD_CHAR ((char16_t)46) 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciU_NAMESPACE_BEGIN 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciICUResourceBundleFactory::ICUResourceBundleFactory() 321cb0ef41Sopenharmony_ci : LocaleKeyFactory(VISIBLE) 331cb0ef41Sopenharmony_ci , _bundleName() 341cb0ef41Sopenharmony_ci{ 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciICUResourceBundleFactory::ICUResourceBundleFactory(const UnicodeString& bundleName) 381cb0ef41Sopenharmony_ci : LocaleKeyFactory(VISIBLE) 391cb0ef41Sopenharmony_ci , _bundleName(bundleName) 401cb0ef41Sopenharmony_ci{ 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciICUResourceBundleFactory::~ICUResourceBundleFactory() {} 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ciconst Hashtable* 461cb0ef41Sopenharmony_ciICUResourceBundleFactory::getSupportedIDs(UErrorCode& status) const 471cb0ef41Sopenharmony_ci{ 481cb0ef41Sopenharmony_ci if (U_SUCCESS(status)) { 491cb0ef41Sopenharmony_ci return LocaleUtility::getAvailableLocaleNames(_bundleName); 501cb0ef41Sopenharmony_ci } 511cb0ef41Sopenharmony_ci return nullptr; 521cb0ef41Sopenharmony_ci} 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ciUObject* 551cb0ef41Sopenharmony_ciICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, const ICUService* /* service */, UErrorCode& status) const 561cb0ef41Sopenharmony_ci{ 571cb0ef41Sopenharmony_ci if (U_SUCCESS(status)) { 581cb0ef41Sopenharmony_ci // _bundleName is a package name 591cb0ef41Sopenharmony_ci // and should only contain invariant characters 601cb0ef41Sopenharmony_ci // ??? is it always true that the max length of the bundle name is 19? 611cb0ef41Sopenharmony_ci // who made this change? -- dlf 621cb0ef41Sopenharmony_ci char pkg[20]; 631cb0ef41Sopenharmony_ci int32_t length; 641cb0ef41Sopenharmony_ci length=_bundleName.extract(0, INT32_MAX, pkg, (int32_t)sizeof(pkg), US_INV); 651cb0ef41Sopenharmony_ci if(length>=(int32_t)sizeof(pkg)) { 661cb0ef41Sopenharmony_ci return nullptr; 671cb0ef41Sopenharmony_ci } 681cb0ef41Sopenharmony_ci return new ResourceBundle(pkg, loc, status); 691cb0ef41Sopenharmony_ci } 701cb0ef41Sopenharmony_ci return nullptr; 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci#ifdef SERVICE_DEBUG 741cb0ef41Sopenharmony_ciUnicodeString& 751cb0ef41Sopenharmony_ciICUResourceBundleFactory::debug(UnicodeString& result) const 761cb0ef41Sopenharmony_ci{ 771cb0ef41Sopenharmony_ci LocaleKeyFactory::debug(result); 781cb0ef41Sopenharmony_ci result.append((UnicodeString)", bundle: "); 791cb0ef41Sopenharmony_ci return result.append(_bundleName); 801cb0ef41Sopenharmony_ci} 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ciUnicodeString& 831cb0ef41Sopenharmony_ciICUResourceBundleFactory::debugClass(UnicodeString& result) const 841cb0ef41Sopenharmony_ci{ 851cb0ef41Sopenharmony_ci return result.append((UnicodeString)"ICUResourceBundleFactory"); 861cb0ef41Sopenharmony_ci} 871cb0ef41Sopenharmony_ci#endif 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ciUOBJECT_DEFINE_RTTI_IMPLEMENTATION(ICUResourceBundleFactory) 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ciU_NAMESPACE_END 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_ci/* !UCONFIG_NO_SERVICE */ 941cb0ef41Sopenharmony_ci#endif 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci 97