servrbf.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /**
  4. *******************************************************************************
  5. * Copyright (C) 2001-2014, International Business Machines Corporation and *
  6. * others. All Rights Reserved. *
  7. *******************************************************************************
  8. *
  9. *******************************************************************************
  10. */
  11. #include "unicode/utypes.h"
  12. #if !UCONFIG_NO_SERVICE
  13. #include "unicode/resbund.h"
  14. #include "uresimp.h"
  15. #include "cmemory.h"
  16. #include "servloc.h"
  17. #include "ustrfmt.h"
  18. #include "uhash.h"
  19. #include "charstr.h"
  20. #include "ucln_cmn.h"
  21. #include "uassert.h"
  22. #define UNDERSCORE_CHAR ((char16_t)0x005f)
  23. #define AT_SIGN_CHAR ((char16_t)64)
  24. #define PERIOD_CHAR ((char16_t)46)
  25. U_NAMESPACE_BEGIN
  26. ICUResourceBundleFactory::ICUResourceBundleFactory()
  27. : LocaleKeyFactory(VISIBLE)
  28. , _bundleName()
  29. {
  30. }
  31. ICUResourceBundleFactory::ICUResourceBundleFactory(const UnicodeString& bundleName)
  32. : LocaleKeyFactory(VISIBLE)
  33. , _bundleName(bundleName)
  34. {
  35. }
  36. ICUResourceBundleFactory::~ICUResourceBundleFactory() {}
  37. const Hashtable*
  38. ICUResourceBundleFactory::getSupportedIDs(UErrorCode& status) const
  39. {
  40. if (U_SUCCESS(status)) {
  41. return LocaleUtility::getAvailableLocaleNames(_bundleName);
  42. }
  43. return nullptr;
  44. }
  45. UObject*
  46. ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, const ICUService* /* service */, UErrorCode& status) const
  47. {
  48. if (U_SUCCESS(status)) {
  49. // _bundleName is a package name
  50. // and should only contain invariant characters
  51. // ??? is it always true that the max length of the bundle name is 19?
  52. // who made this change? -- dlf
  53. char pkg[20];
  54. int32_t length;
  55. length = _bundleName.extract(0, INT32_MAX, pkg, static_cast<int32_t>(sizeof(pkg)), US_INV);
  56. if (length >= static_cast<int32_t>(sizeof(pkg))) {
  57. return nullptr;
  58. }
  59. return new ResourceBundle(pkg, loc, status);
  60. }
  61. return nullptr;
  62. }
  63. #ifdef SERVICE_DEBUG
  64. UnicodeString&
  65. ICUResourceBundleFactory::debug(UnicodeString& result) const
  66. {
  67. LocaleKeyFactory::debug(result);
  68. result.append((UnicodeString)", bundle: ");
  69. return result.append(_bundleName);
  70. }
  71. UnicodeString&
  72. ICUResourceBundleFactory::debugClass(UnicodeString& result) const
  73. {
  74. return result.append((UnicodeString)"ICUResourceBundleFactory");
  75. }
  76. #endif
  77. UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ICUResourceBundleFactory)
  78. U_NAMESPACE_END
  79. /* !UCONFIG_NO_SERVICE */
  80. #endif