locid.h 48 KB

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