michael@0: /* michael@0: * Copyright (c) 1999 michael@0: * Silicon Graphics Computer Systems, Inc. michael@0: * michael@0: * Copyright (c) 1999 michael@0: * Boris Fomitchev michael@0: * michael@0: * This material is provided "as is", with absolutely no warranty expressed michael@0: * or implied. Any use is at your own risk. michael@0: * michael@0: * Permission to use or copy this software for any purpose is hereby granted michael@0: * without fee, provided the above notices are retained on all copies. michael@0: * Permission to modify the code and to distribute modified code is granted, michael@0: * provided the above notices are retained, and a notice that the code was michael@0: * modified is included with the above copyright notice. michael@0: * michael@0: */ michael@0: michael@0: /* michael@0: * It is impossible to write the C++ locale library in terms of locales michael@0: * as defined in the C standard. Instead, we write the C++ locale and I/O michael@0: * library in terms of a low level C-like interface. This file defines michael@0: * that interface. michael@0: * michael@0: * The low-level locale interface can't be written portably; there michael@0: * must be a version of it for each platform that the C++ library michael@0: * is ported to. On many systems this interface may be a thin wrapper michael@0: * for existing functionality. michael@0: */ michael@0: michael@0: #ifndef _STLP_C_LOCALE_IMPL_H michael@0: #define _STLP_C_LOCALE_IMPL_H michael@0: michael@0: #include "stlport_prefix.h" michael@0: michael@0: #include /* for mbstate_t */ michael@0: #include michael@0: michael@0: struct _Locale_name_hint; michael@0: michael@0: #if defined (_GNU_SOURCE) && defined (__GLIBC__) && \ michael@0: ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) michael@0: # define _STLP_USE_GLIBC2_LOCALIZATION michael@0: # include michael@0: typedef nl_catd nl_catd_type; michael@0: #else michael@0: typedef int nl_catd_type; michael@0: #endif michael@0: michael@0: /* michael@0: * A number: the maximum length of a simple locale name. michael@0: * (i.e. a name like like en_US, as opposed to a name like michael@0: * en_US/de_AT/de_AT/es_MX/en_US/en_US) */ michael@0: #define _Locale_MAX_SIMPLE_NAME 256 michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: /* michael@0: * Typedefs: michael@0: */ michael@0: typedef unsigned short int _Locale_mask_t; michael@0: michael@0: /* Function called during STLport library load phase. Might contain any michael@0: * code necessary to the platform localization layer. michael@0: */ michael@0: void _Locale_init(void); michael@0: michael@0: /* Function called during STLport library unload. Might contain any michael@0: * code necessary to the platform localization layer. michael@0: */ michael@0: void _Locale_final(void); michael@0: michael@0: /* Create a category of the locale with the given name. michael@0: * michael@0: * The char* argument is a simple (not a composite) locale name, which may michael@0: * neither be an empty string nor a null pointer. michael@0: * michael@0: * These functions return NULL to indicate failure. Failure reason should be reported michael@0: * using the __err_code pointer. michael@0: */ michael@0: struct _Locale_ctype* _Locale_ctype_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); michael@0: struct _Locale_codecvt* _Locale_codecvt_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); michael@0: struct _Locale_numeric* _Locale_numeric_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); michael@0: struct _Locale_time* _Locale_time_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); michael@0: struct _Locale_collate* _Locale_collate_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); michael@0: struct _Locale_monetary* _Locale_monetary_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); michael@0: struct _Locale_messages* _Locale_messages_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); michael@0: michael@0: /* Give error reason on failure of one of the _Locale_*_create functions. Available michael@0: * reasons are: michael@0: * 0: No specific error reason has been reported. michael@0: * 1: No platform support for the given facet. michael@0: * 2: Unknown locale name michael@0: * 3: No platform API for localization support. michael@0: * 4: No more memory michael@0: */ michael@0: #define _STLP_LOC_UNDEFINED 0 michael@0: #define _STLP_LOC_UNSUPPORTED_FACET_CATEGORY 1 michael@0: #define _STLP_LOC_UNKNOWN_NAME 2 michael@0: #define _STLP_LOC_NO_PLATFORM_SUPPORT 3 michael@0: #define _STLP_LOC_NO_MEMORY 4 michael@0: michael@0: /* Release a category of a locale michael@0: * michael@0: * These functions are used to release a category acquired with the michael@0: * according _Locale_*_create() functions. michael@0: */ michael@0: void _Locale_ctype_destroy(struct _Locale_ctype *); michael@0: void _Locale_codecvt_destroy(struct _Locale_codecvt *); michael@0: void _Locale_numeric_destroy(struct _Locale_numeric *); michael@0: void _Locale_time_destroy(struct _Locale_time *); michael@0: void _Locale_collate_destroy(struct _Locale_collate *); michael@0: void _Locale_monetary_destroy(struct _Locale_monetary *); michael@0: void _Locale_messages_destroy(struct _Locale_messages *); michael@0: michael@0: /* michael@0: * Returns the name of the user's default locale in each michael@0: * category, as a null-terminated string. A NULL value michael@0: * means the default "C" locale. michael@0: */ michael@0: const char * _Locale_ctype_default(char * __buf); michael@0: const char * _Locale_numeric_default(char * __buf); michael@0: const char * _Locale_time_default(char * __buf); michael@0: const char * _Locale_collate_default(char * __buf); michael@0: const char * _Locale_monetary_default(char * __buf); michael@0: const char * _Locale_messages_default(char * __buf); michael@0: michael@0: /* Retrieve the name of the given category michael@0: * michael@0: * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME michael@0: * characters. These functions store the name, as a null-terminated michael@0: * string, in __buf. This function can't fail, at worst name is truncated. michael@0: */ michael@0: char const* _Locale_ctype_name(const struct _Locale_ctype *, char* __buf); michael@0: char const* _Locale_codecvt_name(const struct _Locale_codecvt *, char* __buf); michael@0: char const* _Locale_numeric_name(const struct _Locale_numeric *, char* __buf); michael@0: char const* _Locale_time_name(const struct _Locale_time *, char* __buf); michael@0: char const* _Locale_collate_name(const struct _Locale_collate *, char* __buf); michael@0: char const* _Locale_monetary_name(const struct _Locale_monetary *, char* __buf); michael@0: char const* _Locale_messages_name(const struct _Locale_messages *, char* __buf); michael@0: michael@0: /* michael@0: * cname is a (possibly composite) locale name---i.e. a name that can michael@0: * be passed to setlocale. __buf points to an array large enough to michael@0: * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these michael@0: * functions extracts the name of a single category, stores it in buf michael@0: * as a null-terminated string, and returns buf. michael@0: */ michael@0: char const* _Locale_extract_ctype_name(const char *cname, char *__buf, michael@0: struct _Locale_name_hint* __hint, int *__err_code); michael@0: char const* _Locale_extract_numeric_name(const char *cname, char *__buf, michael@0: struct _Locale_name_hint* __hint, int *__err_code); michael@0: char const* _Locale_extract_time_name(const char *cname, char *__buf, michael@0: struct _Locale_name_hint* __hint, int *__err_code); michael@0: char const* _Locale_extract_collate_name(const char *cname, char *__buf, michael@0: struct _Locale_name_hint* __hint, int *__err_code); michael@0: char const* _Locale_extract_monetary_name(const char *cname, char *__buf, michael@0: struct _Locale_name_hint* __hint, int *__err_code); michael@0: char const* _Locale_extract_messages_name(const char *cname, char *__buf, michael@0: struct _Locale_name_hint* __hint, int *__err_code); michael@0: michael@0: /* Functions to improve locale creation process. For some locale API (Win32) michael@0: * you need to find a locale identification from the name which can be a michael@0: * rather expensive operation especially if you do so for all facets of a michael@0: * locale. Those functions can be used to extract from a API dependent facet michael@0: * struct the information necessary to skip this lookup process for other michael@0: * facets creation. If not supported those function should return NULL. michael@0: */ michael@0: struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*); michael@0: struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*); michael@0: struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*); michael@0: struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*); michael@0: struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*); michael@0: struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*); michael@0: michael@0: /* michael@0: * FUNCTIONS THAT USE CTYPE michael@0: */ michael@0: michael@0: /* michael@0: * Narrow character functions: michael@0: */ michael@0: michael@0: /* michael@0: * Returns a pointer to the beginning of the ctype table. The table is michael@0: * at least 257 bytes long; if p is the pointer returned by this michael@0: * function, then p[c] is valid if c is EOF or if p is any value of michael@0: * type unsigned char. michael@0: */ michael@0: const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *); michael@0: michael@0: /* michael@0: * c is either EOF, or an unsigned char value. michael@0: */ michael@0: int _Locale_toupper(struct _Locale_ctype *, int /* c */); michael@0: int _Locale_tolower(struct _Locale_ctype *, int /* c */); michael@0: michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: /* michael@0: * Wide character functions: michael@0: */ michael@0: _Locale_mask_t _WLocale_ctype(struct _Locale_ctype *, wint_t, _Locale_mask_t); michael@0: wint_t _WLocale_tolower(struct _Locale_ctype *, wint_t); michael@0: wint_t _WLocale_toupper(struct _Locale_ctype *, wint_t); michael@0: michael@0: /* michael@0: * Multibyte functions: michael@0: */ michael@0: michael@0: /* michael@0: * Returns the number of bytes of the longest allowed multibyte michael@0: * character in the current encoding. michael@0: */ michael@0: int _WLocale_mb_cur_max(struct _Locale_codecvt *); michael@0: michael@0: /* michael@0: * Returns the number of bytes of the shortest allowed multibyte michael@0: * character in the current encoding. michael@0: */ michael@0: int _WLocale_mb_cur_min(struct _Locale_codecvt *); michael@0: michael@0: /* michael@0: * Returns 1 if the current multibyte encoding is stateless michael@0: * and does not require the use of an mbstate_t value. michael@0: */ michael@0: int _WLocale_is_stateless(struct _Locale_codecvt *); michael@0: michael@0: /* michael@0: * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only michael@0: * important difference is that mbrtowc treats null wide characters michael@0: * as special, and we don't. Specifically: examines the characters michael@0: * in [from, from + n), extracts a single wide character, and stores michael@0: * it in *to. Modifies shift_state if appropriate. The return value, michael@0: * which is always positive, is the number of characters extracted from michael@0: * the input sequence. Return value is (size_t) -1 if there was an michael@0: * encoding error in the input sequence, and (size_t) -2 if michael@0: * [from, from + n) is correct but not complete. None of the pointer michael@0: * arguments may be null pointers. michael@0: */ michael@0: size_t _WLocale_mbtowc(struct _Locale_codecvt *, michael@0: wchar_t * /* to */, michael@0: const char * /* from */, size_t /* n */, michael@0: mbstate_t *); michael@0: michael@0: /* michael@0: * Again, very similar to wcrtomb. The differences are that (1) it michael@0: * doesn't treat null characters as special; and (2) it stores at most michael@0: * n characters. Converts c to a multibyte sequence, stores that michael@0: * sequence in the array 'to', and returns the length of the sequence. michael@0: * Modifies shift_state if appropriate. The return value is (size_t) -1 michael@0: * if c is not a valid wide character, and (size_t) -2 if the length of michael@0: * the multibyte character sequence is greater than n. michael@0: */ michael@0: size_t _WLocale_wctomb(struct _Locale_codecvt *, michael@0: char *, size_t, michael@0: const wchar_t, michael@0: mbstate_t *); michael@0: michael@0: /* michael@0: * Inserts whatever characters are necessary to restore st to an michael@0: * initial shift state. Sets *next to buf + m, where m is the number michael@0: * of characters inserted. (0 <= m <= n.) Returns m to indicate michael@0: * success, (size_t) -1 to indicate error, (size_t) -2 to indicate michael@0: * partial success (more than n characters needed). For success or partial michael@0: * success, sets *next to buf + m. michael@0: */ michael@0: size_t _WLocale_unshift(struct _Locale_codecvt *, michael@0: mbstate_t *, michael@0: char *, size_t, char **); michael@0: #endif michael@0: michael@0: /* michael@0: * FUNCTIONS THAT USE COLLATE michael@0: */ michael@0: michael@0: /* michael@0: * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither michael@0: * sequence is assumed to be null-terminated, and null characters michael@0: * aren't special. If the two sequences are the same up through michael@0: * min(n1, n2), then the sequence that compares less is whichever one michael@0: * is shorter. michael@0: */ michael@0: int _Locale_strcmp(struct _Locale_collate *, michael@0: const char * /* s1 */, size_t /* n1 */, michael@0: const char * /* s2 */, size_t /* n2 */); michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: int _WLocale_strcmp(struct _Locale_collate *, michael@0: const wchar_t * /* s1 */, size_t /* n1 */, michael@0: const wchar_t * /* s2 */, size_t /* n2 */); michael@0: #endif michael@0: michael@0: /* michael@0: * Creates a transformed version of the string [s2, s2 + n2). The michael@0: * string may contain embedded null characters; nulls aren't special. michael@0: * The transformed string begins at s1, and contains at most n1 michael@0: * characters. The return value is the length of the transformed michael@0: * string. If the return value is greater than n1 then this is an michael@0: * error condition: it indicates that there wasn't enough space. In michael@0: * that case, the contents of [s1, s1 + n1) is unspecified. michael@0: */ michael@0: size_t _Locale_strxfrm(struct _Locale_collate *, michael@0: char * /* s1 */, size_t /* n1 */, michael@0: const char * /* s2 */, size_t /* n2 */); michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: size_t _WLocale_strxfrm(struct _Locale_collate *, michael@0: wchar_t * /* s1 */, size_t /* n1 */, michael@0: const wchar_t * /* s2 */, size_t /* n2 */); michael@0: #endif michael@0: michael@0: michael@0: /* michael@0: * FUNCTIONS THAT USE NUMERIC michael@0: */ michael@0: michael@0: /* michael@0: * Equivalent to the first three fields in struct lconv. (C standard, michael@0: * section 7.4.) michael@0: */ michael@0: char _Locale_decimal_point(struct _Locale_numeric *); michael@0: char _Locale_thousands_sep(struct _Locale_numeric *); michael@0: const char * _Locale_grouping(struct _Locale_numeric *); michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: wchar_t _WLocale_decimal_point(struct _Locale_numeric *); michael@0: wchar_t _WLocale_thousands_sep(struct _Locale_numeric *); michael@0: #endif michael@0: michael@0: /* michael@0: * Return "true" and "false" in English locales, and something michael@0: * appropriate in non-English locales. michael@0: */ michael@0: const char * _Locale_true(struct _Locale_numeric *); michael@0: const char * _Locale_false(struct _Locale_numeric *); michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: const wchar_t * _WLocale_true(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */); michael@0: const wchar_t * _WLocale_false(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */); michael@0: #endif michael@0: michael@0: /* michael@0: * FUNCTIONS THAT USE MONETARY michael@0: */ michael@0: michael@0: /* michael@0: * Return the obvious fields of struct lconv. michael@0: */ michael@0: const char * _Locale_int_curr_symbol(struct _Locale_monetary *); michael@0: const char * _Locale_currency_symbol(struct _Locale_monetary *); michael@0: char _Locale_mon_decimal_point(struct _Locale_monetary *); michael@0: char _Locale_mon_thousands_sep(struct _Locale_monetary *); michael@0: const char * _Locale_mon_grouping(struct _Locale_monetary *); michael@0: const char * _Locale_positive_sign(struct _Locale_monetary *); michael@0: const char * _Locale_negative_sign(struct _Locale_monetary *); michael@0: char _Locale_int_frac_digits(struct _Locale_monetary *); michael@0: char _Locale_frac_digits(struct _Locale_monetary *); michael@0: int _Locale_p_cs_precedes(struct _Locale_monetary *); michael@0: int _Locale_p_sep_by_space(struct _Locale_monetary *); michael@0: int _Locale_p_sign_posn(struct _Locale_monetary *); michael@0: int _Locale_n_cs_precedes(struct _Locale_monetary *); michael@0: int _Locale_n_sep_by_space(struct _Locale_monetary *); michael@0: int _Locale_n_sign_posn(struct _Locale_monetary *); michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: const wchar_t * _WLocale_int_curr_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); michael@0: const wchar_t * _WLocale_currency_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); michael@0: wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary *); michael@0: wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary *); michael@0: const wchar_t * _WLocale_positive_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); michael@0: const wchar_t * _WLocale_negative_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); michael@0: #endif michael@0: michael@0: /* michael@0: * FUNCTIONS THAT USE TIME michael@0: */ michael@0: michael@0: /* michael@0: * month is in the range [0, 12). michael@0: */ michael@0: const char * _Locale_full_monthname(struct _Locale_time *, int /* month */); michael@0: const char * _Locale_abbrev_monthname(struct _Locale_time *, int /* month */); michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: const wchar_t * _WLocale_full_monthname(struct _Locale_time *, int /* month */, michael@0: wchar_t* /* buf */, size_t /* bufSize */); michael@0: const wchar_t * _WLocale_abbrev_monthname(struct _Locale_time *, int /* month */, michael@0: wchar_t* /* buf */, size_t /* bufSize */); michael@0: #endif michael@0: michael@0: /* michael@0: * day is in the range [0, 7). Sunday is 0. michael@0: */ michael@0: const char * _Locale_full_dayofweek(struct _Locale_time *, int /* day */); michael@0: const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int /* day */); michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: const wchar_t * _WLocale_full_dayofweek(struct _Locale_time *, int /* day */, michael@0: wchar_t* /* buf */, size_t /* bufSize */); michael@0: const wchar_t * _WLocale_abbrev_dayofweek(struct _Locale_time *, int /* day */, michael@0: wchar_t* /* buf */, size_t /* bufSize */); michael@0: #endif michael@0: michael@0: const char * _Locale_d_t_fmt(struct _Locale_time *); michael@0: const char * _Locale_d_fmt(struct _Locale_time *); michael@0: const char * _Locale_t_fmt(struct _Locale_time *); michael@0: const char * _Locale_long_d_t_fmt(struct _Locale_time*); michael@0: const char * _Locale_long_d_fmt(struct _Locale_time*); michael@0: michael@0: const char * _Locale_am_str(struct _Locale_time *); michael@0: const char * _Locale_pm_str(struct _Locale_time *); michael@0: michael@0: #ifndef _STLP_NO_WCHAR_T michael@0: const wchar_t * _WLocale_am_str(struct _Locale_time *, michael@0: wchar_t* /* buf */, size_t /* bufSize */); michael@0: const wchar_t * _WLocale_pm_str(struct _Locale_time *, michael@0: wchar_t* /* buf */, size_t /* bufSize */); michael@0: #endif michael@0: michael@0: /* michael@0: * FUNCTIONS THAT USE MESSAGES michael@0: */ michael@0: michael@0: /* michael@0: * Very similar to catopen, except that it uses the given message michael@0: * category to determine which catalog to open. michael@0: */ michael@0: nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*); michael@0: michael@0: /* Complementary to _Locale_catopen. michael@0: * The catalog must be a value that was returned by a previous call michael@0: * to _Locale_catopen. michael@0: */ michael@0: void _Locale_catclose(struct _Locale_messages*, nl_catd_type); michael@0: michael@0: /* michael@0: * Returns a string, identified by a set index and a message index, michael@0: * from an opened message catalog. Returns the supplied default if michael@0: * no such string exists. michael@0: */ michael@0: const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type, michael@0: int, int,const char *); michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif /* _STLP_C_LOCALE_IMPL_H */