jpayne@69
|
1 // © 2016 and later: Unicode, Inc. and others.
|
jpayne@69
|
2 // License & terms of use: http://www.unicode.org/copyright.html
|
jpayne@69
|
3 /*
|
jpayne@69
|
4 ******************************************************************************
|
jpayne@69
|
5 *
|
jpayne@69
|
6 * Copyright (C) 1996-2015, International Business Machines
|
jpayne@69
|
7 * Corporation and others. All Rights Reserved.
|
jpayne@69
|
8 *
|
jpayne@69
|
9 ******************************************************************************
|
jpayne@69
|
10 *
|
jpayne@69
|
11 * File locid.h
|
jpayne@69
|
12 *
|
jpayne@69
|
13 * Created by: Helena Shih
|
jpayne@69
|
14 *
|
jpayne@69
|
15 * Modification History:
|
jpayne@69
|
16 *
|
jpayne@69
|
17 * Date Name Description
|
jpayne@69
|
18 * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
|
jpayne@69
|
19 * get and set it.
|
jpayne@69
|
20 * 04/02/97 aliu Made operator!= inline; fixed return value of getName().
|
jpayne@69
|
21 * 04/15/97 aliu Cleanup for AIX/Win32.
|
jpayne@69
|
22 * 04/24/97 aliu Numerous changes per code review.
|
jpayne@69
|
23 * 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
|
jpayne@69
|
24 * 09/08/98 stephen Moved definition of kEmptyString for Mac Port
|
jpayne@69
|
25 * 11/09/99 weiv Added const char * getName() const;
|
jpayne@69
|
26 * 04/12/00 srl removing unicodestring api's and cached hash code
|
jpayne@69
|
27 * 08/10/01 grhoten Change the static Locales to accessor functions
|
jpayne@69
|
28 ******************************************************************************
|
jpayne@69
|
29 */
|
jpayne@69
|
30
|
jpayne@69
|
31 #ifndef LOCID_H
|
jpayne@69
|
32 #define LOCID_H
|
jpayne@69
|
33
|
jpayne@69
|
34 #include "unicode/utypes.h"
|
jpayne@69
|
35
|
jpayne@69
|
36 #if U_SHOW_CPLUSPLUS_API
|
jpayne@69
|
37
|
jpayne@69
|
38 #include "unicode/bytestream.h"
|
jpayne@69
|
39 #include "unicode/localpointer.h"
|
jpayne@69
|
40 #include "unicode/strenum.h"
|
jpayne@69
|
41 #include "unicode/stringpiece.h"
|
jpayne@69
|
42 #include "unicode/uobject.h"
|
jpayne@69
|
43 #include "unicode/putil.h"
|
jpayne@69
|
44 #include "unicode/uloc.h"
|
jpayne@69
|
45
|
jpayne@69
|
46 /**
|
jpayne@69
|
47 * \file
|
jpayne@69
|
48 * \brief C++ API: Locale ID object.
|
jpayne@69
|
49 */
|
jpayne@69
|
50
|
jpayne@69
|
51 U_NAMESPACE_BEGIN
|
jpayne@69
|
52
|
jpayne@69
|
53 // Forward Declarations
|
jpayne@69
|
54 void U_CALLCONV locale_available_init(); /**< @internal */
|
jpayne@69
|
55
|
jpayne@69
|
56 class StringEnumeration;
|
jpayne@69
|
57 class UnicodeString;
|
jpayne@69
|
58
|
jpayne@69
|
59 /**
|
jpayne@69
|
60 * A <code>Locale</code> object represents a specific geographical, political,
|
jpayne@69
|
61 * or cultural region. An operation that requires a <code>Locale</code> to perform
|
jpayne@69
|
62 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
|
jpayne@69
|
63 * to tailor information for the user. For example, displaying a number
|
jpayne@69
|
64 * is a locale-sensitive operation--the number should be formatted
|
jpayne@69
|
65 * according to the customs/conventions of the user's native country,
|
jpayne@69
|
66 * region, or culture.
|
jpayne@69
|
67 *
|
jpayne@69
|
68 * The Locale class is not suitable for subclassing.
|
jpayne@69
|
69 *
|
jpayne@69
|
70 * <P>
|
jpayne@69
|
71 * You can create a <code>Locale</code> object using the constructor in
|
jpayne@69
|
72 * this class:
|
jpayne@69
|
73 * \htmlonly<blockquote>\endhtmlonly
|
jpayne@69
|
74 * <pre>
|
jpayne@69
|
75 * Locale( const char* language,
|
jpayne@69
|
76 * const char* country,
|
jpayne@69
|
77 * const char* variant);
|
jpayne@69
|
78 * </pre>
|
jpayne@69
|
79 * \htmlonly</blockquote>\endhtmlonly
|
jpayne@69
|
80 * The first argument to the constructors is a valid <STRONG>ISO
|
jpayne@69
|
81 * Language Code.</STRONG> These codes are the lower-case two-letter
|
jpayne@69
|
82 * codes as defined by ISO-639.
|
jpayne@69
|
83 * You can find a full list of these codes at:
|
jpayne@69
|
84 * <BR><a href ="http://www.loc.gov/standards/iso639-2/">
|
jpayne@69
|
85 * http://www.loc.gov/standards/iso639-2/</a>
|
jpayne@69
|
86 *
|
jpayne@69
|
87 * <P>
|
jpayne@69
|
88 * The second argument to the constructors is a valid <STRONG>ISO Country
|
jpayne@69
|
89 * Code.</STRONG> These codes are the upper-case two-letter codes
|
jpayne@69
|
90 * as defined by ISO-3166.
|
jpayne@69
|
91 * You can find a full list of these codes at a number of sites, such as:
|
jpayne@69
|
92 * <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html">
|
jpayne@69
|
93 * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a>
|
jpayne@69
|
94 *
|
jpayne@69
|
95 * <P>
|
jpayne@69
|
96 * The third constructor requires a third argument--the <STRONG>Variant.</STRONG>
|
jpayne@69
|
97 * The Variant codes are vendor and browser-specific.
|
jpayne@69
|
98 * For example, use REVISED for a language's revised script orthography, and POSIX for POSIX.
|
jpayne@69
|
99 * Where there are two variants, separate them with an underscore, and
|
jpayne@69
|
100 * put the most important one first. For
|
jpayne@69
|
101 * example, a Traditional Spanish collation might be referenced, with
|
jpayne@69
|
102 * "ES", "ES", "Traditional_POSIX".
|
jpayne@69
|
103 *
|
jpayne@69
|
104 * <P>
|
jpayne@69
|
105 * Because a <code>Locale</code> object is just an identifier for a region,
|
jpayne@69
|
106 * no validity check is performed when you construct a <code>Locale</code>.
|
jpayne@69
|
107 * If you want to see whether particular resources are available for the
|
jpayne@69
|
108 * <code>Locale</code> you construct, you must query those resources. For
|
jpayne@69
|
109 * example, ask the <code>NumberFormat</code> for the locales it supports
|
jpayne@69
|
110 * using its <code>getAvailableLocales</code> method.
|
jpayne@69
|
111 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
|
jpayne@69
|
112 * locale, you get back the best available match, not necessarily
|
jpayne@69
|
113 * precisely what you asked for. For more information, look at
|
jpayne@69
|
114 * <code>ResourceBundle</code>.
|
jpayne@69
|
115 *
|
jpayne@69
|
116 * <P>
|
jpayne@69
|
117 * The <code>Locale</code> class provides a number of convenient constants
|
jpayne@69
|
118 * that you can use to create <code>Locale</code> objects for commonly used
|
jpayne@69
|
119 * locales. For example, the following refers to a <code>Locale</code> object
|
jpayne@69
|
120 * for the United States:
|
jpayne@69
|
121 * \htmlonly<blockquote>\endhtmlonly
|
jpayne@69
|
122 * <pre>
|
jpayne@69
|
123 * Locale::getUS()
|
jpayne@69
|
124 * </pre>
|
jpayne@69
|
125 * \htmlonly</blockquote>\endhtmlonly
|
jpayne@69
|
126 *
|
jpayne@69
|
127 * <P>
|
jpayne@69
|
128 * Once you've created a <code>Locale</code> you can query it for information about
|
jpayne@69
|
129 * itself. Use <code>getCountry</code> to get the ISO Country Code and
|
jpayne@69
|
130 * <code>getLanguage</code> to get the ISO Language Code. You can
|
jpayne@69
|
131 * use <code>getDisplayCountry</code> to get the
|
jpayne@69
|
132 * name of the country suitable for displaying to the user. Similarly,
|
jpayne@69
|
133 * you can use <code>getDisplayLanguage</code> to get the name of
|
jpayne@69
|
134 * the language suitable for displaying to the user. Interestingly,
|
jpayne@69
|
135 * the <code>getDisplayXXX</code> methods are themselves locale-sensitive
|
jpayne@69
|
136 * and have two versions: one that uses the default locale and one
|
jpayne@69
|
137 * that takes a locale as an argument and displays the name or country in
|
jpayne@69
|
138 * a language appropriate to that locale.
|
jpayne@69
|
139 *
|
jpayne@69
|
140 * <P>
|
jpayne@69
|
141 * ICU provides a number of classes that perform locale-sensitive
|
jpayne@69
|
142 * operations. For example, the <code>NumberFormat</code> class formats
|
jpayne@69
|
143 * numbers, currency, or percentages in a locale-sensitive manner. Classes
|
jpayne@69
|
144 * such as <code>NumberFormat</code> have a number of convenience methods
|
jpayne@69
|
145 * for creating a default object of that type. For example, the
|
jpayne@69
|
146 * <code>NumberFormat</code> class provides these three convenience methods
|
jpayne@69
|
147 * for creating a default <code>NumberFormat</code> object:
|
jpayne@69
|
148 * \htmlonly<blockquote>\endhtmlonly
|
jpayne@69
|
149 * <pre>
|
jpayne@69
|
150 * UErrorCode success = U_ZERO_ERROR;
|
jpayne@69
|
151 * Locale myLocale;
|
jpayne@69
|
152 * NumberFormat *nf;
|
jpayne@69
|
153 *
|
jpayne@69
|
154 * nf = NumberFormat::createInstance( success ); delete nf;
|
jpayne@69
|
155 * nf = NumberFormat::createCurrencyInstance( success ); delete nf;
|
jpayne@69
|
156 * nf = NumberFormat::createPercentInstance( success ); delete nf;
|
jpayne@69
|
157 * </pre>
|
jpayne@69
|
158 * \htmlonly</blockquote>\endhtmlonly
|
jpayne@69
|
159 * Each of these methods has two variants; one with an explicit locale
|
jpayne@69
|
160 * and one without; the latter using the default locale.
|
jpayne@69
|
161 * \htmlonly<blockquote>\endhtmlonly
|
jpayne@69
|
162 * <pre>
|
jpayne@69
|
163 * nf = NumberFormat::createInstance( myLocale, success ); delete nf;
|
jpayne@69
|
164 * nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf;
|
jpayne@69
|
165 * nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf;
|
jpayne@69
|
166 * </pre>
|
jpayne@69
|
167 * \htmlonly</blockquote>\endhtmlonly
|
jpayne@69
|
168 * A <code>Locale</code> is the mechanism for identifying the kind of object
|
jpayne@69
|
169 * (<code>NumberFormat</code>) that you would like to get. The locale is
|
jpayne@69
|
170 * <STRONG>just</STRONG> a mechanism for identifying objects,
|
jpayne@69
|
171 * <STRONG>not</STRONG> a container for the objects themselves.
|
jpayne@69
|
172 *
|
jpayne@69
|
173 * <P>
|
jpayne@69
|
174 * Each class that performs locale-sensitive operations allows you
|
jpayne@69
|
175 * to get all the available objects of that type. You can sift
|
jpayne@69
|
176 * through these objects by language, country, or variant,
|
jpayne@69
|
177 * and use the display names to present a menu to the user.
|
jpayne@69
|
178 * For example, you can create a menu of all the collation objects
|
jpayne@69
|
179 * suitable for a given language. Such classes implement these
|
jpayne@69
|
180 * three class methods:
|
jpayne@69
|
181 * \htmlonly<blockquote>\endhtmlonly
|
jpayne@69
|
182 * <pre>
|
jpayne@69
|
183 * static Locale* getAvailableLocales(int32_t& numLocales)
|
jpayne@69
|
184 * static UnicodeString& getDisplayName(const Locale& objectLocale,
|
jpayne@69
|
185 * const Locale& displayLocale,
|
jpayne@69
|
186 * UnicodeString& displayName)
|
jpayne@69
|
187 * static UnicodeString& getDisplayName(const Locale& objectLocale,
|
jpayne@69
|
188 * UnicodeString& displayName)
|
jpayne@69
|
189 * </pre>
|
jpayne@69
|
190 * \htmlonly</blockquote>\endhtmlonly
|
jpayne@69
|
191 *
|
jpayne@69
|
192 * @stable ICU 2.0
|
jpayne@69
|
193 * @see ResourceBundle
|
jpayne@69
|
194 */
|
jpayne@69
|
195 class U_COMMON_API Locale : public UObject {
|
jpayne@69
|
196 public:
|
jpayne@69
|
197 /** Useful constant for the Root locale. @stable ICU 4.4 */
|
jpayne@69
|
198 static const Locale &U_EXPORT2 getRoot(void);
|
jpayne@69
|
199 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
200 static const Locale &U_EXPORT2 getEnglish(void);
|
jpayne@69
|
201 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
202 static const Locale &U_EXPORT2 getFrench(void);
|
jpayne@69
|
203 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
204 static const Locale &U_EXPORT2 getGerman(void);
|
jpayne@69
|
205 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
206 static const Locale &U_EXPORT2 getItalian(void);
|
jpayne@69
|
207 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
208 static const Locale &U_EXPORT2 getJapanese(void);
|
jpayne@69
|
209 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
210 static const Locale &U_EXPORT2 getKorean(void);
|
jpayne@69
|
211 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
212 static const Locale &U_EXPORT2 getChinese(void);
|
jpayne@69
|
213 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
214 static const Locale &U_EXPORT2 getSimplifiedChinese(void);
|
jpayne@69
|
215 /** Useful constant for this language. @stable ICU 2.0 */
|
jpayne@69
|
216 static const Locale &U_EXPORT2 getTraditionalChinese(void);
|
jpayne@69
|
217
|
jpayne@69
|
218 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
219 static const Locale &U_EXPORT2 getFrance(void);
|
jpayne@69
|
220 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
221 static const Locale &U_EXPORT2 getGermany(void);
|
jpayne@69
|
222 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
223 static const Locale &U_EXPORT2 getItaly(void);
|
jpayne@69
|
224 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
225 static const Locale &U_EXPORT2 getJapan(void);
|
jpayne@69
|
226 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
227 static const Locale &U_EXPORT2 getKorea(void);
|
jpayne@69
|
228 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
229 static const Locale &U_EXPORT2 getChina(void);
|
jpayne@69
|
230 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
231 static const Locale &U_EXPORT2 getPRC(void);
|
jpayne@69
|
232 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
233 static const Locale &U_EXPORT2 getTaiwan(void);
|
jpayne@69
|
234 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
235 static const Locale &U_EXPORT2 getUK(void);
|
jpayne@69
|
236 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
237 static const Locale &U_EXPORT2 getUS(void);
|
jpayne@69
|
238 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
239 static const Locale &U_EXPORT2 getCanada(void);
|
jpayne@69
|
240 /** Useful constant for this country/region. @stable ICU 2.0 */
|
jpayne@69
|
241 static const Locale &U_EXPORT2 getCanadaFrench(void);
|
jpayne@69
|
242
|
jpayne@69
|
243
|
jpayne@69
|
244 /**
|
jpayne@69
|
245 * Construct a default locale object, a Locale for the default locale ID.
|
jpayne@69
|
246 *
|
jpayne@69
|
247 * @see getDefault
|
jpayne@69
|
248 * @see uloc_getDefault
|
jpayne@69
|
249 * @stable ICU 2.0
|
jpayne@69
|
250 */
|
jpayne@69
|
251 Locale();
|
jpayne@69
|
252
|
jpayne@69
|
253 /**
|
jpayne@69
|
254 * Construct a locale from language, country, variant.
|
jpayne@69
|
255 * If an error occurs, then the constructed object will be "bogus"
|
jpayne@69
|
256 * (isBogus() will return TRUE).
|
jpayne@69
|
257 *
|
jpayne@69
|
258 * @param language Lowercase two-letter or three-letter ISO-639 code.
|
jpayne@69
|
259 * This parameter can instead be an ICU style C locale (e.g. "en_US"),
|
jpayne@69
|
260 * but the other parameters must not be used.
|
jpayne@69
|
261 * This parameter can be NULL; if so,
|
jpayne@69
|
262 * the locale is initialized to match the current default locale.
|
jpayne@69
|
263 * (This is the same as using the default constructor.)
|
jpayne@69
|
264 * Please note: The Java Locale class does NOT accept the form
|
jpayne@69
|
265 * 'new Locale("en_US")' but only 'new Locale("en","US")'
|
jpayne@69
|
266 *
|
jpayne@69
|
267 * @param country Uppercase two-letter ISO-3166 code. (optional)
|
jpayne@69
|
268 * @param variant Uppercase vendor and browser specific code. See class
|
jpayne@69
|
269 * description. (optional)
|
jpayne@69
|
270 * @param keywordsAndValues A string consisting of keyword/values pairs, such as
|
jpayne@69
|
271 * "collation=phonebook;currency=euro"
|
jpayne@69
|
272 *
|
jpayne@69
|
273 * @see getDefault
|
jpayne@69
|
274 * @see uloc_getDefault
|
jpayne@69
|
275 * @stable ICU 2.0
|
jpayne@69
|
276 */
|
jpayne@69
|
277 Locale( const char * language,
|
jpayne@69
|
278 const char * country = 0,
|
jpayne@69
|
279 const char * variant = 0,
|
jpayne@69
|
280 const char * keywordsAndValues = 0);
|
jpayne@69
|
281
|
jpayne@69
|
282 /**
|
jpayne@69
|
283 * Initializes a Locale object from another Locale object.
|
jpayne@69
|
284 *
|
jpayne@69
|
285 * @param other The Locale object being copied in.
|
jpayne@69
|
286 * @stable ICU 2.0
|
jpayne@69
|
287 */
|
jpayne@69
|
288 Locale(const Locale& other);
|
jpayne@69
|
289
|
jpayne@69
|
290 /**
|
jpayne@69
|
291 * Move constructor; might leave source in bogus state.
|
jpayne@69
|
292 * This locale will have the same contents that the source locale had.
|
jpayne@69
|
293 *
|
jpayne@69
|
294 * @param other The Locale object being moved in.
|
jpayne@69
|
295 * @stable ICU 63
|
jpayne@69
|
296 */
|
jpayne@69
|
297 Locale(Locale&& other) U_NOEXCEPT;
|
jpayne@69
|
298
|
jpayne@69
|
299 /**
|
jpayne@69
|
300 * Destructor
|
jpayne@69
|
301 * @stable ICU 2.0
|
jpayne@69
|
302 */
|
jpayne@69
|
303 virtual ~Locale() ;
|
jpayne@69
|
304
|
jpayne@69
|
305 /**
|
jpayne@69
|
306 * Replaces the entire contents of *this with the specified value.
|
jpayne@69
|
307 *
|
jpayne@69
|
308 * @param other The Locale object being copied in.
|
jpayne@69
|
309 * @return *this
|
jpayne@69
|
310 * @stable ICU 2.0
|
jpayne@69
|
311 */
|
jpayne@69
|
312 Locale& operator=(const Locale& other);
|
jpayne@69
|
313
|
jpayne@69
|
314 /**
|
jpayne@69
|
315 * Move assignment operator; might leave source in bogus state.
|
jpayne@69
|
316 * This locale will have the same contents that the source locale had.
|
jpayne@69
|
317 * The behavior is undefined if *this and the source are the same object.
|
jpayne@69
|
318 *
|
jpayne@69
|
319 * @param other The Locale object being moved in.
|
jpayne@69
|
320 * @return *this
|
jpayne@69
|
321 * @stable ICU 63
|
jpayne@69
|
322 */
|
jpayne@69
|
323 Locale& operator=(Locale&& other) U_NOEXCEPT;
|
jpayne@69
|
324
|
jpayne@69
|
325 /**
|
jpayne@69
|
326 * Checks if two locale keys are the same.
|
jpayne@69
|
327 *
|
jpayne@69
|
328 * @param other The locale key object to be compared with this.
|
jpayne@69
|
329 * @return True if the two locale keys are the same, false otherwise.
|
jpayne@69
|
330 * @stable ICU 2.0
|
jpayne@69
|
331 */
|
jpayne@69
|
332 UBool operator==(const Locale& other) const;
|
jpayne@69
|
333
|
jpayne@69
|
334 /**
|
jpayne@69
|
335 * Checks if two locale keys are not the same.
|
jpayne@69
|
336 *
|
jpayne@69
|
337 * @param other The locale key object to be compared with this.
|
jpayne@69
|
338 * @return True if the two locale keys are not the same, false
|
jpayne@69
|
339 * otherwise.
|
jpayne@69
|
340 * @stable ICU 2.0
|
jpayne@69
|
341 */
|
jpayne@69
|
342 inline UBool operator!=(const Locale& other) const;
|
jpayne@69
|
343
|
jpayne@69
|
344 /**
|
jpayne@69
|
345 * Clone this object.
|
jpayne@69
|
346 * Clones can be used concurrently in multiple threads.
|
jpayne@69
|
347 * If an error occurs, then NULL is returned.
|
jpayne@69
|
348 * The caller must delete the clone.
|
jpayne@69
|
349 *
|
jpayne@69
|
350 * @return a clone of this object
|
jpayne@69
|
351 *
|
jpayne@69
|
352 * @see getDynamicClassID
|
jpayne@69
|
353 * @stable ICU 2.8
|
jpayne@69
|
354 */
|
jpayne@69
|
355 Locale *clone() const;
|
jpayne@69
|
356
|
jpayne@69
|
357 #ifndef U_HIDE_SYSTEM_API
|
jpayne@69
|
358 /**
|
jpayne@69
|
359 * Common methods of getting the current default Locale. Used for the
|
jpayne@69
|
360 * presentation: menus, dialogs, etc. Generally set once when your applet or
|
jpayne@69
|
361 * application is initialized, then never reset. (If you do reset the
|
jpayne@69
|
362 * default locale, you probably want to reload your GUI, so that the change
|
jpayne@69
|
363 * is reflected in your interface.)
|
jpayne@69
|
364 *
|
jpayne@69
|
365 * More advanced programs will allow users to use different locales for
|
jpayne@69
|
366 * different fields, e.g. in a spreadsheet.
|
jpayne@69
|
367 *
|
jpayne@69
|
368 * Note that the initial setting will match the host system.
|
jpayne@69
|
369 * @return a reference to the Locale object for the default locale ID
|
jpayne@69
|
370 * @system
|
jpayne@69
|
371 * @stable ICU 2.0
|
jpayne@69
|
372 */
|
jpayne@69
|
373 static const Locale& U_EXPORT2 getDefault(void);
|
jpayne@69
|
374
|
jpayne@69
|
375 /**
|
jpayne@69
|
376 * Sets the default. Normally set once at the beginning of a process,
|
jpayne@69
|
377 * then never reset.
|
jpayne@69
|
378 * setDefault() only changes ICU's default locale ID, <strong>not</strong>
|
jpayne@69
|
379 * the default locale ID of the runtime environment.
|
jpayne@69
|
380 *
|
jpayne@69
|
381 * @param newLocale Locale to set to. If NULL, set to the value obtained
|
jpayne@69
|
382 * from the runtime environment.
|
jpayne@69
|
383 * @param success The error code.
|
jpayne@69
|
384 * @system
|
jpayne@69
|
385 * @stable ICU 2.0
|
jpayne@69
|
386 */
|
jpayne@69
|
387 static void U_EXPORT2 setDefault(const Locale& newLocale,
|
jpayne@69
|
388 UErrorCode& success);
|
jpayne@69
|
389 #endif /* U_HIDE_SYSTEM_API */
|
jpayne@69
|
390
|
jpayne@69
|
391 /**
|
jpayne@69
|
392 * Returns a Locale for the specified BCP47 language tag string.
|
jpayne@69
|
393 * If the specified language tag contains any ill-formed subtags,
|
jpayne@69
|
394 * the first such subtag and all following subtags are ignored.
|
jpayne@69
|
395 * <p>
|
jpayne@69
|
396 * This implements the 'Language-Tag' production of BCP47, and so
|
jpayne@69
|
397 * supports grandfathered (regular and irregular) as well as private
|
jpayne@69
|
398 * use language tags. Private use tags are represented as 'x-whatever',
|
jpayne@69
|
399 * and grandfathered tags are converted to their canonical replacements
|
jpayne@69
|
400 * where they exist. Note that a few grandfathered tags have no modern
|
jpayne@69
|
401 * replacement, these will be converted using the fallback described in
|
jpayne@69
|
402 * the first paragraph, so some information might be lost.
|
jpayne@69
|
403 * @param tag the input BCP47 language tag.
|
jpayne@69
|
404 * @param status error information if creating the Locale failed.
|
jpayne@69
|
405 * @return the Locale for the specified BCP47 language tag.
|
jpayne@69
|
406 * @stable ICU 63
|
jpayne@69
|
407 */
|
jpayne@69
|
408 static Locale U_EXPORT2 forLanguageTag(StringPiece tag, UErrorCode& status);
|
jpayne@69
|
409
|
jpayne@69
|
410 /**
|
jpayne@69
|
411 * Returns a well-formed language tag for this Locale.
|
jpayne@69
|
412 * <p>
|
jpayne@69
|
413 * <b>Note</b>: Any locale fields which do not satisfy the BCP47 syntax
|
jpayne@69
|
414 * requirement will be silently omitted from the result.
|
jpayne@69
|
415 *
|
jpayne@69
|
416 * If this function fails, partial output may have been written to the sink.
|
jpayne@69
|
417 *
|
jpayne@69
|
418 * @param sink the output sink receiving the BCP47 language
|
jpayne@69
|
419 * tag for this Locale.
|
jpayne@69
|
420 * @param status error information if creating the language tag failed.
|
jpayne@69
|
421 * @stable ICU 63
|
jpayne@69
|
422 */
|
jpayne@69
|
423 void toLanguageTag(ByteSink& sink, UErrorCode& status) const;
|
jpayne@69
|
424
|
jpayne@69
|
425 /**
|
jpayne@69
|
426 * Returns a well-formed language tag for this Locale.
|
jpayne@69
|
427 * <p>
|
jpayne@69
|
428 * <b>Note</b>: Any locale fields which do not satisfy the BCP47 syntax
|
jpayne@69
|
429 * requirement will be silently omitted from the result.
|
jpayne@69
|
430 *
|
jpayne@69
|
431 * @param status error information if creating the language tag failed.
|
jpayne@69
|
432 * @return the BCP47 language tag for this Locale.
|
jpayne@69
|
433 * @stable ICU 63
|
jpayne@69
|
434 */
|
jpayne@69
|
435 template<typename StringClass>
|
jpayne@69
|
436 inline StringClass toLanguageTag(UErrorCode& status) const;
|
jpayne@69
|
437
|
jpayne@69
|
438 /**
|
jpayne@69
|
439 * Creates a locale which has had minimal canonicalization
|
jpayne@69
|
440 * as per uloc_getName().
|
jpayne@69
|
441 * @param name The name to create from. If name is null,
|
jpayne@69
|
442 * the default Locale is used.
|
jpayne@69
|
443 * @return new locale object
|
jpayne@69
|
444 * @stable ICU 2.0
|
jpayne@69
|
445 * @see uloc_getName
|
jpayne@69
|
446 */
|
jpayne@69
|
447 static Locale U_EXPORT2 createFromName(const char *name);
|
jpayne@69
|
448
|
jpayne@69
|
449 /**
|
jpayne@69
|
450 * Creates a locale from the given string after canonicalizing
|
jpayne@69
|
451 * the string according to CLDR by calling uloc_canonicalize().
|
jpayne@69
|
452 * @param name the locale ID to create from. Must not be NULL.
|
jpayne@69
|
453 * @return a new locale object corresponding to the given name
|
jpayne@69
|
454 * @stable ICU 3.0
|
jpayne@69
|
455 * @see uloc_canonicalize
|
jpayne@69
|
456 */
|
jpayne@69
|
457 static Locale U_EXPORT2 createCanonical(const char* name);
|
jpayne@69
|
458
|
jpayne@69
|
459 /**
|
jpayne@69
|
460 * Returns the locale's ISO-639 language code.
|
jpayne@69
|
461 * @return An alias to the code
|
jpayne@69
|
462 * @stable ICU 2.0
|
jpayne@69
|
463 */
|
jpayne@69
|
464 inline const char * getLanguage( ) const;
|
jpayne@69
|
465
|
jpayne@69
|
466 /**
|
jpayne@69
|
467 * Returns the locale's ISO-15924 abbreviation script code.
|
jpayne@69
|
468 * @return An alias to the code
|
jpayne@69
|
469 * @see uscript_getShortName
|
jpayne@69
|
470 * @see uscript_getCode
|
jpayne@69
|
471 * @stable ICU 2.8
|
jpayne@69
|
472 */
|
jpayne@69
|
473 inline const char * getScript( ) const;
|
jpayne@69
|
474
|
jpayne@69
|
475 /**
|
jpayne@69
|
476 * Returns the locale's ISO-3166 country code.
|
jpayne@69
|
477 * @return An alias to the code
|
jpayne@69
|
478 * @stable ICU 2.0
|
jpayne@69
|
479 */
|
jpayne@69
|
480 inline const char * getCountry( ) const;
|
jpayne@69
|
481
|
jpayne@69
|
482 /**
|
jpayne@69
|
483 * Returns the locale's variant code.
|
jpayne@69
|
484 * @return An alias to the code
|
jpayne@69
|
485 * @stable ICU 2.0
|
jpayne@69
|
486 */
|
jpayne@69
|
487 inline const char * getVariant( ) const;
|
jpayne@69
|
488
|
jpayne@69
|
489 /**
|
jpayne@69
|
490 * Returns the programmatic name of the entire locale, with the language,
|
jpayne@69
|
491 * country and variant separated by underbars. If a field is missing, up
|
jpayne@69
|
492 * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
|
jpayne@69
|
493 * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
|
jpayne@69
|
494 * @return A pointer to "name".
|
jpayne@69
|
495 * @stable ICU 2.0
|
jpayne@69
|
496 */
|
jpayne@69
|
497 inline const char * getName() const;
|
jpayne@69
|
498
|
jpayne@69
|
499 /**
|
jpayne@69
|
500 * Returns the programmatic name of the entire locale as getName() would return,
|
jpayne@69
|
501 * but without keywords.
|
jpayne@69
|
502 * @return A pointer to "name".
|
jpayne@69
|
503 * @see getName
|
jpayne@69
|
504 * @stable ICU 2.8
|
jpayne@69
|
505 */
|
jpayne@69
|
506 const char * getBaseName() const;
|
jpayne@69
|
507
|
jpayne@69
|
508 /**
|
jpayne@69
|
509 * Add the likely subtags for this Locale, per the algorithm described
|
jpayne@69
|
510 * in the following CLDR technical report:
|
jpayne@69
|
511 *
|
jpayne@69
|
512 * http://www.unicode.org/reports/tr35/#Likely_Subtags
|
jpayne@69
|
513 *
|
jpayne@69
|
514 * If this Locale is already in the maximal form, or not valid, or there is
|
jpayne@69
|
515 * no data available for maximization, the Locale will be unchanged.
|
jpayne@69
|
516 *
|
jpayne@69
|
517 * For example, "und-Zzzz" cannot be maximized, since there is no
|
jpayne@69
|
518 * reasonable maximization.
|
jpayne@69
|
519 *
|
jpayne@69
|
520 * Examples:
|
jpayne@69
|
521 *
|
jpayne@69
|
522 * "en" maximizes to "en_Latn_US"
|
jpayne@69
|
523 *
|
jpayne@69
|
524 * "de" maximizes to "de_Latn_US"
|
jpayne@69
|
525 *
|
jpayne@69
|
526 * "sr" maximizes to "sr_Cyrl_RS"
|
jpayne@69
|
527 *
|
jpayne@69
|
528 * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.)
|
jpayne@69
|
529 *
|
jpayne@69
|
530 * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.)
|
jpayne@69
|
531 *
|
jpayne@69
|
532 * @param status error information if maximizing this Locale failed.
|
jpayne@69
|
533 * If this Locale is not well-formed, the error code is
|
jpayne@69
|
534 * U_ILLEGAL_ARGUMENT_ERROR.
|
jpayne@69
|
535 * @stable ICU 63
|
jpayne@69
|
536 */
|
jpayne@69
|
537 void addLikelySubtags(UErrorCode& status);
|
jpayne@69
|
538
|
jpayne@69
|
539 /**
|
jpayne@69
|
540 * Minimize the subtags for this Locale, per the algorithm described
|
jpayne@69
|
541 * in the following CLDR technical report:
|
jpayne@69
|
542 *
|
jpayne@69
|
543 * http://www.unicode.org/reports/tr35/#Likely_Subtags
|
jpayne@69
|
544 *
|
jpayne@69
|
545 * If this Locale is already in the minimal form, or not valid, or there is
|
jpayne@69
|
546 * no data available for minimization, the Locale will be unchanged.
|
jpayne@69
|
547 *
|
jpayne@69
|
548 * Since the minimization algorithm relies on proper maximization, see the
|
jpayne@69
|
549 * comments for addLikelySubtags for reasons why there might not be any
|
jpayne@69
|
550 * data.
|
jpayne@69
|
551 *
|
jpayne@69
|
552 * Examples:
|
jpayne@69
|
553 *
|
jpayne@69
|
554 * "en_Latn_US" minimizes to "en"
|
jpayne@69
|
555 *
|
jpayne@69
|
556 * "de_Latn_US" minimizes to "de"
|
jpayne@69
|
557 *
|
jpayne@69
|
558 * "sr_Cyrl_RS" minimizes to "sr"
|
jpayne@69
|
559 *
|
jpayne@69
|
560 * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the
|
jpayne@69
|
561 * script, and minimizing to "zh" would imply "zh_Hans_CN".)
|
jpayne@69
|
562 *
|
jpayne@69
|
563 * @param status error information if maximizing this Locale failed.
|
jpayne@69
|
564 * If this Locale is not well-formed, the error code is
|
jpayne@69
|
565 * U_ILLEGAL_ARGUMENT_ERROR.
|
jpayne@69
|
566 * @stable ICU 63
|
jpayne@69
|
567 */
|
jpayne@69
|
568 void minimizeSubtags(UErrorCode& status);
|
jpayne@69
|
569
|
jpayne@69
|
570 #ifndef U_HIDE_DRAFT_API
|
jpayne@69
|
571 /**
|
jpayne@69
|
572 * Canonicalize the locale ID of this object according to CLDR.
|
jpayne@69
|
573 * @param status the status code
|
jpayne@69
|
574 * @draft ICU 67
|
jpayne@69
|
575 * @see createCanonical
|
jpayne@69
|
576 */
|
jpayne@69
|
577 void canonicalize(UErrorCode& status);
|
jpayne@69
|
578 #endif // U_HIDE_DRAFT_API
|
jpayne@69
|
579
|
jpayne@69
|
580 /**
|
jpayne@69
|
581 * Gets the list of keywords for the specified locale.
|
jpayne@69
|
582 *
|
jpayne@69
|
583 * @param status the status code
|
jpayne@69
|
584 * @return pointer to StringEnumeration class, or NULL if there are no keywords.
|
jpayne@69
|
585 * Client must dispose of it by calling delete.
|
jpayne@69
|
586 * @see getKeywords
|
jpayne@69
|
587 * @stable ICU 2.8
|
jpayne@69
|
588 */
|
jpayne@69
|
589 StringEnumeration * createKeywords(UErrorCode &status) const;
|
jpayne@69
|
590
|
jpayne@69
|
591 /**
|
jpayne@69
|
592 * Gets the list of Unicode keywords for the specified locale.
|
jpayne@69
|
593 *
|
jpayne@69
|
594 * @param status the status code
|
jpayne@69
|
595 * @return pointer to StringEnumeration class, or NULL if there are no keywords.
|
jpayne@69
|
596 * Client must dispose of it by calling delete.
|
jpayne@69
|
597 * @see getUnicodeKeywords
|
jpayne@69
|
598 * @stable ICU 63
|
jpayne@69
|
599 */
|
jpayne@69
|
600 StringEnumeration * createUnicodeKeywords(UErrorCode &status) const;
|
jpayne@69
|
601
|
jpayne@69
|
602 /**
|
jpayne@69
|
603 * Gets the set of keywords for this Locale.
|
jpayne@69
|
604 *
|
jpayne@69
|
605 * A wrapper to call createKeywords() and write the resulting
|
jpayne@69
|
606 * keywords as standard strings (or compatible objects) into any kind of
|
jpayne@69
|
607 * container that can be written to by an STL style output iterator.
|
jpayne@69
|
608 *
|
jpayne@69
|
609 * @param iterator an STL style output iterator to write the keywords to.
|
jpayne@69
|
610 * @param status error information if creating set of keywords failed.
|
jpayne@69
|
611 * @stable ICU 63
|
jpayne@69
|
612 */
|
jpayne@69
|
613 template<typename StringClass, typename OutputIterator>
|
jpayne@69
|
614 inline void getKeywords(OutputIterator iterator, UErrorCode& status) const;
|
jpayne@69
|
615
|
jpayne@69
|
616 /**
|
jpayne@69
|
617 * Gets the set of Unicode keywords for this Locale.
|
jpayne@69
|
618 *
|
jpayne@69
|
619 * A wrapper to call createUnicodeKeywords() and write the resulting
|
jpayne@69
|
620 * keywords as standard strings (or compatible objects) into any kind of
|
jpayne@69
|
621 * container that can be written to by an STL style output iterator.
|
jpayne@69
|
622 *
|
jpayne@69
|
623 * @param iterator an STL style output iterator to write the keywords to.
|
jpayne@69
|
624 * @param status error information if creating set of keywords failed.
|
jpayne@69
|
625 * @stable ICU 63
|
jpayne@69
|
626 */
|
jpayne@69
|
627 template<typename StringClass, typename OutputIterator>
|
jpayne@69
|
628 inline void getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const;
|
jpayne@69
|
629
|
jpayne@69
|
630 /**
|
jpayne@69
|
631 * Gets the value for a keyword.
|
jpayne@69
|
632 *
|
jpayne@69
|
633 * This uses legacy keyword=value pairs, like "collation=phonebook".
|
jpayne@69
|
634 *
|
jpayne@69
|
635 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
636 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
637 *
|
jpayne@69
|
638 * @param keywordName name of the keyword for which we want the value. Case insensitive.
|
jpayne@69
|
639 * @param buffer The buffer to receive the keyword value.
|
jpayne@69
|
640 * @param bufferCapacity The capacity of receiving buffer
|
jpayne@69
|
641 * @param status Returns any error information while performing this operation.
|
jpayne@69
|
642 * @return the length of the keyword value
|
jpayne@69
|
643 *
|
jpayne@69
|
644 * @stable ICU 2.8
|
jpayne@69
|
645 */
|
jpayne@69
|
646 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
|
jpayne@69
|
647
|
jpayne@69
|
648 /**
|
jpayne@69
|
649 * Gets the value for a keyword.
|
jpayne@69
|
650 *
|
jpayne@69
|
651 * This uses legacy keyword=value pairs, like "collation=phonebook".
|
jpayne@69
|
652 *
|
jpayne@69
|
653 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
654 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
655 *
|
jpayne@69
|
656 * @param keywordName name of the keyword for which we want the value.
|
jpayne@69
|
657 * @param sink the sink to receive the keyword value.
|
jpayne@69
|
658 * @param status error information if getting the value failed.
|
jpayne@69
|
659 * @stable ICU 63
|
jpayne@69
|
660 */
|
jpayne@69
|
661 void getKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const;
|
jpayne@69
|
662
|
jpayne@69
|
663 /**
|
jpayne@69
|
664 * Gets the value for a keyword.
|
jpayne@69
|
665 *
|
jpayne@69
|
666 * This uses legacy keyword=value pairs, like "collation=phonebook".
|
jpayne@69
|
667 *
|
jpayne@69
|
668 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
669 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
670 *
|
jpayne@69
|
671 * @param keywordName name of the keyword for which we want the value.
|
jpayne@69
|
672 * @param status error information if getting the value failed.
|
jpayne@69
|
673 * @return the keyword value.
|
jpayne@69
|
674 * @stable ICU 63
|
jpayne@69
|
675 */
|
jpayne@69
|
676 template<typename StringClass>
|
jpayne@69
|
677 inline StringClass getKeywordValue(StringPiece keywordName, UErrorCode& status) const;
|
jpayne@69
|
678
|
jpayne@69
|
679 /**
|
jpayne@69
|
680 * Gets the Unicode value for a Unicode keyword.
|
jpayne@69
|
681 *
|
jpayne@69
|
682 * This uses Unicode key-value pairs, like "co-phonebk".
|
jpayne@69
|
683 *
|
jpayne@69
|
684 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
685 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
686 *
|
jpayne@69
|
687 * @param keywordName name of the keyword for which we want the value.
|
jpayne@69
|
688 * @param sink the sink to receive the keyword value.
|
jpayne@69
|
689 * @param status error information if getting the value failed.
|
jpayne@69
|
690 * @stable ICU 63
|
jpayne@69
|
691 */
|
jpayne@69
|
692 void getUnicodeKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& status) const;
|
jpayne@69
|
693
|
jpayne@69
|
694 /**
|
jpayne@69
|
695 * Gets the Unicode value for a Unicode keyword.
|
jpayne@69
|
696 *
|
jpayne@69
|
697 * This uses Unicode key-value pairs, like "co-phonebk".
|
jpayne@69
|
698 *
|
jpayne@69
|
699 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
700 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
701 *
|
jpayne@69
|
702 * @param keywordName name of the keyword for which we want the value.
|
jpayne@69
|
703 * @param status error information if getting the value failed.
|
jpayne@69
|
704 * @return the keyword value.
|
jpayne@69
|
705 * @stable ICU 63
|
jpayne@69
|
706 */
|
jpayne@69
|
707 template<typename StringClass>
|
jpayne@69
|
708 inline StringClass getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const;
|
jpayne@69
|
709
|
jpayne@69
|
710 /**
|
jpayne@69
|
711 * Sets or removes the value for a keyword.
|
jpayne@69
|
712 *
|
jpayne@69
|
713 * For removing all keywords, use getBaseName(),
|
jpayne@69
|
714 * and construct a new Locale if it differs from getName().
|
jpayne@69
|
715 *
|
jpayne@69
|
716 * This uses legacy keyword=value pairs, like "collation=phonebook".
|
jpayne@69
|
717 *
|
jpayne@69
|
718 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
719 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
720 *
|
jpayne@69
|
721 * @param keywordName name of the keyword to be set. Case insensitive.
|
jpayne@69
|
722 * @param keywordValue value of the keyword to be set. If 0-length or
|
jpayne@69
|
723 * NULL, will result in the keyword being removed. No error is given if
|
jpayne@69
|
724 * that keyword does not exist.
|
jpayne@69
|
725 * @param status Returns any error information while performing this operation.
|
jpayne@69
|
726 *
|
jpayne@69
|
727 * @stable ICU 49
|
jpayne@69
|
728 */
|
jpayne@69
|
729 void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
|
jpayne@69
|
730
|
jpayne@69
|
731 /**
|
jpayne@69
|
732 * Sets or removes the value for a keyword.
|
jpayne@69
|
733 *
|
jpayne@69
|
734 * For removing all keywords, use getBaseName(),
|
jpayne@69
|
735 * and construct a new Locale if it differs from getName().
|
jpayne@69
|
736 *
|
jpayne@69
|
737 * This uses legacy keyword=value pairs, like "collation=phonebook".
|
jpayne@69
|
738 *
|
jpayne@69
|
739 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
740 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
741 *
|
jpayne@69
|
742 * @param keywordName name of the keyword to be set.
|
jpayne@69
|
743 * @param keywordValue value of the keyword to be set. If 0-length or
|
jpayne@69
|
744 * NULL, will result in the keyword being removed. No error is given if
|
jpayne@69
|
745 * that keyword does not exist.
|
jpayne@69
|
746 * @param status Returns any error information while performing this operation.
|
jpayne@69
|
747 * @stable ICU 63
|
jpayne@69
|
748 */
|
jpayne@69
|
749 void setKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status);
|
jpayne@69
|
750
|
jpayne@69
|
751 /**
|
jpayne@69
|
752 * Sets or removes the Unicode value for a Unicode keyword.
|
jpayne@69
|
753 *
|
jpayne@69
|
754 * For removing all keywords, use getBaseName(),
|
jpayne@69
|
755 * and construct a new Locale if it differs from getName().
|
jpayne@69
|
756 *
|
jpayne@69
|
757 * This uses Unicode key-value pairs, like "co-phonebk".
|
jpayne@69
|
758 *
|
jpayne@69
|
759 * ICU4C doesn't do automatic conversion between legacy and Unicode
|
jpayne@69
|
760 * keywords and values in getters and setters (as opposed to ICU4J).
|
jpayne@69
|
761 *
|
jpayne@69
|
762 * @param keywordName name of the keyword to be set.
|
jpayne@69
|
763 * @param keywordValue value of the keyword to be set. If 0-length or
|
jpayne@69
|
764 * NULL, will result in the keyword being removed. No error is given if
|
jpayne@69
|
765 * that keyword does not exist.
|
jpayne@69
|
766 * @param status Returns any error information while performing this operation.
|
jpayne@69
|
767 * @stable ICU 63
|
jpayne@69
|
768 */
|
jpayne@69
|
769 void setUnicodeKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode& status);
|
jpayne@69
|
770
|
jpayne@69
|
771 /**
|
jpayne@69
|
772 * returns the locale's three-letter language code, as specified
|
jpayne@69
|
773 * in ISO draft standard ISO-639-2.
|
jpayne@69
|
774 * @return An alias to the code, or an empty string
|
jpayne@69
|
775 * @stable ICU 2.0
|
jpayne@69
|
776 */
|
jpayne@69
|
777 const char * getISO3Language() const;
|
jpayne@69
|
778
|
jpayne@69
|
779 /**
|
jpayne@69
|
780 * Fills in "name" with the locale's three-letter ISO-3166 country code.
|
jpayne@69
|
781 * @return An alias to the code, or an empty string
|
jpayne@69
|
782 * @stable ICU 2.0
|
jpayne@69
|
783 */
|
jpayne@69
|
784 const char * getISO3Country() const;
|
jpayne@69
|
785
|
jpayne@69
|
786 /**
|
jpayne@69
|
787 * Returns the Windows LCID value corresponding to this locale.
|
jpayne@69
|
788 * This value is stored in the resource data for the locale as a one-to-four-digit
|
jpayne@69
|
789 * hexadecimal number. If the resource is missing, in the wrong format, or
|
jpayne@69
|
790 * there is no Windows LCID value that corresponds to this locale, returns 0.
|
jpayne@69
|
791 * @stable ICU 2.0
|
jpayne@69
|
792 */
|
jpayne@69
|
793 uint32_t getLCID(void) const;
|
jpayne@69
|
794
|
jpayne@69
|
795 /**
|
jpayne@69
|
796 * Returns whether this locale's script is written right-to-left.
|
jpayne@69
|
797 * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags().
|
jpayne@69
|
798 * If no likely script is known, then FALSE is returned.
|
jpayne@69
|
799 *
|
jpayne@69
|
800 * A script is right-to-left according to the CLDR script metadata
|
jpayne@69
|
801 * which corresponds to whether the script's letters have Bidi_Class=R or AL.
|
jpayne@69
|
802 *
|
jpayne@69
|
803 * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl".
|
jpayne@69
|
804 *
|
jpayne@69
|
805 * @return TRUE if the locale's script is written right-to-left
|
jpayne@69
|
806 * @stable ICU 54
|
jpayne@69
|
807 */
|
jpayne@69
|
808 UBool isRightToLeft() const;
|
jpayne@69
|
809
|
jpayne@69
|
810 /**
|
jpayne@69
|
811 * Fills in "dispLang" with the name of this locale's language in a format suitable for
|
jpayne@69
|
812 * user display in the default locale. For example, if the locale's language code is
|
jpayne@69
|
813 * "fr" and the default locale's language code is "en", this function would set
|
jpayne@69
|
814 * dispLang to "French".
|
jpayne@69
|
815 * @param dispLang Receives the language's display name.
|
jpayne@69
|
816 * @return A reference to "dispLang".
|
jpayne@69
|
817 * @stable ICU 2.0
|
jpayne@69
|
818 */
|
jpayne@69
|
819 UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
|
jpayne@69
|
820
|
jpayne@69
|
821 /**
|
jpayne@69
|
822 * Fills in "dispLang" with the name of this locale's language in a format suitable for
|
jpayne@69
|
823 * user display in the locale specified by "displayLocale". For example, if the locale's
|
jpayne@69
|
824 * language code is "en" and displayLocale's language code is "fr", this function would set
|
jpayne@69
|
825 * dispLang to "Anglais".
|
jpayne@69
|
826 * @param displayLocale Specifies the locale to be used to display the name. In other words,
|
jpayne@69
|
827 * if the locale's language code is "en", passing Locale::getFrench() for
|
jpayne@69
|
828 * displayLocale would result in "Anglais", while passing Locale::getGerman()
|
jpayne@69
|
829 * for displayLocale would result in "Englisch".
|
jpayne@69
|
830 * @param dispLang Receives the language's display name.
|
jpayne@69
|
831 * @return A reference to "dispLang".
|
jpayne@69
|
832 * @stable ICU 2.0
|
jpayne@69
|
833 */
|
jpayne@69
|
834 UnicodeString& getDisplayLanguage( const Locale& displayLocale,
|
jpayne@69
|
835 UnicodeString& dispLang) const;
|
jpayne@69
|
836
|
jpayne@69
|
837 /**
|
jpayne@69
|
838 * Fills in "dispScript" with the name of this locale's script in a format suitable
|
jpayne@69
|
839 * for user display in the default locale. For example, if the locale's script code
|
jpayne@69
|
840 * is "LATN" and the default locale's language code is "en", this function would set
|
jpayne@69
|
841 * dispScript to "Latin".
|
jpayne@69
|
842 * @param dispScript Receives the scripts's display name.
|
jpayne@69
|
843 * @return A reference to "dispScript".
|
jpayne@69
|
844 * @stable ICU 2.8
|
jpayne@69
|
845 */
|
jpayne@69
|
846 UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
|
jpayne@69
|
847
|
jpayne@69
|
848 /**
|
jpayne@69
|
849 * Fills in "dispScript" with the name of this locale's country in a format suitable
|
jpayne@69
|
850 * for user display in the locale specified by "displayLocale". For example, if the locale's
|
jpayne@69
|
851 * script code is "LATN" and displayLocale's language code is "en", this function would set
|
jpayne@69
|
852 * dispScript to "Latin".
|
jpayne@69
|
853 * @param displayLocale Specifies the locale to be used to display the name. In other
|
jpayne@69
|
854 * words, if the locale's script code is "LATN", passing
|
jpayne@69
|
855 * Locale::getFrench() for displayLocale would result in "", while
|
jpayne@69
|
856 * passing Locale::getGerman() for displayLocale would result in
|
jpayne@69
|
857 * "".
|
jpayne@69
|
858 * @param dispScript Receives the scripts's display name.
|
jpayne@69
|
859 * @return A reference to "dispScript".
|
jpayne@69
|
860 * @stable ICU 2.8
|
jpayne@69
|
861 */
|
jpayne@69
|
862 UnicodeString& getDisplayScript( const Locale& displayLocale,
|
jpayne@69
|
863 UnicodeString& dispScript) const;
|
jpayne@69
|
864
|
jpayne@69
|
865 /**
|
jpayne@69
|
866 * Fills in "dispCountry" with the name of this locale's country in a format suitable
|
jpayne@69
|
867 * for user display in the default locale. For example, if the locale's country code
|
jpayne@69
|
868 * is "FR" and the default locale's language code is "en", this function would set
|
jpayne@69
|
869 * dispCountry to "France".
|
jpayne@69
|
870 * @param dispCountry Receives the country's display name.
|
jpayne@69
|
871 * @return A reference to "dispCountry".
|
jpayne@69
|
872 * @stable ICU 2.0
|
jpayne@69
|
873 */
|
jpayne@69
|
874 UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
|
jpayne@69
|
875
|
jpayne@69
|
876 /**
|
jpayne@69
|
877 * Fills in "dispCountry" with the name of this locale's country in a format suitable
|
jpayne@69
|
878 * for user display in the locale specified by "displayLocale". For example, if the locale's
|
jpayne@69
|
879 * country code is "US" and displayLocale's language code is "fr", this function would set
|
jpayne@69
|
880 * dispCountry to "États-Unis".
|
jpayne@69
|
881 * @param displayLocale Specifies the locale to be used to display the name. In other
|
jpayne@69
|
882 * words, if the locale's country code is "US", passing
|
jpayne@69
|
883 * Locale::getFrench() for displayLocale would result in "États-Unis", while
|
jpayne@69
|
884 * passing Locale::getGerman() for displayLocale would result in
|
jpayne@69
|
885 * "Vereinigte Staaten".
|
jpayne@69
|
886 * @param dispCountry Receives the country's display name.
|
jpayne@69
|
887 * @return A reference to "dispCountry".
|
jpayne@69
|
888 * @stable ICU 2.0
|
jpayne@69
|
889 */
|
jpayne@69
|
890 UnicodeString& getDisplayCountry( const Locale& displayLocale,
|
jpayne@69
|
891 UnicodeString& dispCountry) const;
|
jpayne@69
|
892
|
jpayne@69
|
893 /**
|
jpayne@69
|
894 * Fills in "dispVar" with the name of this locale's variant code in a format suitable
|
jpayne@69
|
895 * for user display in the default locale.
|
jpayne@69
|
896 * @param dispVar Receives the variant's name.
|
jpayne@69
|
897 * @return A reference to "dispVar".
|
jpayne@69
|
898 * @stable ICU 2.0
|
jpayne@69
|
899 */
|
jpayne@69
|
900 UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
|
jpayne@69
|
901
|
jpayne@69
|
902 /**
|
jpayne@69
|
903 * Fills in "dispVar" with the name of this locale's variant code in a format
|
jpayne@69
|
904 * suitable for user display in the locale specified by "displayLocale".
|
jpayne@69
|
905 * @param displayLocale Specifies the locale to be used to display the name.
|
jpayne@69
|
906 * @param dispVar Receives the variant's display name.
|
jpayne@69
|
907 * @return A reference to "dispVar".
|
jpayne@69
|
908 * @stable ICU 2.0
|
jpayne@69
|
909 */
|
jpayne@69
|
910 UnicodeString& getDisplayVariant( const Locale& displayLocale,
|
jpayne@69
|
911 UnicodeString& dispVar) const;
|
jpayne@69
|
912
|
jpayne@69
|
913 /**
|
jpayne@69
|
914 * Fills in "name" with the name of this locale in a format suitable for user display
|
jpayne@69
|
915 * in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(),
|
jpayne@69
|
916 * and getDisplayVariant() to do its work, and outputs the display name in the format
|
jpayne@69
|
917 * "language (country[,variant])". For example, if the default locale is en_US, then
|
jpayne@69
|
918 * fr_FR's display name would be "French (France)", and es_MX_Traditional's display name
|
jpayne@69
|
919 * would be "Spanish (Mexico,Traditional)".
|
jpayne@69
|
920 * @param name Receives the locale's display name.
|
jpayne@69
|
921 * @return A reference to "name".
|
jpayne@69
|
922 * @stable ICU 2.0
|
jpayne@69
|
923 */
|
jpayne@69
|
924 UnicodeString& getDisplayName( UnicodeString& name) const;
|
jpayne@69
|
925
|
jpayne@69
|
926 /**
|
jpayne@69
|
927 * Fills in "name" with the name of this locale in a format suitable for user display
|
jpayne@69
|
928 * in the locale specified by "displayLocale". This function uses getDisplayLanguage(),
|
jpayne@69
|
929 * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display
|
jpayne@69
|
930 * name in the format "language (country[,variant])". For example, if displayLocale is
|
jpayne@69
|
931 * fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's
|
jpayne@69
|
932 * display name would be "norvégien (Norvège,NY)".
|
jpayne@69
|
933 * @param displayLocale Specifies the locale to be used to display the name.
|
jpayne@69
|
934 * @param name Receives the locale's display name.
|
jpayne@69
|
935 * @return A reference to "name".
|
jpayne@69
|
936 * @stable ICU 2.0
|
jpayne@69
|
937 */
|
jpayne@69
|
938 UnicodeString& getDisplayName( const Locale& displayLocale,
|
jpayne@69
|
939 UnicodeString& name) const;
|
jpayne@69
|
940
|
jpayne@69
|
941 /**
|
jpayne@69
|
942 * Generates a hash code for the locale.
|
jpayne@69
|
943 * @stable ICU 2.0
|
jpayne@69
|
944 */
|
jpayne@69
|
945 int32_t hashCode(void) const;
|
jpayne@69
|
946
|
jpayne@69
|
947 /**
|
jpayne@69
|
948 * Sets the locale to bogus
|
jpayne@69
|
949 * A bogus locale represents a non-existing locale associated
|
jpayne@69
|
950 * with services that can be instantiated from non-locale data
|
jpayne@69
|
951 * in addition to locale (for example, collation can be
|
jpayne@69
|
952 * instantiated from a locale and from a rule set).
|
jpayne@69
|
953 * @stable ICU 2.1
|
jpayne@69
|
954 */
|
jpayne@69
|
955 void setToBogus();
|
jpayne@69
|
956
|
jpayne@69
|
957 /**
|
jpayne@69
|
958 * Gets the bogus state. Locale object can be bogus if it doesn't exist
|
jpayne@69
|
959 * @return FALSE if it is a real locale, TRUE if it is a bogus locale
|
jpayne@69
|
960 * @stable ICU 2.1
|
jpayne@69
|
961 */
|
jpayne@69
|
962 inline UBool isBogus(void) const;
|
jpayne@69
|
963
|
jpayne@69
|
964 /**
|
jpayne@69
|
965 * Returns a list of all installed locales.
|
jpayne@69
|
966 * @param count Receives the number of locales in the list.
|
jpayne@69
|
967 * @return A pointer to an array of Locale objects. This array is the list
|
jpayne@69
|
968 * of all locales with installed resource files. The called does NOT
|
jpayne@69
|
969 * get ownership of this list, and must NOT delete it.
|
jpayne@69
|
970 * @stable ICU 2.0
|
jpayne@69
|
971 */
|
jpayne@69
|
972 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
|
jpayne@69
|
973
|
jpayne@69
|
974 /**
|
jpayne@69
|
975 * Gets a list of all available 2-letter country codes defined in ISO 3166. This is a
|
jpayne@69
|
976 * pointer to an array of pointers to arrays of char. All of these pointers are
|
jpayne@69
|
977 * owned by ICU-- do not delete them, and do not write through them. The array is
|
jpayne@69
|
978 * terminated with a null pointer.
|
jpayne@69
|
979 * @return a list of all available country codes
|
jpayne@69
|
980 * @stable ICU 2.0
|
jpayne@69
|
981 */
|
jpayne@69
|
982 static const char* const* U_EXPORT2 getISOCountries();
|
jpayne@69
|
983
|
jpayne@69
|
984 /**
|
jpayne@69
|
985 * Gets a list of all available language codes defined in ISO 639. This is a pointer
|
jpayne@69
|
986 * to an array of pointers to arrays of char. All of these pointers are owned
|
jpayne@69
|
987 * by ICU-- do not delete them, and do not write through them. The array is
|
jpayne@69
|
988 * terminated with a null pointer.
|
jpayne@69
|
989 * @return a list of all available language codes
|
jpayne@69
|
990 * @stable ICU 2.0
|
jpayne@69
|
991 */
|
jpayne@69
|
992 static const char* const* U_EXPORT2 getISOLanguages();
|
jpayne@69
|
993
|
jpayne@69
|
994 /**
|
jpayne@69
|
995 * ICU "poor man's RTTI", returns a UClassID for this class.
|
jpayne@69
|
996 *
|
jpayne@69
|
997 * @stable ICU 2.2
|
jpayne@69
|
998 */
|
jpayne@69
|
999 static UClassID U_EXPORT2 getStaticClassID();
|
jpayne@69
|
1000
|
jpayne@69
|
1001 /**
|
jpayne@69
|
1002 * ICU "poor man's RTTI", returns a UClassID for the actual class.
|
jpayne@69
|
1003 *
|
jpayne@69
|
1004 * @stable ICU 2.2
|
jpayne@69
|
1005 */
|
jpayne@69
|
1006 virtual UClassID getDynamicClassID() const;
|
jpayne@69
|
1007
|
jpayne@69
|
1008 #ifndef U_HIDE_DRAFT_API
|
jpayne@69
|
1009 /**
|
jpayne@69
|
1010 * A Locale iterator interface similar to a Java Iterator<Locale>.
|
jpayne@69
|
1011 * @draft ICU 65
|
jpayne@69
|
1012 */
|
jpayne@69
|
1013 class U_COMMON_API Iterator /* not : public UObject because this is an interface/mixin class */ {
|
jpayne@69
|
1014 public:
|
jpayne@69
|
1015 /** @draft ICU 65 */
|
jpayne@69
|
1016 virtual ~Iterator();
|
jpayne@69
|
1017
|
jpayne@69
|
1018 /**
|
jpayne@69
|
1019 * @return TRUE if next() can be called again.
|
jpayne@69
|
1020 * @draft ICU 65
|
jpayne@69
|
1021 */
|
jpayne@69
|
1022 virtual UBool hasNext() const = 0;
|
jpayne@69
|
1023
|
jpayne@69
|
1024 /**
|
jpayne@69
|
1025 * @return the next locale.
|
jpayne@69
|
1026 * @draft ICU 65
|
jpayne@69
|
1027 */
|
jpayne@69
|
1028 virtual const Locale &next() = 0;
|
jpayne@69
|
1029 };
|
jpayne@69
|
1030
|
jpayne@69
|
1031 /**
|
jpayne@69
|
1032 * A generic Locale iterator implementation over Locale input iterators.
|
jpayne@69
|
1033 * @draft ICU 65
|
jpayne@69
|
1034 */
|
jpayne@69
|
1035 template<typename Iter>
|
jpayne@69
|
1036 class RangeIterator : public Iterator, public UMemory {
|
jpayne@69
|
1037 public:
|
jpayne@69
|
1038 /**
|
jpayne@69
|
1039 * Constructs an iterator from a begin/end range.
|
jpayne@69
|
1040 * Each of the iterator parameter values must be an
|
jpayne@69
|
1041 * input iterator whose value is convertible to const Locale &.
|
jpayne@69
|
1042 *
|
jpayne@69
|
1043 * @param begin Start of range.
|
jpayne@69
|
1044 * @param end Exclusive end of range.
|
jpayne@69
|
1045 * @draft ICU 65
|
jpayne@69
|
1046 */
|
jpayne@69
|
1047 RangeIterator(Iter begin, Iter end) : it_(begin), end_(end) {}
|
jpayne@69
|
1048
|
jpayne@69
|
1049 /**
|
jpayne@69
|
1050 * @return TRUE if next() can be called again.
|
jpayne@69
|
1051 * @draft ICU 65
|
jpayne@69
|
1052 */
|
jpayne@69
|
1053 UBool hasNext() const override { return it_ != end_; }
|
jpayne@69
|
1054
|
jpayne@69
|
1055 /**
|
jpayne@69
|
1056 * @return the next locale.
|
jpayne@69
|
1057 * @draft ICU 65
|
jpayne@69
|
1058 */
|
jpayne@69
|
1059 const Locale &next() override { return *it_++; }
|
jpayne@69
|
1060
|
jpayne@69
|
1061 private:
|
jpayne@69
|
1062 Iter it_;
|
jpayne@69
|
1063 const Iter end_;
|
jpayne@69
|
1064 };
|
jpayne@69
|
1065
|
jpayne@69
|
1066 /**
|
jpayne@69
|
1067 * A generic Locale iterator implementation over Locale input iterators.
|
jpayne@69
|
1068 * Calls the converter to convert each *begin to a const Locale &.
|
jpayne@69
|
1069 * @draft ICU 65
|
jpayne@69
|
1070 */
|
jpayne@69
|
1071 template<typename Iter, typename Conv>
|
jpayne@69
|
1072 class ConvertingIterator : public Iterator, public UMemory {
|
jpayne@69
|
1073 public:
|
jpayne@69
|
1074 /**
|
jpayne@69
|
1075 * Constructs an iterator from a begin/end range.
|
jpayne@69
|
1076 * Each of the iterator parameter values must be an
|
jpayne@69
|
1077 * input iterator whose value the converter converts to const Locale &.
|
jpayne@69
|
1078 *
|
jpayne@69
|
1079 * @param begin Start of range.
|
jpayne@69
|
1080 * @param end Exclusive end of range.
|
jpayne@69
|
1081 * @param converter Converter from *begin to const Locale & or compatible.
|
jpayne@69
|
1082 * @draft ICU 65
|
jpayne@69
|
1083 */
|
jpayne@69
|
1084 ConvertingIterator(Iter begin, Iter end, Conv converter) :
|
jpayne@69
|
1085 it_(begin), end_(end), converter_(converter) {}
|
jpayne@69
|
1086
|
jpayne@69
|
1087 /**
|
jpayne@69
|
1088 * @return TRUE if next() can be called again.
|
jpayne@69
|
1089 * @draft ICU 65
|
jpayne@69
|
1090 */
|
jpayne@69
|
1091 UBool hasNext() const override { return it_ != end_; }
|
jpayne@69
|
1092
|
jpayne@69
|
1093 /**
|
jpayne@69
|
1094 * @return the next locale.
|
jpayne@69
|
1095 * @draft ICU 65
|
jpayne@69
|
1096 */
|
jpayne@69
|
1097 const Locale &next() override { return converter_(*it_++); }
|
jpayne@69
|
1098
|
jpayne@69
|
1099 private:
|
jpayne@69
|
1100 Iter it_;
|
jpayne@69
|
1101 const Iter end_;
|
jpayne@69
|
1102 Conv converter_;
|
jpayne@69
|
1103 };
|
jpayne@69
|
1104 #endif // U_HIDE_DRAFT_API
|
jpayne@69
|
1105
|
jpayne@69
|
1106 protected: /* only protected for testing purposes. DO NOT USE. */
|
jpayne@69
|
1107 #ifndef U_HIDE_INTERNAL_API
|
jpayne@69
|
1108 /**
|
jpayne@69
|
1109 * Set this from a single POSIX style locale string.
|
jpayne@69
|
1110 * @internal
|
jpayne@69
|
1111 */
|
jpayne@69
|
1112 void setFromPOSIXID(const char *posixID);
|
jpayne@69
|
1113 #endif /* U_HIDE_INTERNAL_API */
|
jpayne@69
|
1114
|
jpayne@69
|
1115 private:
|
jpayne@69
|
1116 /**
|
jpayne@69
|
1117 * Initialize the locale object with a new name.
|
jpayne@69
|
1118 * Was deprecated - used in implementation - moved internal
|
jpayne@69
|
1119 *
|
jpayne@69
|
1120 * @param cLocaleID The new locale name.
|
jpayne@69
|
1121 * @param canonicalize whether to call uloc_canonicalize on cLocaleID
|
jpayne@69
|
1122 */
|
jpayne@69
|
1123 Locale& init(const char* cLocaleID, UBool canonicalize);
|
jpayne@69
|
1124
|
jpayne@69
|
1125 /*
|
jpayne@69
|
1126 * Internal constructor to allow construction of a locale object with
|
jpayne@69
|
1127 * NO side effects. (Default constructor tries to get
|
jpayne@69
|
1128 * the default locale.)
|
jpayne@69
|
1129 */
|
jpayne@69
|
1130 enum ELocaleType {
|
jpayne@69
|
1131 eBOGUS
|
jpayne@69
|
1132 };
|
jpayne@69
|
1133 Locale(ELocaleType);
|
jpayne@69
|
1134
|
jpayne@69
|
1135 /**
|
jpayne@69
|
1136 * Initialize the locale cache for commonly used locales
|
jpayne@69
|
1137 */
|
jpayne@69
|
1138 static Locale *getLocaleCache(void);
|
jpayne@69
|
1139
|
jpayne@69
|
1140 char language[ULOC_LANG_CAPACITY];
|
jpayne@69
|
1141 char script[ULOC_SCRIPT_CAPACITY];
|
jpayne@69
|
1142 char country[ULOC_COUNTRY_CAPACITY];
|
jpayne@69
|
1143 int32_t variantBegin;
|
jpayne@69
|
1144 char* fullName;
|
jpayne@69
|
1145 char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
|
jpayne@69
|
1146 // name without keywords
|
jpayne@69
|
1147 char* baseName;
|
jpayne@69
|
1148 void initBaseName(UErrorCode& status);
|
jpayne@69
|
1149
|
jpayne@69
|
1150 UBool fIsBogus;
|
jpayne@69
|
1151
|
jpayne@69
|
1152 static const Locale &getLocale(int locid);
|
jpayne@69
|
1153
|
jpayne@69
|
1154 /**
|
jpayne@69
|
1155 * A friend to allow the default locale to be set by either the C or C++ API.
|
jpayne@69
|
1156 * @internal (private)
|
jpayne@69
|
1157 */
|
jpayne@69
|
1158 friend Locale *locale_set_default_internal(const char *, UErrorCode& status);
|
jpayne@69
|
1159
|
jpayne@69
|
1160 /**
|
jpayne@69
|
1161 * @internal (private)
|
jpayne@69
|
1162 */
|
jpayne@69
|
1163 friend void U_CALLCONV locale_available_init();
|
jpayne@69
|
1164 };
|
jpayne@69
|
1165
|
jpayne@69
|
1166 inline UBool
|
jpayne@69
|
1167 Locale::operator!=(const Locale& other) const
|
jpayne@69
|
1168 {
|
jpayne@69
|
1169 return !operator==(other);
|
jpayne@69
|
1170 }
|
jpayne@69
|
1171
|
jpayne@69
|
1172 template<typename StringClass> inline StringClass
|
jpayne@69
|
1173 Locale::toLanguageTag(UErrorCode& status) const
|
jpayne@69
|
1174 {
|
jpayne@69
|
1175 StringClass result;
|
jpayne@69
|
1176 StringByteSink<StringClass> sink(&result);
|
jpayne@69
|
1177 toLanguageTag(sink, status);
|
jpayne@69
|
1178 return result;
|
jpayne@69
|
1179 }
|
jpayne@69
|
1180
|
jpayne@69
|
1181 inline const char *
|
jpayne@69
|
1182 Locale::getCountry() const
|
jpayne@69
|
1183 {
|
jpayne@69
|
1184 return country;
|
jpayne@69
|
1185 }
|
jpayne@69
|
1186
|
jpayne@69
|
1187 inline const char *
|
jpayne@69
|
1188 Locale::getLanguage() const
|
jpayne@69
|
1189 {
|
jpayne@69
|
1190 return language;
|
jpayne@69
|
1191 }
|
jpayne@69
|
1192
|
jpayne@69
|
1193 inline const char *
|
jpayne@69
|
1194 Locale::getScript() const
|
jpayne@69
|
1195 {
|
jpayne@69
|
1196 return script;
|
jpayne@69
|
1197 }
|
jpayne@69
|
1198
|
jpayne@69
|
1199 inline const char *
|
jpayne@69
|
1200 Locale::getVariant() const
|
jpayne@69
|
1201 {
|
jpayne@69
|
1202 return &baseName[variantBegin];
|
jpayne@69
|
1203 }
|
jpayne@69
|
1204
|
jpayne@69
|
1205 inline const char *
|
jpayne@69
|
1206 Locale::getName() const
|
jpayne@69
|
1207 {
|
jpayne@69
|
1208 return fullName;
|
jpayne@69
|
1209 }
|
jpayne@69
|
1210
|
jpayne@69
|
1211 template<typename StringClass, typename OutputIterator> inline void
|
jpayne@69
|
1212 Locale::getKeywords(OutputIterator iterator, UErrorCode& status) const
|
jpayne@69
|
1213 {
|
jpayne@69
|
1214 LocalPointer<StringEnumeration> keys(createKeywords(status));
|
jpayne@69
|
1215 if (U_FAILURE(status) || keys.isNull()) {
|
jpayne@69
|
1216 return;
|
jpayne@69
|
1217 }
|
jpayne@69
|
1218 for (;;) {
|
jpayne@69
|
1219 int32_t resultLength;
|
jpayne@69
|
1220 const char* buffer = keys->next(&resultLength, status);
|
jpayne@69
|
1221 if (U_FAILURE(status) || buffer == nullptr) {
|
jpayne@69
|
1222 return;
|
jpayne@69
|
1223 }
|
jpayne@69
|
1224 *iterator++ = StringClass(buffer, resultLength);
|
jpayne@69
|
1225 }
|
jpayne@69
|
1226 }
|
jpayne@69
|
1227
|
jpayne@69
|
1228 template<typename StringClass, typename OutputIterator> inline void
|
jpayne@69
|
1229 Locale::getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const
|
jpayne@69
|
1230 {
|
jpayne@69
|
1231 LocalPointer<StringEnumeration> keys(createUnicodeKeywords(status));
|
jpayne@69
|
1232 if (U_FAILURE(status) || keys.isNull()) {
|
jpayne@69
|
1233 return;
|
jpayne@69
|
1234 }
|
jpayne@69
|
1235 for (;;) {
|
jpayne@69
|
1236 int32_t resultLength;
|
jpayne@69
|
1237 const char* buffer = keys->next(&resultLength, status);
|
jpayne@69
|
1238 if (U_FAILURE(status) || buffer == nullptr) {
|
jpayne@69
|
1239 return;
|
jpayne@69
|
1240 }
|
jpayne@69
|
1241 *iterator++ = StringClass(buffer, resultLength);
|
jpayne@69
|
1242 }
|
jpayne@69
|
1243 }
|
jpayne@69
|
1244
|
jpayne@69
|
1245 template<typename StringClass> inline StringClass
|
jpayne@69
|
1246 Locale::getKeywordValue(StringPiece keywordName, UErrorCode& status) const
|
jpayne@69
|
1247 {
|
jpayne@69
|
1248 StringClass result;
|
jpayne@69
|
1249 StringByteSink<StringClass> sink(&result);
|
jpayne@69
|
1250 getKeywordValue(keywordName, sink, status);
|
jpayne@69
|
1251 return result;
|
jpayne@69
|
1252 }
|
jpayne@69
|
1253
|
jpayne@69
|
1254 template<typename StringClass> inline StringClass
|
jpayne@69
|
1255 Locale::getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const
|
jpayne@69
|
1256 {
|
jpayne@69
|
1257 StringClass result;
|
jpayne@69
|
1258 StringByteSink<StringClass> sink(&result);
|
jpayne@69
|
1259 getUnicodeKeywordValue(keywordName, sink, status);
|
jpayne@69
|
1260 return result;
|
jpayne@69
|
1261 }
|
jpayne@69
|
1262
|
jpayne@69
|
1263 inline UBool
|
jpayne@69
|
1264 Locale::isBogus(void) const {
|
jpayne@69
|
1265 return fIsBogus;
|
jpayne@69
|
1266 }
|
jpayne@69
|
1267
|
jpayne@69
|
1268 U_NAMESPACE_END
|
jpayne@69
|
1269
|
jpayne@69
|
1270 #endif /* U_SHOW_CPLUSPLUS_API */
|
jpayne@69
|
1271
|
jpayne@69
|
1272 #endif
|