intl/icu/source/common/servslkf.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/servslkf.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,122 @@
     1.4 +/**
     1.5 + *******************************************************************************
     1.6 + * Copyright (C) 2001-2005, International Business Machines Corporation and    *
     1.7 + * others. All Rights Reserved.                                                *
     1.8 + *******************************************************************************
     1.9 + *
    1.10 + *******************************************************************************
    1.11 + */
    1.12 +#include "unicode/utypes.h"
    1.13 +
    1.14 +#if !UCONFIG_NO_SERVICE
    1.15 +
    1.16 +#include "unicode/resbund.h"
    1.17 +#include "uresimp.h"
    1.18 +#include "cmemory.h"
    1.19 +#include "servloc.h"
    1.20 +#include "ustrfmt.h"
    1.21 +#include "uhash.h"
    1.22 +#include "charstr.h"
    1.23 +#include "ucln_cmn.h"
    1.24 +#include "uassert.h"
    1.25 +
    1.26 +#define UNDERSCORE_CHAR ((UChar)0x005f)
    1.27 +#define AT_SIGN_CHAR    ((UChar)64)
    1.28 +#define PERIOD_CHAR     ((UChar)46)
    1.29 +
    1.30 +U_NAMESPACE_BEGIN
    1.31 +
    1.32 +/*
    1.33 + ******************************************************************
    1.34 + */
    1.35 +
    1.36 +SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
    1.37 +                                               const UnicodeString& locale,
    1.38 +                                               int32_t kind,
    1.39 +                                               int32_t coverage)
    1.40 +  : LocaleKeyFactory(coverage)
    1.41 +  , _obj(objToAdopt)
    1.42 +  , _id(locale)
    1.43 +  , _kind(kind)
    1.44 +{
    1.45 +}
    1.46 +
    1.47 +SimpleLocaleKeyFactory::SimpleLocaleKeyFactory(UObject* objToAdopt,
    1.48 +                                               const Locale& locale,
    1.49 +                                               int32_t kind,
    1.50 +                                               int32_t coverage)
    1.51 +  : LocaleKeyFactory(coverage)
    1.52 +  , _obj(objToAdopt)
    1.53 +  , _id()
    1.54 +  , _kind(kind)
    1.55 +{
    1.56 +    LocaleUtility::initNameFromLocale(locale, _id);
    1.57 +}
    1.58 +
    1.59 +SimpleLocaleKeyFactory::~SimpleLocaleKeyFactory()
    1.60 +{
    1.61 +  delete _obj;
    1.62 +  _obj = NULL;
    1.63 +}
    1.64 +
    1.65 +UObject*
    1.66 +SimpleLocaleKeyFactory::create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
    1.67 +{
    1.68 +    if (U_SUCCESS(status)) {
    1.69 +        const LocaleKey& lkey = (const LocaleKey&)key;
    1.70 +        if (_kind == LocaleKey::KIND_ANY || _kind == lkey.kind()) {
    1.71 +            UnicodeString keyID;
    1.72 +            lkey.currentID(keyID);
    1.73 +            if (_id == keyID) {
    1.74 +                return service->cloneInstance(_obj);
    1.75 +            }
    1.76 +        }
    1.77 +    }
    1.78 +    return NULL;
    1.79 +}
    1.80 +
    1.81 +//UBool
    1.82 +//SimpleLocaleKeyFactory::isSupportedID(const UnicodeString& id, UErrorCode& /* status */) const
    1.83 +//{
    1.84 +//    return id == _id;
    1.85 +//}
    1.86 +
    1.87 +void
    1.88 +SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
    1.89 +{
    1.90 +    if (U_SUCCESS(status)) {
    1.91 +        if (_coverage & 0x1) {
    1.92 +            result.remove(_id);
    1.93 +        } else {
    1.94 +            result.put(_id, (void*)this, status);
    1.95 +        }
    1.96 +    }
    1.97 +}
    1.98 +
    1.99 +#ifdef SERVICE_DEBUG
   1.100 +UnicodeString&
   1.101 +SimpleLocaleKeyFactory::debug(UnicodeString& result) const
   1.102 +{
   1.103 +    LocaleKeyFactory::debug(result);
   1.104 +    result.append(", id: ");
   1.105 +    result.append(_id);
   1.106 +    result.append(", kind: ");
   1.107 +    result.append(_kind);
   1.108 +    return result;
   1.109 +}
   1.110 +
   1.111 +UnicodeString&
   1.112 +SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const
   1.113 +{
   1.114 +    return result.append("SimpleLocaleKeyFactory");
   1.115 +}
   1.116 +#endif
   1.117 +
   1.118 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleLocaleKeyFactory)
   1.119 +
   1.120 +U_NAMESPACE_END
   1.121 +
   1.122 +/* !UCONFIG_NO_SERVICE */
   1.123 +#endif
   1.124 +
   1.125 +

mercurial