Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (c) 2004, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | * Author: Alan Liu |
michael@0 | 7 | * Created: January 16 2004 |
michael@0 | 8 | * Since: ICU 2.8 |
michael@0 | 9 | ********************************************************************** |
michael@0 | 10 | */ |
michael@0 | 11 | #ifndef LOCBASED_H |
michael@0 | 12 | #define LOCBASED_H |
michael@0 | 13 | |
michael@0 | 14 | #include "unicode/locid.h" |
michael@0 | 15 | #include "unicode/uobject.h" |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * Macro to declare a locale LocaleBased wrapper object for the given |
michael@0 | 19 | * object, which must have two members named `validLocale' and |
michael@0 | 20 | * `actualLocale'. |
michael@0 | 21 | */ |
michael@0 | 22 | #define U_LOCALE_BASED(varname, objname) \ |
michael@0 | 23 | LocaleBased varname((objname).validLocale, (objname).actualLocale); |
michael@0 | 24 | |
michael@0 | 25 | U_NAMESPACE_BEGIN |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * A utility class that unifies the implementation of getLocale() by |
michael@0 | 29 | * various ICU services. This class is likely to be removed in the |
michael@0 | 30 | * ICU 3.0 time frame in favor of an integrated approach with the |
michael@0 | 31 | * services framework. |
michael@0 | 32 | * @since ICU 2.8 |
michael@0 | 33 | */ |
michael@0 | 34 | class U_COMMON_API LocaleBased : public UMemory { |
michael@0 | 35 | |
michael@0 | 36 | public: |
michael@0 | 37 | |
michael@0 | 38 | /** |
michael@0 | 39 | * Construct a LocaleBased wrapper around the two pointers. These |
michael@0 | 40 | * will be aliased for the lifetime of this object. |
michael@0 | 41 | */ |
michael@0 | 42 | inline LocaleBased(char* validAlias, char* actualAlias); |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Construct a LocaleBased wrapper around the two const pointers. |
michael@0 | 46 | * These will be aliased for the lifetime of this object. |
michael@0 | 47 | */ |
michael@0 | 48 | inline LocaleBased(const char* validAlias, const char* actualAlias); |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Return locale meta-data for the service object wrapped by this |
michael@0 | 52 | * object. Either the valid or the actual locale may be |
michael@0 | 53 | * retrieved. |
michael@0 | 54 | * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE |
michael@0 | 55 | * @param status input-output error code |
michael@0 | 56 | * @return the indicated locale |
michael@0 | 57 | */ |
michael@0 | 58 | Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; |
michael@0 | 59 | |
michael@0 | 60 | /** |
michael@0 | 61 | * Return the locale ID for the service object wrapped by this |
michael@0 | 62 | * object. Either the valid or the actual locale may be |
michael@0 | 63 | * retrieved. |
michael@0 | 64 | * @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE |
michael@0 | 65 | * @param status input-output error code |
michael@0 | 66 | * @return the indicated locale ID |
michael@0 | 67 | */ |
michael@0 | 68 | const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const; |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Set the locale meta-data for the service object wrapped by this |
michael@0 | 72 | * object. If either parameter is zero, it is ignored. |
michael@0 | 73 | * @param valid the ID of the valid locale |
michael@0 | 74 | * @param actual the ID of the actual locale |
michael@0 | 75 | */ |
michael@0 | 76 | void setLocaleIDs(const char* valid, const char* actual); |
michael@0 | 77 | |
michael@0 | 78 | private: |
michael@0 | 79 | |
michael@0 | 80 | char* valid; |
michael@0 | 81 | |
michael@0 | 82 | char* actual; |
michael@0 | 83 | }; |
michael@0 | 84 | |
michael@0 | 85 | inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) : |
michael@0 | 86 | valid(validAlias), actual(actualAlias) { |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | inline LocaleBased::LocaleBased(const char* validAlias, |
michael@0 | 90 | const char* actualAlias) : |
michael@0 | 91 | // ugh: cast away const |
michael@0 | 92 | valid((char*)validAlias), actual((char*)actualAlias) { |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | U_NAMESPACE_END |
michael@0 | 96 | |
michael@0 | 97 | #endif |