ulocimp.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 2004-2016, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. */
  9. #ifndef ULOCIMP_H
  10. #define ULOCIMP_H
  11. #include "unicode/bytestream.h"
  12. #include "unicode/uloc.h"
  13. /**
  14. * Create an iterator over the specified keywords list
  15. * @param keywordList double-null terminated list. Will be copied.
  16. * @param keywordListSize size in bytes of keywordList
  17. * @param status err code
  18. * @return enumeration (owned by caller) of the keyword list.
  19. * @internal ICU 3.0
  20. */
  21. U_CAPI UEnumeration* U_EXPORT2
  22. uloc_openKeywordList(const char *keywordList, int32_t keywordListSize, UErrorCode* status);
  23. /**
  24. * Look up a resource bundle table item with fallback on the table level.
  25. * This is accessible so it can be called by C++ code.
  26. */
  27. U_CAPI const UChar * U_EXPORT2
  28. uloc_getTableStringWithFallback(
  29. const char *path,
  30. const char *locale,
  31. const char *tableKey,
  32. const char *subTableKey,
  33. const char *itemKey,
  34. int32_t *pLength,
  35. UErrorCode *pErrorCode);
  36. /*returns TRUE if a is an ID separator FALSE otherwise*/
  37. #define _isIDSeparator(a) (a == '_' || a == '-')
  38. U_CFUNC const char*
  39. uloc_getCurrentCountryID(const char* oldID);
  40. U_CFUNC const char*
  41. uloc_getCurrentLanguageID(const char* oldID);
  42. U_CFUNC int32_t
  43. ulocimp_getLanguage(const char *localeID,
  44. char *language, int32_t languageCapacity,
  45. const char **pEnd);
  46. U_CFUNC int32_t
  47. ulocimp_getScript(const char *localeID,
  48. char *script, int32_t scriptCapacity,
  49. const char **pEnd);
  50. U_CFUNC int32_t
  51. ulocimp_getCountry(const char *localeID,
  52. char *country, int32_t countryCapacity,
  53. const char **pEnd);
  54. U_STABLE void U_EXPORT2
  55. ulocimp_getName(const char* localeID,
  56. icu::ByteSink& sink,
  57. UErrorCode* err);
  58. U_STABLE void U_EXPORT2
  59. ulocimp_getBaseName(const char* localeID,
  60. icu::ByteSink& sink,
  61. UErrorCode* err);
  62. U_STABLE void U_EXPORT2
  63. ulocimp_canonicalize(const char* localeID,
  64. icu::ByteSink& sink,
  65. UErrorCode* err);
  66. /**
  67. * Writes a well-formed language tag for this locale ID.
  68. *
  69. * **Note**: When `strict` is FALSE, any locale fields which do not satisfy the
  70. * BCP47 syntax requirement will be omitted from the result. When `strict` is
  71. * TRUE, this function sets U_ILLEGAL_ARGUMENT_ERROR to the `err` if any locale
  72. * fields do not satisfy the BCP47 syntax requirement.
  73. *
  74. * @param localeID the input locale ID
  75. * @param sink the output sink receiving the BCP47 language
  76. * tag for this Locale.
  77. * @param strict boolean value indicating if the function returns
  78. * an error for an ill-formed input locale ID.
  79. * @param err error information if receiving the language
  80. * tag failed.
  81. * @return The length of the BCP47 language tag.
  82. *
  83. * @internal ICU 64
  84. */
  85. U_STABLE void U_EXPORT2
  86. ulocimp_toLanguageTag(const char* localeID,
  87. icu::ByteSink& sink,
  88. UBool strict,
  89. UErrorCode* err);
  90. /**
  91. * Returns a locale ID for the specified BCP47 language tag string.
  92. * If the specified language tag contains any ill-formed subtags,
  93. * the first such subtag and all following subtags are ignored.
  94. * <p>
  95. * This implements the 'Language-Tag' production of BCP47, and so
  96. * supports grandfathered (regular and irregular) as well as private
  97. * use language tags. Private use tags are represented as 'x-whatever',
  98. * and grandfathered tags are converted to their canonical replacements
  99. * where they exist. Note that a few grandfathered tags have no modern
  100. * replacement, these will be converted using the fallback described in
  101. * the first paragraph, so some information might be lost.
  102. * @param langtag the input BCP47 language tag.
  103. * @param tagLen the length of langtag, or -1 to call uprv_strlen().
  104. * @param sink the output sink receiving a locale ID for the
  105. * specified BCP47 language tag.
  106. * @param parsedLength if not NULL, successfully parsed length
  107. * for the input language tag is set.
  108. * @param err error information if receiving the locald ID
  109. * failed.
  110. * @internal ICU 63
  111. */
  112. U_CAPI void U_EXPORT2
  113. ulocimp_forLanguageTag(const char* langtag,
  114. int32_t tagLen,
  115. icu::ByteSink& sink,
  116. int32_t* parsedLength,
  117. UErrorCode* err);
  118. /**
  119. * Get the region to use for supplemental data lookup. Uses
  120. * (1) any region specified by locale tag "rg"; if none then
  121. * (2) any unicode_region_tag in the locale ID; if none then
  122. * (3) if inferRegion is TRUE, the region suggested by
  123. * getLikelySubtags on the localeID.
  124. * If no region is found, returns length 0.
  125. *
  126. * @param localeID
  127. * The complete locale ID (with keywords) from which
  128. * to get the region to use for supplemental data.
  129. * @param inferRegion
  130. * If TRUE, will try to infer region from localeID if
  131. * no other region is found.
  132. * @param region
  133. * Buffer in which to put the region ID found; should
  134. * have a capacity at least ULOC_COUNTRY_CAPACITY.
  135. * @param regionCapacity
  136. * The actual capacity of the region buffer.
  137. * @param status
  138. * Pointer to in/out UErrorCode value for latest status.
  139. * @return
  140. * The length of any region code found, or 0 if none.
  141. * @internal ICU 57
  142. */
  143. U_CAPI int32_t U_EXPORT2
  144. ulocimp_getRegionForSupplementalData(const char *localeID, UBool inferRegion,
  145. char *region, int32_t regionCapacity, UErrorCode* status);
  146. /**
  147. * Add the likely subtags for a provided locale ID, per the algorithm described
  148. * in the following CLDR technical report:
  149. *
  150. * http://www.unicode.org/reports/tr35/#Likely_Subtags
  151. *
  152. * If localeID is already in the maximal form, or there is no data available
  153. * for maximization, it will be copied to the output buffer. For example,
  154. * "und-Zzzz" cannot be maximized, since there is no reasonable maximization.
  155. *
  156. * Examples:
  157. *
  158. * "en" maximizes to "en_Latn_US"
  159. *
  160. * "de" maximizes to "de_Latn_US"
  161. *
  162. * "sr" maximizes to "sr_Cyrl_RS"
  163. *
  164. * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.)
  165. *
  166. * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.)
  167. *
  168. * @param localeID The locale to maximize
  169. * @param sink The output sink receiving the maximized locale
  170. * @param err Error information if maximizing the locale failed. If the length
  171. * of the localeID and the null-terminator is greater than the maximum allowed size,
  172. * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR.
  173. * @internal ICU 64
  174. */
  175. U_STABLE void U_EXPORT2
  176. ulocimp_addLikelySubtags(const char* localeID,
  177. icu::ByteSink& sink,
  178. UErrorCode* err);
  179. /**
  180. * Minimize the subtags for a provided locale ID, per the algorithm described
  181. * in the following CLDR technical report:
  182. *
  183. * http://www.unicode.org/reports/tr35/#Likely_Subtags
  184. *
  185. * If localeID is already in the minimal form, or there is no data available
  186. * for minimization, it will be copied to the output buffer. Since the
  187. * minimization algorithm relies on proper maximization, see the comments
  188. * for ulocimp_addLikelySubtags for reasons why there might not be any data.
  189. *
  190. * Examples:
  191. *
  192. * "en_Latn_US" minimizes to "en"
  193. *
  194. * "de_Latn_US" minimizes to "de"
  195. *
  196. * "sr_Cyrl_RS" minimizes to "sr"
  197. *
  198. * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the
  199. * script, and minimizing to "zh" would imply "zh_Hans_CN".)
  200. *
  201. * @param localeID The locale to minimize
  202. * @param sink The output sink receiving the maximized locale
  203. * @param err Error information if minimizing the locale failed. If the length
  204. * of the localeID and the null-terminator is greater than the maximum allowed size,
  205. * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR.
  206. * @internal ICU 64
  207. */
  208. U_STABLE void U_EXPORT2
  209. ulocimp_minimizeSubtags(const char* localeID,
  210. icu::ByteSink& sink,
  211. UErrorCode* err);
  212. U_CAPI const char * U_EXPORT2
  213. locale_getKeywordsStart(const char *localeID);
  214. U_CFUNC UBool
  215. ultag_isExtensionSubtags(const char* s, int32_t len);
  216. U_CFUNC UBool
  217. ultag_isLanguageSubtag(const char* s, int32_t len);
  218. U_CFUNC UBool
  219. ultag_isPrivateuseValueSubtags(const char* s, int32_t len);
  220. U_CFUNC UBool
  221. ultag_isRegionSubtag(const char* s, int32_t len);
  222. U_CFUNC UBool
  223. ultag_isScriptSubtag(const char* s, int32_t len);
  224. U_CFUNC UBool
  225. ultag_isTransformedExtensionSubtags(const char* s, int32_t len);
  226. U_CFUNC UBool
  227. ultag_isUnicodeExtensionSubtags(const char* s, int32_t len);
  228. U_CFUNC UBool
  229. ultag_isUnicodeLocaleAttribute(const char* s, int32_t len);
  230. U_CFUNC UBool
  231. ultag_isUnicodeLocaleAttributes(const char* s, int32_t len);
  232. U_CFUNC UBool
  233. ultag_isUnicodeLocaleKey(const char* s, int32_t len);
  234. U_CFUNC UBool
  235. ultag_isUnicodeLocaleType(const char* s, int32_t len);
  236. U_CFUNC UBool
  237. ultag_isVariantSubtags(const char* s, int32_t len);
  238. U_CFUNC const char*
  239. ulocimp_toBcpKey(const char* key);
  240. U_CFUNC const char*
  241. ulocimp_toLegacyKey(const char* key);
  242. U_CFUNC const char*
  243. ulocimp_toBcpType(const char* key, const char* type, UBool* isKnownKey, UBool* isSpecialType);
  244. U_CFUNC const char*
  245. ulocimp_toLegacyType(const char* key, const char* type, UBool* isKnownKey, UBool* isSpecialType);
  246. #endif