ulocale.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // © 2023 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. #ifndef ULOCALE_H
  4. #define ULOCALE_H
  5. #include "unicode/localpointer.h"
  6. #include "unicode/uenum.h"
  7. #include "unicode/utypes.h"
  8. /**
  9. * \file
  10. * \brief C API: Locale ID functionality similar to C++ class Locale
  11. */
  12. /**
  13. * Opaque C service object type for the locale API
  14. * @stable ICU 74
  15. */
  16. struct ULocale;
  17. /**
  18. * C typedef for struct ULocale.
  19. * @stable ICU 74
  20. */
  21. typedef struct ULocale ULocale;
  22. /**
  23. * Constructs an ULocale from the locale ID.
  24. * The created ULocale should be destroyed by calling
  25. * ulocale_close();
  26. * @param localeID the locale, a const char * pointer (need not be terminated when
  27. * the length is non-negative)
  28. * @param length the length of the locale; if negative, then the locale need to be
  29. * null terminated.
  30. * @param err the error code
  31. * @return the locale.
  32. *
  33. * @stable ICU 74
  34. */
  35. U_CAPI ULocale* U_EXPORT2
  36. ulocale_openForLocaleID(const char* localeID, int32_t length, UErrorCode* err);
  37. /**
  38. * Constructs an ULocale from the provided IETF BCP 47 language tag.
  39. * The created ULocale should be destroyed by calling
  40. * ulocale_close();
  41. * @param tag the language tag, defined as IETF BCP 47 language tag, const
  42. * char* pointer (need not be terminated when the length is non-negative)
  43. * @param length the length of the tag; if negative, then the tag need to be
  44. * null terminated.
  45. * @param err the error code
  46. * @return the locale.
  47. *
  48. * @stable ICU 74
  49. */
  50. U_CAPI ULocale* U_EXPORT2
  51. ulocale_openForLanguageTag(const char* tag, int32_t length, UErrorCode* err);
  52. /**
  53. * Close the locale and destroy it's internal states.
  54. *
  55. * @param locale the locale
  56. * @stable ICU 74
  57. */
  58. U_CAPI void U_EXPORT2
  59. ulocale_close(ULocale* locale);
  60. /**
  61. * Returns the locale's ISO-639 language code.
  62. *
  63. * @param locale the locale
  64. * @return the language code of the locale.
  65. * @stable ICU 74
  66. */
  67. U_CAPI const char* U_EXPORT2
  68. ulocale_getLanguage(const ULocale* locale);
  69. /**
  70. * Returns the locale's ISO-15924 abbreviation script code.
  71. *
  72. * @param locale the locale
  73. * @return A pointer to the script.
  74. * @stable ICU 74
  75. */
  76. U_CAPI const char* U_EXPORT2
  77. ulocale_getScript(const ULocale* locale);
  78. /**
  79. * Returns the locale's ISO-3166 region code.
  80. *
  81. * @param locale the locale
  82. * @return A pointer to the region.
  83. * @stable ICU 74
  84. */
  85. U_CAPI const char* U_EXPORT2
  86. ulocale_getRegion(const ULocale* locale);
  87. /**
  88. * Returns the locale's variant code.
  89. *
  90. * @param locale the locale
  91. * @return A pointer to the variant.
  92. * @stable ICU 74
  93. */
  94. U_CAPI const char* U_EXPORT2
  95. ulocale_getVariant(const ULocale* locale);
  96. /**
  97. * Returns the programmatic name of the entire locale, with the language,
  98. * country and variant separated by underbars. If a field is missing, up
  99. * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
  100. * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
  101. *
  102. * @param locale the locale
  103. * @return A pointer to "name".
  104. * @stable ICU 74
  105. */
  106. U_CAPI const char* U_EXPORT2
  107. ulocale_getLocaleID(const ULocale* locale);
  108. /**
  109. * Returns the programmatic name of the entire locale as ulocale_getLocaleID()
  110. * would return, but without keywords.
  111. *
  112. * @param locale the locale
  113. * @return A pointer to "base name".
  114. * @stable ICU 74
  115. */
  116. U_CAPI const char* U_EXPORT2
  117. ulocale_getBaseName(const ULocale* locale);
  118. /**
  119. * Gets the bogus state. Locale object can be bogus if it doesn't exist
  120. *
  121. * @param locale the locale
  122. * @return false if it is a real locale, true if it is a bogus locale
  123. * @stable ICU 74
  124. */
  125. U_CAPI bool U_EXPORT2
  126. ulocale_isBogus(const ULocale* locale);
  127. /**
  128. * Gets the list of keywords for the specified locale.
  129. *
  130. * @param locale the locale
  131. * @param err the error code
  132. * @return pointer to UEnumeration, or nullptr if there are no keywords.
  133. * Client must call uenum_close() to dispose the returned value.
  134. * @stable ICU 74
  135. */
  136. U_CAPI UEnumeration* U_EXPORT2
  137. ulocale_getKeywords(const ULocale* locale, UErrorCode *err);
  138. /**
  139. * Gets the list of unicode keywords for the specified locale.
  140. *
  141. * @param locale the locale
  142. * @param err the error code
  143. * @return pointer to UEnumeration, or nullptr if there are no keywords.
  144. * Client must call uenum_close() to dispose the returned value.
  145. * @stable ICU 74
  146. */
  147. U_CAPI UEnumeration* U_EXPORT2
  148. ulocale_getUnicodeKeywords(const ULocale* locale, UErrorCode *err);
  149. /**
  150. * Gets the value for a keyword.
  151. *
  152. * This uses legacy keyword=value pairs, like "collation=phonebook".
  153. *
  154. * @param locale the locale
  155. * @param keyword the keyword, a const char * pointer (need not be
  156. * terminated when the length is non-negative)
  157. * @param keywordLength the length of the keyword; if negative, then the
  158. * keyword need to be null terminated.
  159. * @param valueBuffer The buffer to receive the value.
  160. * @param valueBufferCapacity The capacity of receiving valueBuffer.
  161. * @param err the error code
  162. * @stable ICU 74
  163. */
  164. U_CAPI int32_t U_EXPORT2
  165. ulocale_getKeywordValue(
  166. const ULocale* locale, const char* keyword, int32_t keywordLength,
  167. char* valueBuffer, int32_t valueBufferCapacity, UErrorCode *err);
  168. /**
  169. * Gets the Unicode value for a Unicode keyword.
  170. *
  171. * This uses Unicode key-value pairs, like "co-phonebk".
  172. *
  173. * @param locale the locale
  174. * @param keyword the Unicode keyword, a const char * pointer (need not be
  175. * terminated when the length is non-negative)
  176. * @param keywordLength the length of the Unicode keyword; if negative,
  177. * then the keyword need to be null terminated.
  178. * @param valueBuffer The buffer to receive the Unicode value.
  179. * @param valueBufferCapacity The capacity of receiving valueBuffer.
  180. * @param err the error code
  181. * @stable ICU 74
  182. */
  183. U_CAPI int32_t U_EXPORT2
  184. ulocale_getUnicodeKeywordValue(
  185. const ULocale* locale, const char* keyword, int32_t keywordLength,
  186. char* valueBuffer, int32_t valueBufferCapacity, UErrorCode *err);
  187. #if U_SHOW_CPLUSPLUS_API
  188. U_NAMESPACE_BEGIN
  189. /**
  190. * \class LocalULocalePointer
  191. * "Smart pointer" class, closes a ULocale via ulocale_close().
  192. * For most methods see the LocalPointerBase base class.
  193. *
  194. * @see LocalPointerBase
  195. * @see LocalPointer
  196. * @stable ICU 74
  197. */
  198. U_DEFINE_LOCAL_OPEN_POINTER(LocalULocalePointer, ULocale, ulocale_close);
  199. U_NAMESPACE_END
  200. #endif /* U_SHOW_CPLUSPLUS_API */
  201. #endif /*_ULOCALE */