servslkf.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "uassert.h"
  21. #define UNDERSCORE_CHAR ((char16_t)0x005f)
  22. #define AT_SIGN_CHAR ((char16_t)64)
  23. #define PERIOD_CHAR ((char16_t)46)
  24. U_NAMESPACE_BEGIN
  25. /*
  26. ******************************************************************
  27. */
  28. SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
  29. const UnicodeString& locale,
  30. int32_t kind,
  31. int32_t coverage)
  32. : LocaleKeyFactory(coverage)
  33. , _obj(objToAdopt)
  34. , _id(locale)
  35. , _kind(kind)
  36. {
  37. }
  38. SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
  39. const Locale& locale,
  40. int32_t kind,
  41. int32_t coverage)
  42. : LocaleKeyFactory(coverage)
  43. , _obj(objToAdopt)
  44. , _id()
  45. , _kind(kind)
  46. {
  47. LocaleUtility::initNameFromLocale(locale, _id);
  48. }
  49. SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory()
  50. {
  51. delete _obj;
  52. _obj = nullptr;
  53. }
  54. UObject*
  55. SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
  56. {
  57. if (U_SUCCESS(status)) {
  58. const LocaleKey& lkey = static_cast<const LocaleKey&>(key);
  59. if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) {
  60. UnicodeString keyID;
  61. lkey.currentID(keyID);
  62. if (_id == keyID) {
  63. return service->cloneInstance(_obj);
  64. }
  65. }
  66. }
  67. return nullptr;
  68. }
  69. //UBool
  70. //SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const
  71. //{
  72. // return id == _id;
  73. //}
  74. void
  75. SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
  76. {
  77. if (U_SUCCESS(status)) {
  78. if (_coverage & 0x1) {
  79. result.remove(_id);
  80. } else {
  81. result.put(_id, (void*)this, status);
  82. }
  83. }
  84. }
  85. #ifdef SERVICE_DEBUG
  86. UnicodeString&
  87. SimpleLocaleKeyFactory::debug(UnicodeString& result) const
  88. {
  89. LocaleKeyFactory::debug(result);
  90. result.append((UnicodeString)", id: ");
  91. result.append(_id);
  92. result.append((UnicodeString)", kind: ");
  93. result.append(_kind);
  94. return result;
  95. }
  96. UnicodeString&
  97. SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const
  98. {
  99. return result.append((UnicodeString)"SimpleLocaleKeyFactory");
  100. }
  101. #endif
  102. UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleLocaleKeyFactory)
  103. U_NAMESPACE_END
  104. /* !UCONFIG_NO_SERVICE */
  105. #endif