1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/stlport/src/c_locale.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,450 @@ 1.4 +/* 1.5 + * Copyright (c) 1999 1.6 + * Silicon Graphics Computer Systems, Inc. 1.7 + * 1.8 + * Copyright (c) 1999 1.9 + * Boris Fomitchev 1.10 + * 1.11 + * This material is provided "as is", with absolutely no warranty expressed 1.12 + * or implied. Any use is at your own risk. 1.13 + * 1.14 + * Permission to use or copy this software for any purpose is hereby granted 1.15 + * without fee, provided the above notices are retained on all copies. 1.16 + * Permission to modify the code and to distribute modified code is granted, 1.17 + * provided the above notices are retained, and a notice that the code was 1.18 + * modified is included with the above copyright notice. 1.19 + * 1.20 + */ 1.21 + 1.22 +/* 1.23 + * It is impossible to write the C++ locale library in terms of locales 1.24 + * as defined in the C standard. Instead, we write the C++ locale and I/O 1.25 + * library in terms of a low level C-like interface. This file defines 1.26 + * that interface. 1.27 + * 1.28 + * The low-level locale interface can't be written portably; there 1.29 + * must be a version of it for each platform that the C++ library 1.30 + * is ported to. On many systems this interface may be a thin wrapper 1.31 + * for existing functionality. 1.32 + */ 1.33 + 1.34 +#ifndef _STLP_C_LOCALE_IMPL_H 1.35 +#define _STLP_C_LOCALE_IMPL_H 1.36 + 1.37 +#include "stlport_prefix.h" 1.38 + 1.39 +#include <wchar.h> /* for mbstate_t */ 1.40 +#include <stl/c_locale.h> 1.41 + 1.42 +struct _Locale_name_hint; 1.43 + 1.44 +#if defined (_GNU_SOURCE) && defined (__GLIBC__) && \ 1.45 + ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) 1.46 +# define _STLP_USE_GLIBC2_LOCALIZATION 1.47 +# include <nl_types.h> 1.48 +typedef nl_catd nl_catd_type; 1.49 +#else 1.50 +typedef int nl_catd_type; 1.51 +#endif 1.52 + 1.53 +/* 1.54 + * A number: the maximum length of a simple locale name. 1.55 + * (i.e. a name like like en_US, as opposed to a name like 1.56 + * en_US/de_AT/de_AT/es_MX/en_US/en_US) */ 1.57 +#define _Locale_MAX_SIMPLE_NAME 256 1.58 + 1.59 +#ifdef __cplusplus 1.60 +extern "C" { 1.61 +#endif 1.62 + 1.63 +/* 1.64 + * Typedefs: 1.65 + */ 1.66 +typedef unsigned short int _Locale_mask_t; 1.67 + 1.68 +/* Function called during STLport library load phase. Might contain any 1.69 + * code necessary to the platform localization layer. 1.70 + */ 1.71 +void _Locale_init(void); 1.72 + 1.73 +/* Function called during STLport library unload. Might contain any 1.74 + * code necessary to the platform localization layer. 1.75 + */ 1.76 +void _Locale_final(void); 1.77 + 1.78 +/* Create a category of the locale with the given name. 1.79 + * 1.80 + * The char* argument is a simple (not a composite) locale name, which may 1.81 + * neither be an empty string nor a null pointer. 1.82 + * 1.83 + * These functions return NULL to indicate failure. Failure reason should be reported 1.84 + * using the __err_code pointer. 1.85 + */ 1.86 +struct _Locale_ctype* _Locale_ctype_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); 1.87 +struct _Locale_codecvt* _Locale_codecvt_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); 1.88 +struct _Locale_numeric* _Locale_numeric_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); 1.89 +struct _Locale_time* _Locale_time_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); 1.90 +struct _Locale_collate* _Locale_collate_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); 1.91 +struct _Locale_monetary* _Locale_monetary_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); 1.92 +struct _Locale_messages* _Locale_messages_create(const char *, struct _Locale_name_hint*, int * /* __err_code */); 1.93 + 1.94 +/* Give error reason on failure of one of the _Locale_*_create functions. Available 1.95 + * reasons are: 1.96 + * 0: No specific error reason has been reported. 1.97 + * 1: No platform support for the given facet. 1.98 + * 2: Unknown locale name 1.99 + * 3: No platform API for localization support. 1.100 + * 4: No more memory 1.101 + */ 1.102 +#define _STLP_LOC_UNDEFINED 0 1.103 +#define _STLP_LOC_UNSUPPORTED_FACET_CATEGORY 1 1.104 +#define _STLP_LOC_UNKNOWN_NAME 2 1.105 +#define _STLP_LOC_NO_PLATFORM_SUPPORT 3 1.106 +#define _STLP_LOC_NO_MEMORY 4 1.107 + 1.108 +/* Release a category of a locale 1.109 + * 1.110 + * These functions are used to release a category acquired with the 1.111 + * according _Locale_*_create() functions. 1.112 + */ 1.113 +void _Locale_ctype_destroy(struct _Locale_ctype *); 1.114 +void _Locale_codecvt_destroy(struct _Locale_codecvt *); 1.115 +void _Locale_numeric_destroy(struct _Locale_numeric *); 1.116 +void _Locale_time_destroy(struct _Locale_time *); 1.117 +void _Locale_collate_destroy(struct _Locale_collate *); 1.118 +void _Locale_monetary_destroy(struct _Locale_monetary *); 1.119 +void _Locale_messages_destroy(struct _Locale_messages *); 1.120 + 1.121 +/* 1.122 + * Returns the name of the user's default locale in each 1.123 + * category, as a null-terminated string. A NULL value 1.124 + * means the default "C" locale. 1.125 + */ 1.126 +const char * _Locale_ctype_default(char * __buf); 1.127 +const char * _Locale_numeric_default(char * __buf); 1.128 +const char * _Locale_time_default(char * __buf); 1.129 +const char * _Locale_collate_default(char * __buf); 1.130 +const char * _Locale_monetary_default(char * __buf); 1.131 +const char * _Locale_messages_default(char * __buf); 1.132 + 1.133 +/* Retrieve the name of the given category 1.134 + * 1.135 + * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME 1.136 + * characters. These functions store the name, as a null-terminated 1.137 + * string, in __buf. This function can't fail, at worst name is truncated. 1.138 + */ 1.139 +char const* _Locale_ctype_name(const struct _Locale_ctype *, char* __buf); 1.140 +char const* _Locale_codecvt_name(const struct _Locale_codecvt *, char* __buf); 1.141 +char const* _Locale_numeric_name(const struct _Locale_numeric *, char* __buf); 1.142 +char const* _Locale_time_name(const struct _Locale_time *, char* __buf); 1.143 +char const* _Locale_collate_name(const struct _Locale_collate *, char* __buf); 1.144 +char const* _Locale_monetary_name(const struct _Locale_monetary *, char* __buf); 1.145 +char const* _Locale_messages_name(const struct _Locale_messages *, char* __buf); 1.146 + 1.147 +/* 1.148 + * cname is a (possibly composite) locale name---i.e. a name that can 1.149 + * be passed to setlocale. __buf points to an array large enough to 1.150 + * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these 1.151 + * functions extracts the name of a single category, stores it in buf 1.152 + * as a null-terminated string, and returns buf. 1.153 + */ 1.154 +char const* _Locale_extract_ctype_name(const char *cname, char *__buf, 1.155 + struct _Locale_name_hint* __hint, int *__err_code); 1.156 +char const* _Locale_extract_numeric_name(const char *cname, char *__buf, 1.157 + struct _Locale_name_hint* __hint, int *__err_code); 1.158 +char const* _Locale_extract_time_name(const char *cname, char *__buf, 1.159 + struct _Locale_name_hint* __hint, int *__err_code); 1.160 +char const* _Locale_extract_collate_name(const char *cname, char *__buf, 1.161 + struct _Locale_name_hint* __hint, int *__err_code); 1.162 +char const* _Locale_extract_monetary_name(const char *cname, char *__buf, 1.163 + struct _Locale_name_hint* __hint, int *__err_code); 1.164 +char const* _Locale_extract_messages_name(const char *cname, char *__buf, 1.165 + struct _Locale_name_hint* __hint, int *__err_code); 1.166 + 1.167 +/* Functions to improve locale creation process. For some locale API (Win32) 1.168 + * you need to find a locale identification from the name which can be a 1.169 + * rather expensive operation especially if you do so for all facets of a 1.170 + * locale. Those functions can be used to extract from a API dependent facet 1.171 + * struct the information necessary to skip this lookup process for other 1.172 + * facets creation. If not supported those function should return NULL. 1.173 + */ 1.174 +struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*); 1.175 +struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*); 1.176 +struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*); 1.177 +struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*); 1.178 +struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*); 1.179 +struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*); 1.180 + 1.181 +/* 1.182 + * FUNCTIONS THAT USE CTYPE 1.183 + */ 1.184 + 1.185 +/* 1.186 + * Narrow character functions: 1.187 + */ 1.188 + 1.189 +/* 1.190 + * Returns a pointer to the beginning of the ctype table. The table is 1.191 + * at least 257 bytes long; if p is the pointer returned by this 1.192 + * function, then p[c] is valid if c is EOF or if p is any value of 1.193 + * type unsigned char. 1.194 + */ 1.195 +const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *); 1.196 + 1.197 +/* 1.198 + * c is either EOF, or an unsigned char value. 1.199 + */ 1.200 +int _Locale_toupper(struct _Locale_ctype *, int /* c */); 1.201 +int _Locale_tolower(struct _Locale_ctype *, int /* c */); 1.202 + 1.203 + 1.204 +#ifndef _STLP_NO_WCHAR_T 1.205 +/* 1.206 + * Wide character functions: 1.207 + */ 1.208 +_Locale_mask_t _WLocale_ctype(struct _Locale_ctype *, wint_t, _Locale_mask_t); 1.209 +wint_t _WLocale_tolower(struct _Locale_ctype *, wint_t); 1.210 +wint_t _WLocale_toupper(struct _Locale_ctype *, wint_t); 1.211 + 1.212 +/* 1.213 + * Multibyte functions: 1.214 + */ 1.215 + 1.216 +/* 1.217 + * Returns the number of bytes of the longest allowed multibyte 1.218 + * character in the current encoding. 1.219 + */ 1.220 +int _WLocale_mb_cur_max(struct _Locale_codecvt *); 1.221 + 1.222 +/* 1.223 + * Returns the number of bytes of the shortest allowed multibyte 1.224 + * character in the current encoding. 1.225 + */ 1.226 +int _WLocale_mb_cur_min(struct _Locale_codecvt *); 1.227 + 1.228 +/* 1.229 + * Returns 1 if the current multibyte encoding is stateless 1.230 + * and does not require the use of an mbstate_t value. 1.231 + */ 1.232 +int _WLocale_is_stateless(struct _Locale_codecvt *); 1.233 + 1.234 +/* 1.235 + * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only 1.236 + * important difference is that mbrtowc treats null wide characters 1.237 + * as special, and we don't. Specifically: examines the characters 1.238 + * in [from, from + n), extracts a single wide character, and stores 1.239 + * it in *to. Modifies shift_state if appropriate. The return value, 1.240 + * which is always positive, is the number of characters extracted from 1.241 + * the input sequence. Return value is (size_t) -1 if there was an 1.242 + * encoding error in the input sequence, and (size_t) -2 if 1.243 + * [from, from + n) is correct but not complete. None of the pointer 1.244 + * arguments may be null pointers. 1.245 + */ 1.246 +size_t _WLocale_mbtowc(struct _Locale_codecvt *, 1.247 + wchar_t * /* to */, 1.248 + const char * /* from */, size_t /* n */, 1.249 + mbstate_t *); 1.250 + 1.251 +/* 1.252 + * Again, very similar to wcrtomb. The differences are that (1) it 1.253 + * doesn't treat null characters as special; and (2) it stores at most 1.254 + * n characters. Converts c to a multibyte sequence, stores that 1.255 + * sequence in the array 'to', and returns the length of the sequence. 1.256 + * Modifies shift_state if appropriate. The return value is (size_t) -1 1.257 + * if c is not a valid wide character, and (size_t) -2 if the length of 1.258 + * the multibyte character sequence is greater than n. 1.259 + */ 1.260 +size_t _WLocale_wctomb(struct _Locale_codecvt *, 1.261 + char *, size_t, 1.262 + const wchar_t, 1.263 + mbstate_t *); 1.264 + 1.265 +/* 1.266 + * Inserts whatever characters are necessary to restore st to an 1.267 + * initial shift state. Sets *next to buf + m, where m is the number 1.268 + * of characters inserted. (0 <= m <= n.) Returns m to indicate 1.269 + * success, (size_t) -1 to indicate error, (size_t) -2 to indicate 1.270 + * partial success (more than n characters needed). For success or partial 1.271 + * success, sets *next to buf + m. 1.272 + */ 1.273 +size_t _WLocale_unshift(struct _Locale_codecvt *, 1.274 + mbstate_t *, 1.275 + char *, size_t, char **); 1.276 +#endif 1.277 + 1.278 +/* 1.279 + * FUNCTIONS THAT USE COLLATE 1.280 + */ 1.281 + 1.282 +/* 1.283 + * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither 1.284 + * sequence is assumed to be null-terminated, and null characters 1.285 + * aren't special. If the two sequences are the same up through 1.286 + * min(n1, n2), then the sequence that compares less is whichever one 1.287 + * is shorter. 1.288 + */ 1.289 +int _Locale_strcmp(struct _Locale_collate *, 1.290 + const char * /* s1 */, size_t /* n1 */, 1.291 + const char * /* s2 */, size_t /* n2 */); 1.292 +#ifndef _STLP_NO_WCHAR_T 1.293 +int _WLocale_strcmp(struct _Locale_collate *, 1.294 + const wchar_t * /* s1 */, size_t /* n1 */, 1.295 + const wchar_t * /* s2 */, size_t /* n2 */); 1.296 +#endif 1.297 + 1.298 +/* 1.299 + * Creates a transformed version of the string [s2, s2 + n2). The 1.300 + * string may contain embedded null characters; nulls aren't special. 1.301 + * The transformed string begins at s1, and contains at most n1 1.302 + * characters. The return value is the length of the transformed 1.303 + * string. If the return value is greater than n1 then this is an 1.304 + * error condition: it indicates that there wasn't enough space. In 1.305 + * that case, the contents of [s1, s1 + n1) is unspecified. 1.306 +*/ 1.307 +size_t _Locale_strxfrm(struct _Locale_collate *, 1.308 + char * /* s1 */, size_t /* n1 */, 1.309 + const char * /* s2 */, size_t /* n2 */); 1.310 + 1.311 +#ifndef _STLP_NO_WCHAR_T 1.312 +size_t _WLocale_strxfrm(struct _Locale_collate *, 1.313 + wchar_t * /* s1 */, size_t /* n1 */, 1.314 + const wchar_t * /* s2 */, size_t /* n2 */); 1.315 +#endif 1.316 + 1.317 + 1.318 +/* 1.319 + * FUNCTIONS THAT USE NUMERIC 1.320 + */ 1.321 + 1.322 +/* 1.323 + * Equivalent to the first three fields in struct lconv. (C standard, 1.324 + * section 7.4.) 1.325 + */ 1.326 +char _Locale_decimal_point(struct _Locale_numeric *); 1.327 +char _Locale_thousands_sep(struct _Locale_numeric *); 1.328 +const char * _Locale_grouping(struct _Locale_numeric *); 1.329 + 1.330 +#ifndef _STLP_NO_WCHAR_T 1.331 +wchar_t _WLocale_decimal_point(struct _Locale_numeric *); 1.332 +wchar_t _WLocale_thousands_sep(struct _Locale_numeric *); 1.333 +#endif 1.334 + 1.335 +/* 1.336 + * Return "true" and "false" in English locales, and something 1.337 + * appropriate in non-English locales. 1.338 + */ 1.339 +const char * _Locale_true(struct _Locale_numeric *); 1.340 +const char * _Locale_false(struct _Locale_numeric *); 1.341 + 1.342 +#ifndef _STLP_NO_WCHAR_T 1.343 +const wchar_t * _WLocale_true(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */); 1.344 +const wchar_t * _WLocale_false(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */); 1.345 +#endif 1.346 + 1.347 +/* 1.348 + * FUNCTIONS THAT USE MONETARY 1.349 + */ 1.350 + 1.351 +/* 1.352 + * Return the obvious fields of struct lconv. 1.353 + */ 1.354 +const char * _Locale_int_curr_symbol(struct _Locale_monetary *); 1.355 +const char * _Locale_currency_symbol(struct _Locale_monetary *); 1.356 +char _Locale_mon_decimal_point(struct _Locale_monetary *); 1.357 +char _Locale_mon_thousands_sep(struct _Locale_monetary *); 1.358 +const char * _Locale_mon_grouping(struct _Locale_monetary *); 1.359 +const char * _Locale_positive_sign(struct _Locale_monetary *); 1.360 +const char * _Locale_negative_sign(struct _Locale_monetary *); 1.361 +char _Locale_int_frac_digits(struct _Locale_monetary *); 1.362 +char _Locale_frac_digits(struct _Locale_monetary *); 1.363 +int _Locale_p_cs_precedes(struct _Locale_monetary *); 1.364 +int _Locale_p_sep_by_space(struct _Locale_monetary *); 1.365 +int _Locale_p_sign_posn(struct _Locale_monetary *); 1.366 +int _Locale_n_cs_precedes(struct _Locale_monetary *); 1.367 +int _Locale_n_sep_by_space(struct _Locale_monetary *); 1.368 +int _Locale_n_sign_posn(struct _Locale_monetary *); 1.369 + 1.370 +#ifndef _STLP_NO_WCHAR_T 1.371 +const wchar_t * _WLocale_int_curr_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); 1.372 +const wchar_t * _WLocale_currency_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); 1.373 +wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary *); 1.374 +wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary *); 1.375 +const wchar_t * _WLocale_positive_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); 1.376 +const wchar_t * _WLocale_negative_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */); 1.377 +#endif 1.378 + 1.379 +/* 1.380 + * FUNCTIONS THAT USE TIME 1.381 + */ 1.382 + 1.383 +/* 1.384 + * month is in the range [0, 12). 1.385 + */ 1.386 +const char * _Locale_full_monthname(struct _Locale_time *, int /* month */); 1.387 +const char * _Locale_abbrev_monthname(struct _Locale_time *, int /* month */); 1.388 + 1.389 +#ifndef _STLP_NO_WCHAR_T 1.390 +const wchar_t * _WLocale_full_monthname(struct _Locale_time *, int /* month */, 1.391 + wchar_t* /* buf */, size_t /* bufSize */); 1.392 +const wchar_t * _WLocale_abbrev_monthname(struct _Locale_time *, int /* month */, 1.393 + wchar_t* /* buf */, size_t /* bufSize */); 1.394 +#endif 1.395 + 1.396 +/* 1.397 + * day is in the range [0, 7). Sunday is 0. 1.398 + */ 1.399 +const char * _Locale_full_dayofweek(struct _Locale_time *, int /* day */); 1.400 +const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int /* day */); 1.401 + 1.402 +#ifndef _STLP_NO_WCHAR_T 1.403 +const wchar_t * _WLocale_full_dayofweek(struct _Locale_time *, int /* day */, 1.404 + wchar_t* /* buf */, size_t /* bufSize */); 1.405 +const wchar_t * _WLocale_abbrev_dayofweek(struct _Locale_time *, int /* day */, 1.406 + wchar_t* /* buf */, size_t /* bufSize */); 1.407 +#endif 1.408 + 1.409 +const char * _Locale_d_t_fmt(struct _Locale_time *); 1.410 +const char * _Locale_d_fmt(struct _Locale_time *); 1.411 +const char * _Locale_t_fmt(struct _Locale_time *); 1.412 +const char * _Locale_long_d_t_fmt(struct _Locale_time*); 1.413 +const char * _Locale_long_d_fmt(struct _Locale_time*); 1.414 + 1.415 +const char * _Locale_am_str(struct _Locale_time *); 1.416 +const char * _Locale_pm_str(struct _Locale_time *); 1.417 + 1.418 +#ifndef _STLP_NO_WCHAR_T 1.419 +const wchar_t * _WLocale_am_str(struct _Locale_time *, 1.420 + wchar_t* /* buf */, size_t /* bufSize */); 1.421 +const wchar_t * _WLocale_pm_str(struct _Locale_time *, 1.422 + wchar_t* /* buf */, size_t /* bufSize */); 1.423 +#endif 1.424 + 1.425 +/* 1.426 + * FUNCTIONS THAT USE MESSAGES 1.427 + */ 1.428 + 1.429 +/* 1.430 + * Very similar to catopen, except that it uses the given message 1.431 + * category to determine which catalog to open. 1.432 + */ 1.433 +nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*); 1.434 + 1.435 +/* Complementary to _Locale_catopen. 1.436 + * The catalog must be a value that was returned by a previous call 1.437 + * to _Locale_catopen. 1.438 + */ 1.439 +void _Locale_catclose(struct _Locale_messages*, nl_catd_type); 1.440 + 1.441 +/* 1.442 + * Returns a string, identified by a set index and a message index, 1.443 + * from an opened message catalog. Returns the supplied default if 1.444 + * no such string exists. 1.445 + */ 1.446 +const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type, 1.447 + int, int,const char *); 1.448 + 1.449 +#ifdef __cplusplus 1.450 +} 1.451 +#endif 1.452 + 1.453 +#endif /* _STLP_C_LOCALE_IMPL_H */