sl@0: /* sl@0: * Copyright (c) 1999 sl@0: * Silicon Graphics Computer Systems, Inc. sl@0: * sl@0: * Copyright (c) 1999 sl@0: * Boris Fomitchev sl@0: * sl@0: * This material is provided "as is", with absolutely no warranty expressed sl@0: * or implied. Any use is at your own risk. sl@0: * sl@0: * Permission to use or copy this software for any purpose is hereby granted sl@0: * without fee, provided the above notices are retained on all copies. sl@0: * Permission to modify the code and to distribute modified code is granted, sl@0: * provided the above notices are retained, and a notice that the code was sl@0: * modified is included with the above copyright notice. sl@0: * sl@0: */ sl@0: sl@0: /* sl@0: * It is impossible to write the C++ locale library in terms of locales sl@0: * as defined in the C standard. Instead, we write the C++ locale and I/O sl@0: * library in terms of a low level C-like interface. This file defines sl@0: * that interface. sl@0: * sl@0: * The low-level locale interface can't be written portably; there sl@0: * must be a version of it for each platform that the C++ library sl@0: * is ported to. On many systems this interface may be a thin wrapper sl@0: * for existing functionality. sl@0: */ sl@0: sl@0: #ifndef _STLP_C_LOCALE_IMPL_H sl@0: #define _STLP_C_LOCALE_IMPL_H sl@0: sl@0: #include "stlport_prefix.h" sl@0: #include sl@0: sl@0: #ifdef _STLP_REAL_LOCALE_IMPLEMENTED sl@0: # if defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__) sl@0: # include sl@0: # endif sl@0: #endif sl@0: sl@0: /* sl@0: * A number: the maximum length of a simple locale name. sl@0: * (i.e. a name like like en_US, as opposed to a name like sl@0: * en_US/de_AT/de_AT/es_MX/en_US/en_US) */ sl@0: #define _Locale_MAX_SIMPLE_NAME 256 sl@0: sl@0: /* sl@0: * Maximum length of a composite locale. sl@0: */ sl@0: #define _Locale_MAX_COMPOSITE_NAME 6*(_Locale_MAX_SIMPLE_NAME+3) sl@0: sl@0: #ifdef __cplusplus sl@0: extern "C" { sl@0: #endif sl@0: sl@0: /* sl@0: * Typedefs: sl@0: */ sl@0: #if ((defined (__GNUC__) && !defined (__MINGW32__)) || defined (_KCC) || defined (__ICC)) && (!defined (__SYMBIAN32__)) sl@0: typedef unsigned short int _Locale_mask_t; sl@0: #else sl@0: typedef unsigned int _Locale_mask_t; sl@0: #endif sl@0: sl@0: /* Function called during STLport library load phase. Might contain any sl@0: * code necessary to the platform localization layer. sl@0: */ sl@0: void _Locale_init(); sl@0: sl@0: /* Function called during STLport library unload. Might contain any sl@0: * code necessary to the platform localization layer. sl@0: */ sl@0: void _Locale_final(); sl@0: sl@0: /* Create a category of the locale with the given name. sl@0: * sl@0: * The char* argument is a simple (not a composite) locale name, which may sl@0: * neither be an empty string nor a null pointer. sl@0: * sl@0: * These functions return NULL to indicate failure. sl@0: * sl@0: * Note These functions return a void* instead of the appropriate sl@0: * _Locale_* struct because they are used with __acquire_category which sl@0: * requires that all functions have the same signature. sl@0: */ sl@0: void * _Locale_ctype_create(const char *, struct _Locale_name_hint*); sl@0: void * _Locale_numeric_create(const char *, struct _Locale_name_hint*); sl@0: void * _Locale_time_create(const char *, struct _Locale_name_hint*); sl@0: void * _Locale_collate_create(const char *, struct _Locale_name_hint*); sl@0: void * _Locale_monetary_create(const char *, struct _Locale_name_hint*); sl@0: void * _Locale_messages_create(const char *, struct _Locale_name_hint*); sl@0: sl@0: sl@0: /* Release a category of a locale sl@0: * sl@0: * These functions are used to release a category acquired with the sl@0: * according _Locale_*_create() functions. sl@0: * sl@0: * Note: For the same reasons as for the *_create functions, these sl@0: * take void* instead of the correct types so that they can be used sl@0: * with __release_category. sl@0: */ sl@0: void _Locale_ctype_destroy(void *); sl@0: void _Locale_numeric_destroy(void *); sl@0: void _Locale_time_destroy(void *); sl@0: void _Locale_collate_destroy(void *); sl@0: void _Locale_monetary_destroy(void *); sl@0: void _Locale_messages_destroy(void *); sl@0: sl@0: sl@0: /* sl@0: * Returns the name of the user's default locale in each sl@0: * category, as a null-terminated string. A NULL value sl@0: * means the default "C" locale. sl@0: */ sl@0: const char * _Locale_ctype_default(char * __buf); sl@0: const char * _Locale_numeric_default(char * __buf); sl@0: const char * _Locale_time_default(char * __buf); sl@0: const char * _Locale_collate_default(char * __buf); sl@0: const char * _Locale_monetary_default(char * __buf); sl@0: const char * _Locale_messages_default(char * __buf); sl@0: sl@0: sl@0: /* Retrieve the name of the given category sl@0: * sl@0: * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME sl@0: * characters. These functions store the name, as a null-terminated sl@0: * string, in __buf. sl@0: * TODO: can this fail? How is that signalled then? sl@0: */ sl@0: char const* _Locale_ctype_name(const void *, char* __buf); sl@0: char const* _Locale_numeric_name(const void *, char* __buf); sl@0: char const* _Locale_time_name(const void *, char* __buf); sl@0: char const* _Locale_collate_name(const void *, char* __buf); sl@0: char const* _Locale_monetary_name(const void *, char* __buf); sl@0: char const* _Locale_messages_name(const void *, char* __buf); sl@0: sl@0: sl@0: /* sl@0: * cname is a (possibly composite) locale name---i.e. a name that can sl@0: * be passed to setlocale. __buf points to an array large enough to sl@0: * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these sl@0: * functions extracts the name of a single category, stores it in buf sl@0: * as a null-terminated string, and returns buf. sl@0: */ sl@0: char const* _Locale_extract_ctype_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint); sl@0: char const* _Locale_extract_numeric_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint); sl@0: char const* _Locale_extract_time_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint); sl@0: char const* _Locale_extract_collate_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint); sl@0: char const* _Locale_extract_monetary_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint); sl@0: char const* _Locale_extract_messages_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint); sl@0: sl@0: /* sl@0: * The inputs to this function are six null-terminated strings: the sl@0: * names of a locale's six categories. Locale names for non-standard sl@0: * categories are taken from __DefaultName. sl@0: * __buf is a pointer to an array large enough to store at least sl@0: * _Locale_MAX_COMPOSITE_NAME characters. sl@0: * This function constructs a (possibly composite) name describing the sl@0: * locale as a whole, stores that name in buf as a null-terminated sl@0: * string, and returns buf. sl@0: */ sl@0: char const* _Locale_compose_name(char *__buf, sl@0: const char *__Ctype, const char *__Numeric, sl@0: const char *__Time, const char *__Collate, sl@0: const char *__Monetary, const char *__Messages, sl@0: const char *__DefaultName); sl@0: sl@0: /* Funstions to improve locale creation process. For some locale API (Win32) sl@0: * you need to find a locale identification from the name which can be a sl@0: * rather expensive operation especially if you do so for all facets of a sl@0: * locale. Those functions can be used to extract from a API dependent facet sl@0: * struct the information necessary to skip this lookup process for other sl@0: * facets creation. If not supported those function should return NULL. sl@0: */ sl@0: struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*); sl@0: struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*); sl@0: struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*); sl@0: struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*); sl@0: struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*); sl@0: struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*); sl@0: sl@0: /* sl@0: * FUNCTIONS THAT USE CTYPE sl@0: */ sl@0: sl@0: /* sl@0: * Narrow character functions: sl@0: */ sl@0: sl@0: /* sl@0: * Returns a pointer to the beginning of the ctype table. The table is sl@0: * at least 257 bytes long; if p is the pointer returned by this sl@0: * function, then p[c] is valid if c is EOF or if p is any value of sl@0: * type unsigned char. sl@0: */ sl@0: const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *); sl@0: sl@0: /* sl@0: * c is either EOF, or an unsigned char value. sl@0: */ sl@0: int _Locale_toupper(struct _Locale_ctype *, int); sl@0: int _Locale_tolower(struct _Locale_ctype *, int); sl@0: sl@0: sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: /* sl@0: * Wide character functions: sl@0: */ sl@0: _Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype *, wint_t, sl@0: _Locale_mask_t); sl@0: wint_t _Locale_wchar_tolower(struct _Locale_ctype *, wint_t); sl@0: wint_t _Locale_wchar_toupper(struct _Locale_ctype *, wint_t); sl@0: # endif sl@0: sl@0: # if !defined ( _STLP_NO_MBSTATE_T ) sl@0: sl@0: /* sl@0: * Multibyte functions: sl@0: */ sl@0: sl@0: int _Locale_mb_cur_max (struct _Locale_ctype *); sl@0: /* sl@0: * Returns the number of bytes of the longest allowed multibyte sl@0: * character in the current encoding. sl@0: */ sl@0: sl@0: int _Locale_mb_cur_min (struct _Locale_ctype *); sl@0: /* sl@0: * Returns the number of bytes of the shortest allowed multibyte sl@0: * character in the current encoding. sl@0: */ sl@0: sl@0: int _Locale_is_stateless (struct _Locale_ctype *); sl@0: /* sl@0: * Returns 1 if the current multibyte encoding is stateless sl@0: * and does not require the use of an mbstate_t value. sl@0: */ sl@0: sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: wint_t _Locale_btowc(struct _Locale_ctype *, int); sl@0: int _Locale_wctob(struct _Locale_ctype *, wint_t); sl@0: sl@0: /* sl@0: * Just like btowc and wctob, from 4.6.5.1 of the C standard, Normative sl@0: * Addendum 1. (And just like widen/narrow, from clause 22 of the C++ sl@0: * standard.) sl@0: */ sl@0: sl@0: size_t _Locale_mbtowc(struct _Locale_ctype *, sl@0: wchar_t *, sl@0: const char *, size_t, sl@0: mbstate_t *); sl@0: sl@0: /* sl@0: * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only sl@0: * important difference is that mbrtowc treats null wide characters sl@0: * as special, and we don't. Specifically: examines the characters sl@0: * in [from, from + n), extracts a single wide character, and stores sl@0: * it in *to. Modifies shift_state if appropriate. The return value, sl@0: * which is always positive, is the number of characters extracted from sl@0: * the input sequence. Return value is (size_t) -1 if there was an sl@0: * encoding error in the input sequence, and (size_t) -2 if sl@0: * [from, from + n) is correct but not complete. None of the pointer sl@0: * arguments may be null pointers. sl@0: */ sl@0: sl@0: size_t _Locale_wctomb(struct _Locale_ctype *, sl@0: char *, size_t, sl@0: const wchar_t, sl@0: mbstate_t *); sl@0: sl@0: /* sl@0: * Again, very similar to wcrtomb. The differences are that (1) it sl@0: * doesn't treat null characters as special; and (2) it stores at most sl@0: * n characters. Converts c to a multibyte sequence, stores that sl@0: * sequence in the array 'to', and returns the length of the sequence. sl@0: * Modifies shift_state if appropriate. The return value is (size_t) -1 sl@0: * if c is not a valid wide character, and (size_t) -2 if the length of sl@0: * the multibyte character sequence is greater than n. sl@0: */ sl@0: # endif sl@0: sl@0: size_t _Locale_unshift(struct _Locale_ctype *, sl@0: mbstate_t *, sl@0: char *, size_t, char **); sl@0: sl@0: /* sl@0: * Inserts whatever characters are necessary to restore st to an sl@0: * initial shift state. Sets *next to buf + m, where m is the number sl@0: * of characters inserted. (0 <= m <= n.) Returns m to indicate sl@0: * success, (size_t) -1 to indicate error, (size_t) -2 to indicate sl@0: * partial success (more than n characters needed). For success or partial sl@0: * success, sets *next to buf + m. sl@0: */ sl@0: sl@0: # endif /* _STLP_NO_MBSTATE_T */ sl@0: sl@0: /* sl@0: * FUNCTIONS THAT USE COLLATE sl@0: */ sl@0: sl@0: int _Locale_strcmp(struct _Locale_collate *, sl@0: const char *, size_t, sl@0: const char *, size_t); sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: int _Locale_strwcmp(struct _Locale_collate *, sl@0: const wchar_t *, size_t, sl@0: const wchar_t *, size_t); sl@0: # endif sl@0: /* sl@0: * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither sl@0: * sequence is assumed to be null-terminated, and null characters sl@0: * aren't special. If the two sequences are the same up through sl@0: * min(n1, n2), then the sequence that compares less is whichever one sl@0: * is shorter. sl@0: */ sl@0: sl@0: size_t _Locale_strxfrm(struct _Locale_collate *, sl@0: char *, size_t, sl@0: const char *, size_t); sl@0: sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: size_t _Locale_strwxfrm(struct _Locale_collate *, sl@0: wchar_t *, size_t, sl@0: const wchar_t *, size_t); sl@0: # endif sl@0: sl@0: /* sl@0: * Creates a transformed version of the string [s2, s2 + n2). The sl@0: * string may contain embedded null characters; nulls aren't special. sl@0: * The transformed string begins at s1, and contains at most n1 sl@0: * characters. The return value is the length of the transformed sl@0: * string. If the return value is greater than n1 then this is an sl@0: * error condition: it indicates that there wasn't enough space. In sl@0: * that case, the contents of [s1, s1 + n1) is unspecified. sl@0: */ sl@0: sl@0: /* sl@0: * FUNCTIONS THAT USE NUMERIC sl@0: */ sl@0: sl@0: /* sl@0: * Equivalent to the first three fields in struct lconv. (C standard, sl@0: * section 7.4.) sl@0: */ sl@0: char _Locale_decimal_point(struct _Locale_numeric *); sl@0: char _Locale_thousands_sep(struct _Locale_numeric *); sl@0: const char * _Locale_grouping(struct _Locale_numeric *); sl@0: sl@0: sl@0: /* sl@0: * Return "true" and "false" in English locales, and something sl@0: * appropriate in non-English locales. sl@0: */ sl@0: const char * _Locale_true(struct _Locale_numeric *); sl@0: const char * _Locale_false(struct _Locale_numeric *); sl@0: sl@0: sl@0: /* sl@0: * FUNCTIONS THAT USE MONETARY sl@0: */ sl@0: sl@0: /* sl@0: * Return the obvious fields of struct lconv. sl@0: */ sl@0: const char * _Locale_int_curr_symbol(struct _Locale_monetary *); sl@0: const char * _Locale_currency_symbol(struct _Locale_monetary *); sl@0: char _Locale_mon_decimal_point(struct _Locale_monetary *); sl@0: char _Locale_mon_thousands_sep(struct _Locale_monetary *); sl@0: const char * _Locale_mon_grouping(struct _Locale_monetary *); sl@0: const char * _Locale_positive_sign(struct _Locale_monetary *); sl@0: const char * _Locale_negative_sign(struct _Locale_monetary *); sl@0: char _Locale_int_frac_digits(struct _Locale_monetary *); sl@0: char _Locale_frac_digits(struct _Locale_monetary *); sl@0: int _Locale_p_cs_precedes(struct _Locale_monetary *); sl@0: int _Locale_p_sep_by_space(struct _Locale_monetary *); sl@0: int _Locale_p_sign_posn(struct _Locale_monetary *); sl@0: int _Locale_n_cs_precedes(struct _Locale_monetary *); sl@0: int _Locale_n_sep_by_space(struct _Locale_monetary *); sl@0: int _Locale_n_sign_posn(struct _Locale_monetary *); sl@0: sl@0: sl@0: /* sl@0: * FUNCTIONS THAT USE TIME sl@0: */ sl@0: sl@0: /* sl@0: * month is in the range [0, 12). sl@0: */ sl@0: const char * _Locale_full_monthname(struct _Locale_time *, int); sl@0: const char * _Locale_abbrev_monthname(struct _Locale_time *, int); sl@0: sl@0: sl@0: /* sl@0: * day is in the range [0, 7). Sunday is 0. sl@0: */ sl@0: const char * _Locale_full_dayofweek(struct _Locale_time *, int); sl@0: const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int); sl@0: sl@0: sl@0: const char * _Locale_d_t_fmt(struct _Locale_time *); sl@0: const char * _Locale_d_fmt(struct _Locale_time *); sl@0: const char * _Locale_t_fmt(struct _Locale_time *); sl@0: const char * _Locale_long_d_t_fmt(struct _Locale_time*); sl@0: const char * _Locale_long_d_fmt(struct _Locale_time*); sl@0: sl@0: const char * _Locale_am_str(struct _Locale_time *); sl@0: const char * _Locale_pm_str(struct _Locale_time *); sl@0: const char * _Locale_t_fmt_ampm(struct _Locale_time *); sl@0: sl@0: sl@0: /* sl@0: * FUNCTIONS THAT USE MESSAGES sl@0: */ sl@0: sl@0: # ifdef _STLP_REAL_LOCALE_IMPLEMENTED sl@0: # if defined (WIN32) || defined (_WIN32) sl@0: typedef int nl_catd_type; sl@0: # elif defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__) sl@0: typedef nl_catd nl_catd_type; sl@0: # else sl@0: typedef int nl_catd_type; sl@0: # endif sl@0: # else sl@0: typedef int nl_catd_type; sl@0: # endif /* _STLP_REAL_LOCALE_IMPLEMENTED */ sl@0: sl@0: sl@0: /* sl@0: * Very similar to catopen, except that it uses the given message sl@0: * category to determine which catalog to open. sl@0: */ sl@0: nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*); sl@0: sl@0: /* Complementary to _Locale_catopen. sl@0: * The catalog must be a value that was returned by a previous call sl@0: * to _Locale_catopen. sl@0: */ sl@0: void _Locale_catclose(struct _Locale_messages*, nl_catd_type); sl@0: sl@0: /* sl@0: * Returns a string, identified by a set index and a message index, sl@0: * from an opened message catalog. Returns the supplied default if sl@0: * no such string exists. sl@0: */ sl@0: const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type, sl@0: int, int,const char *); sl@0: sl@0: #ifdef __cplusplus sl@0: } sl@0: #endif sl@0: sl@0: #endif /* _STLP_C_LOCALE_IMPL_H */