c_locale.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. /*
  19. * It is impossible to write the C++ locale library in terms of locales
  20. * as defined in the C standard. Instead, we write the C++ locale and I/O
  21. * library in terms of a low level C-like interface. This file defines
  22. * that interface.
  23. *
  24. * The low-level locale interface can't be written portably; there
  25. * must be a version of it for each platform that the C++ library
  26. * is ported to. On many systems this interface may be a thin wrapper
  27. * for existing functionality.
  28. */
  29. #ifndef _STLP_C_LOCALE_IMPL_H
  30. #define _STLP_C_LOCALE_IMPL_H
  31. #include "stlport_prefix.h"
  32. #include <wchar.h> /* for mbstate_t */
  33. #include <stl/c_locale.h>
  34. struct _Locale_name_hint;
  35. #if defined (_GNU_SOURCE) && defined (__GLIBC__) && \
  36. ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
  37. # define _STLP_USE_GLIBC2_LOCALIZATION
  38. # include <nl_types.h>
  39. typedef nl_catd nl_catd_type;
  40. #else
  41. typedef int nl_catd_type;
  42. #endif
  43. /*
  44. * A number: the maximum length of a simple locale name.
  45. * (i.e. a name like like en_US, as opposed to a name like
  46. * en_US/de_AT/de_AT/es_MX/en_US/en_US) */
  47. #define _Locale_MAX_SIMPLE_NAME 256
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /*
  52. * Typedefs:
  53. */
  54. typedef unsigned short int _Locale_mask_t;
  55. /* Function called during STLport library load phase. Might contain any
  56. * code necessary to the platform localization layer.
  57. */
  58. void _Locale_init(void);
  59. /* Function called during STLport library unload. Might contain any
  60. * code necessary to the platform localization layer.
  61. */
  62. void _Locale_final(void);
  63. /* Create a category of the locale with the given name.
  64. *
  65. * The char* argument is a simple (not a composite) locale name, which may
  66. * neither be an empty string nor a null pointer.
  67. *
  68. * These functions return NULL to indicate failure. Failure reason should be reported
  69. * using the __err_code pointer.
  70. */
  71. struct _Locale_ctype* _Locale_ctype_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
  72. struct _Locale_codecvt* _Locale_codecvt_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
  73. struct _Locale_numeric* _Locale_numeric_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
  74. struct _Locale_time* _Locale_time_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
  75. struct _Locale_collate* _Locale_collate_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
  76. struct _Locale_monetary* _Locale_monetary_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
  77. struct _Locale_messages* _Locale_messages_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
  78. /* Give error reason on failure of one of the _Locale_*_create functions. Available
  79. * reasons are:
  80. * 0: No specific error reason has been reported.
  81. * 1: No platform support for the given facet.
  82. * 2: Unknown locale name
  83. * 3: No platform API for localization support.
  84. * 4: No more memory
  85. */
  86. #define _STLP_LOC_UNDEFINED 0
  87. #define _STLP_LOC_UNSUPPORTED_FACET_CATEGORY 1
  88. #define _STLP_LOC_UNKNOWN_NAME 2
  89. #define _STLP_LOC_NO_PLATFORM_SUPPORT 3
  90. #define _STLP_LOC_NO_MEMORY 4
  91. /* Release a category of a locale
  92. *
  93. * These functions are used to release a category acquired with the
  94. * according _Locale_*_create() functions.
  95. */
  96. void _Locale_ctype_destroy(struct _Locale_ctype *);
  97. void _Locale_codecvt_destroy(struct _Locale_codecvt *);
  98. void _Locale_numeric_destroy(struct _Locale_numeric *);
  99. void _Locale_time_destroy(struct _Locale_time *);
  100. void _Locale_collate_destroy(struct _Locale_collate *);
  101. void _Locale_monetary_destroy(struct _Locale_monetary *);
  102. void _Locale_messages_destroy(struct _Locale_messages *);
  103. /*
  104. * Returns the name of the user's default locale in each
  105. * category, as a null-terminated string. A NULL value
  106. * means the default "C" locale.
  107. */
  108. const char * _Locale_ctype_default(char * __buf);
  109. const char * _Locale_numeric_default(char * __buf);
  110. const char * _Locale_time_default(char * __buf);
  111. const char * _Locale_collate_default(char * __buf);
  112. const char * _Locale_monetary_default(char * __buf);
  113. const char * _Locale_messages_default(char * __buf);
  114. /* Retrieve the name of the given category
  115. *
  116. * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME
  117. * characters. These functions store the name, as a null-terminated
  118. * string, in __buf. This function can't fail, at worst name is truncated.
  119. */
  120. char const* _Locale_ctype_name(const struct _Locale_ctype *, char* __buf);
  121. char const* _Locale_codecvt_name(const struct _Locale_codecvt *, char* __buf);
  122. char const* _Locale_numeric_name(const struct _Locale_numeric *, char* __buf);
  123. char const* _Locale_time_name(const struct _Locale_time *, char* __buf);
  124. char const* _Locale_collate_name(const struct _Locale_collate *, char* __buf);
  125. char const* _Locale_monetary_name(const struct _Locale_monetary *, char* __buf);
  126. char const* _Locale_messages_name(const struct _Locale_messages *, char* __buf);
  127. /*
  128. * cname is a (possibly composite) locale name---i.e. a name that can
  129. * be passed to setlocale. __buf points to an array large enough to
  130. * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these
  131. * functions extracts the name of a single category, stores it in buf
  132. * as a null-terminated string, and returns buf.
  133. */
  134. char const* _Locale_extract_ctype_name(const char *cname, char *__buf,
  135. struct _Locale_name_hint* __hint, int *__err_code);
  136. char const* _Locale_extract_numeric_name(const char *cname, char *__buf,
  137. struct _Locale_name_hint* __hint, int *__err_code);
  138. char const* _Locale_extract_time_name(const char *cname, char *__buf,
  139. struct _Locale_name_hint* __hint, int *__err_code);
  140. char const* _Locale_extract_collate_name(const char *cname, char *__buf,
  141. struct _Locale_name_hint* __hint, int *__err_code);
  142. char const* _Locale_extract_monetary_name(const char *cname, char *__buf,
  143. struct _Locale_name_hint* __hint, int *__err_code);
  144. char const* _Locale_extract_messages_name(const char *cname, char *__buf,
  145. struct _Locale_name_hint* __hint, int *__err_code);
  146. /* Functions to improve locale creation process. For some locale API (Win32)
  147. * you need to find a locale identification from the name which can be a
  148. * rather expensive operation especially if you do so for all facets of a
  149. * locale. Those functions can be used to extract from a API dependent facet
  150. * struct the information necessary to skip this lookup process for other
  151. * facets creation. If not supported those function should return NULL.
  152. */
  153. struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*);
  154. struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*);
  155. struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*);
  156. struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*);
  157. struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*);
  158. struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*);
  159. /*
  160. * FUNCTIONS THAT USE CTYPE
  161. */
  162. /*
  163. * Narrow character functions:
  164. */
  165. /*
  166. * Returns a pointer to the beginning of the ctype table. The table is
  167. * at least 257 bytes long; if p is the pointer returned by this
  168. * function, then p[c] is valid if c is EOF or if p is any value of
  169. * type unsigned char.
  170. */
  171. const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *);
  172. /*
  173. * c is either EOF, or an unsigned char value.
  174. */
  175. int _Locale_toupper(struct _Locale_ctype *, int /* c */);
  176. int _Locale_tolower(struct _Locale_ctype *, int /* c */);
  177. #ifndef _STLP_NO_WCHAR_T
  178. /*
  179. * Wide character functions:
  180. */
  181. _Locale_mask_t _WLocale_ctype(struct _Locale_ctype *, wint_t, _Locale_mask_t);
  182. wint_t _WLocale_tolower(struct _Locale_ctype *, wint_t);
  183. wint_t _WLocale_toupper(struct _Locale_ctype *, wint_t);
  184. /*
  185. * Multibyte functions:
  186. */
  187. /*
  188. * Returns the number of bytes of the longest allowed multibyte
  189. * character in the current encoding.
  190. */
  191. int _WLocale_mb_cur_max(struct _Locale_codecvt *);
  192. /*
  193. * Returns the number of bytes of the shortest allowed multibyte
  194. * character in the current encoding.
  195. */
  196. int _WLocale_mb_cur_min(struct _Locale_codecvt *);
  197. /*
  198. * Returns 1 if the current multibyte encoding is stateless
  199. * and does not require the use of an mbstate_t value.
  200. */
  201. int _WLocale_is_stateless(struct _Locale_codecvt *);
  202. /*
  203. * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only
  204. * important difference is that mbrtowc treats null wide characters
  205. * as special, and we don't. Specifically: examines the characters
  206. * in [from, from + n), extracts a single wide character, and stores
  207. * it in *to. Modifies shift_state if appropriate. The return value,
  208. * which is always positive, is the number of characters extracted from
  209. * the input sequence. Return value is (size_t) -1 if there was an
  210. * encoding error in the input sequence, and (size_t) -2 if
  211. * [from, from + n) is correct but not complete. None of the pointer
  212. * arguments may be null pointers.
  213. */
  214. size_t _WLocale_mbtowc(struct _Locale_codecvt *,
  215. wchar_t * /* to */,
  216. const char * /* from */, size_t /* n */,
  217. mbstate_t *);
  218. /*
  219. * Again, very similar to wcrtomb. The differences are that (1) it
  220. * doesn't treat null characters as special; and (2) it stores at most
  221. * n characters. Converts c to a multibyte sequence, stores that
  222. * sequence in the array 'to', and returns the length of the sequence.
  223. * Modifies shift_state if appropriate. The return value is (size_t) -1
  224. * if c is not a valid wide character, and (size_t) -2 if the length of
  225. * the multibyte character sequence is greater than n.
  226. */
  227. size_t _WLocale_wctomb(struct _Locale_codecvt *,
  228. char *, size_t,
  229. const wchar_t,
  230. mbstate_t *);
  231. /*
  232. * Inserts whatever characters are necessary to restore st to an
  233. * initial shift state. Sets *next to buf + m, where m is the number
  234. * of characters inserted. (0 <= m <= n.) Returns m to indicate
  235. * success, (size_t) -1 to indicate error, (size_t) -2 to indicate
  236. * partial success (more than n characters needed). For success or partial
  237. * success, sets *next to buf + m.
  238. */
  239. size_t _WLocale_unshift(struct _Locale_codecvt *,
  240. mbstate_t *,
  241. char *, size_t, char **);
  242. #endif
  243. /*
  244. * FUNCTIONS THAT USE COLLATE
  245. */
  246. /*
  247. * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither
  248. * sequence is assumed to be null-terminated, and null characters
  249. * aren't special. If the two sequences are the same up through
  250. * min(n1, n2), then the sequence that compares less is whichever one
  251. * is shorter.
  252. */
  253. int _Locale_strcmp(struct _Locale_collate *,
  254. const char * /* s1 */, size_t /* n1 */,
  255. const char * /* s2 */, size_t /* n2 */);
  256. #ifndef _STLP_NO_WCHAR_T
  257. int _WLocale_strcmp(struct _Locale_collate *,
  258. const wchar_t * /* s1 */, size_t /* n1 */,
  259. const wchar_t * /* s2 */, size_t /* n2 */);
  260. #endif
  261. /*
  262. * Creates a transformed version of the string [s2, s2 + n2). The
  263. * string may contain embedded null characters; nulls aren't special.
  264. * The transformed string begins at s1, and contains at most n1
  265. * characters. The return value is the length of the transformed
  266. * string. If the return value is greater than n1 then this is an
  267. * error condition: it indicates that there wasn't enough space. In
  268. * that case, the contents of [s1, s1 + n1) is unspecified.
  269. */
  270. size_t _Locale_strxfrm(struct _Locale_collate *,
  271. char * /* s1 */, size_t /* n1 */,
  272. const char * /* s2 */, size_t /* n2 */);
  273. #ifndef _STLP_NO_WCHAR_T
  274. size_t _WLocale_strxfrm(struct _Locale_collate *,
  275. wchar_t * /* s1 */, size_t /* n1 */,
  276. const wchar_t * /* s2 */, size_t /* n2 */);
  277. #endif
  278. /*
  279. * FUNCTIONS THAT USE NUMERIC
  280. */
  281. /*
  282. * Equivalent to the first three fields in struct lconv. (C standard,
  283. * section 7.4.)
  284. */
  285. char _Locale_decimal_point(struct _Locale_numeric *);
  286. char _Locale_thousands_sep(struct _Locale_numeric *);
  287. const char * _Locale_grouping(struct _Locale_numeric *);
  288. #ifndef _STLP_NO_WCHAR_T
  289. wchar_t _WLocale_decimal_point(struct _Locale_numeric *);
  290. wchar_t _WLocale_thousands_sep(struct _Locale_numeric *);
  291. #endif
  292. /*
  293. * Return "true" and "false" in English locales, and something
  294. * appropriate in non-English locales.
  295. */
  296. const char * _Locale_true(struct _Locale_numeric *);
  297. const char * _Locale_false(struct _Locale_numeric *);
  298. #ifndef _STLP_NO_WCHAR_T
  299. const wchar_t * _WLocale_true(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */);
  300. const wchar_t * _WLocale_false(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */);
  301. #endif
  302. /*
  303. * FUNCTIONS THAT USE MONETARY
  304. */
  305. /*
  306. * Return the obvious fields of struct lconv.
  307. */
  308. const char * _Locale_int_curr_symbol(struct _Locale_monetary *);
  309. const char * _Locale_currency_symbol(struct _Locale_monetary *);
  310. char _Locale_mon_decimal_point(struct _Locale_monetary *);
  311. char _Locale_mon_thousands_sep(struct _Locale_monetary *);
  312. const char * _Locale_mon_grouping(struct _Locale_monetary *);
  313. const char * _Locale_positive_sign(struct _Locale_monetary *);
  314. const char * _Locale_negative_sign(struct _Locale_monetary *);
  315. char _Locale_int_frac_digits(struct _Locale_monetary *);
  316. char _Locale_frac_digits(struct _Locale_monetary *);
  317. int _Locale_p_cs_precedes(struct _Locale_monetary *);
  318. int _Locale_p_sep_by_space(struct _Locale_monetary *);
  319. int _Locale_p_sign_posn(struct _Locale_monetary *);
  320. int _Locale_n_cs_precedes(struct _Locale_monetary *);
  321. int _Locale_n_sep_by_space(struct _Locale_monetary *);
  322. int _Locale_n_sign_posn(struct _Locale_monetary *);
  323. #ifndef _STLP_NO_WCHAR_T
  324. const wchar_t * _WLocale_int_curr_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
  325. const wchar_t * _WLocale_currency_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
  326. wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary *);
  327. wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary *);
  328. const wchar_t * _WLocale_positive_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
  329. const wchar_t * _WLocale_negative_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
  330. #endif
  331. /*
  332. * FUNCTIONS THAT USE TIME
  333. */
  334. /*
  335. * month is in the range [0, 12).
  336. */
  337. const char * _Locale_full_monthname(struct _Locale_time *, int /* month */);
  338. const char * _Locale_abbrev_monthname(struct _Locale_time *, int /* month */);
  339. #ifndef _STLP_NO_WCHAR_T
  340. const wchar_t * _WLocale_full_monthname(struct _Locale_time *, int /* month */,
  341. wchar_t* /* buf */, size_t /* bufSize */);
  342. const wchar_t * _WLocale_abbrev_monthname(struct _Locale_time *, int /* month */,
  343. wchar_t* /* buf */, size_t /* bufSize */);
  344. #endif
  345. /*
  346. * day is in the range [0, 7). Sunday is 0.
  347. */
  348. const char * _Locale_full_dayofweek(struct _Locale_time *, int /* day */);
  349. const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int /* day */);
  350. #ifndef _STLP_NO_WCHAR_T
  351. const wchar_t * _WLocale_full_dayofweek(struct _Locale_time *, int /* day */,
  352. wchar_t* /* buf */, size_t /* bufSize */);
  353. const wchar_t * _WLocale_abbrev_dayofweek(struct _Locale_time *, int /* day */,
  354. wchar_t* /* buf */, size_t /* bufSize */);
  355. #endif
  356. const char * _Locale_d_t_fmt(struct _Locale_time *);
  357. const char * _Locale_d_fmt(struct _Locale_time *);
  358. const char * _Locale_t_fmt(struct _Locale_time *);
  359. const char * _Locale_long_d_t_fmt(struct _Locale_time*);
  360. const char * _Locale_long_d_fmt(struct _Locale_time*);
  361. const char * _Locale_am_str(struct _Locale_time *);
  362. const char * _Locale_pm_str(struct _Locale_time *);
  363. #ifndef _STLP_NO_WCHAR_T
  364. const wchar_t * _WLocale_am_str(struct _Locale_time *,
  365. wchar_t* /* buf */, size_t /* bufSize */);
  366. const wchar_t * _WLocale_pm_str(struct _Locale_time *,
  367. wchar_t* /* buf */, size_t /* bufSize */);
  368. #endif
  369. /*
  370. * FUNCTIONS THAT USE MESSAGES
  371. */
  372. /*
  373. * Very similar to catopen, except that it uses the given message
  374. * category to determine which catalog to open.
  375. */
  376. nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*);
  377. /* Complementary to _Locale_catopen.
  378. * The catalog must be a value that was returned by a previous call
  379. * to _Locale_catopen.
  380. */
  381. void _Locale_catclose(struct _Locale_messages*, nl_catd_type);
  382. /*
  383. * Returns a string, identified by a set index and a message index,
  384. * from an opened message catalog. Returns the supplied default if
  385. * no such string exists.
  386. */
  387. const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type,
  388. int, int,const char *);
  389. #ifdef __cplusplus
  390. }
  391. #endif
  392. #endif /* _STLP_C_LOCALE_IMPL_H */