ulocale.h 6.4 KB

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