intl/icu/source/common/servslkf.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /**
     2  *******************************************************************************
     3  * Copyright (C) 2001-2005, International Business Machines Corporation and    *
     4  * others. All Rights Reserved.                                                *
     5  *******************************************************************************
     6  *
     7  *******************************************************************************
     8  */
     9 #include "unicode/utypes.h"
    11 #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"
    23 #define UNDERSCORE_CHAR ((UChar)0x005f)
    24 #define AT_SIGN_CHAR    ((UChar)64)
    25 #define PERIOD_CHAR     ((UChar)46)
    27 U_NAMESPACE_BEGIN
    29 /*
    30  ******************************************************************
    31  */
    33 SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
    34                                                const UnicodeString& locale,
    35                                                int32_t kind,
    36                                                int32_t coverage)
    37   : LocaleKeyFactory(coverage)
    38   , _obj(objToAdopt)
    39   , _id(locale)
    40   , _kind(kind)
    41 {
    42 }
    44 SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
    45                                                const Locale& locale,
    46                                                int32_t kind,
    47                                                int32_t coverage)
    48   : LocaleKeyFactory(coverage)
    49   , _obj(objToAdopt)
    50   , _id()
    51   , _kind(kind)
    52 {
    53     LocaleUtility::initNameFromLocale(locale, _id);
    54 }
    56 SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory()
    57 {
    58   delete _obj;
    59   _obj = NULL;
    60 }
    62 UObject*
    63 SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
    64 {
    65     if (U_SUCCESS(status)) {
    66         const LocaleKey& lkey = (const LocaleKey&)key;
    67         if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) {
    68             UnicodeString keyID;
    69             lkey.currentID(keyID);
    70             if (_id == keyID) {
    71                 return service->cloneInstance(_obj);
    72             }
    73         }
    74     }
    75     return NULL;
    76 }
    78 //UBool
    79 //SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const
    80 //{
    81 //    return id == _id;
    82 //}
    84 void
    85 SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
    86 {
    87     if (U_SUCCESS(status)) {
    88         if (_coverage & 0x1) {
    89             result.remove(_id);
    90         } else {
    91             result.put(_id, (void*)this, status);
    92         }
    93     }
    94 }
    96 #ifdef SERVICE_DEBUG
    97 UnicodeString&
    98 SimpleLocaleKeyFactory::debug(UnicodeString& result) const
    99 {
   100     LocaleKeyFactory::debug(result);
   101     result.append(", id: ");
   102     result.append(_id);
   103     result.append(", kind: ");
   104     result.append(_kind);
   105     return result;
   106 }
   108 UnicodeString&
   109 SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const
   110 {
   111     return result.append("SimpleLocaleKeyFactory");
   112 }
   113 #endif
   115 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleLocaleKeyFactory)
   117 U_NAMESPACE_END
   119 /* !UCONFIG_NO_SERVICE */
   120 #endif

mercurial