1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/src/c_locale.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,456 @@
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 +#include <stl/c_locale.h>
1.39 +
1.40 +#ifdef _STLP_REAL_LOCALE_IMPLEMENTED
1.41 +# if defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__)
1.42 +# include <nl_types.h>
1.43 +# endif
1.44 +#endif
1.45 +
1.46 +/*
1.47 + * A number: the maximum length of a simple locale name.
1.48 + * (i.e. a name like like en_US, as opposed to a name like
1.49 + * en_US/de_AT/de_AT/es_MX/en_US/en_US) */
1.50 +#define _Locale_MAX_SIMPLE_NAME 256
1.51 +
1.52 +/*
1.53 + * Maximum length of a composite locale.
1.54 + */
1.55 +#define _Locale_MAX_COMPOSITE_NAME 6*(_Locale_MAX_SIMPLE_NAME+3)
1.56 +
1.57 +#ifdef __cplusplus
1.58 +extern "C" {
1.59 +#endif
1.60 +
1.61 +/*
1.62 + * Typedefs:
1.63 + */
1.64 +#if ((defined (__GNUC__) && !defined (__MINGW32__)) || defined (_KCC) || defined (__ICC)) && (!defined (__SYMBIAN32__))
1.65 +typedef unsigned short int _Locale_mask_t;
1.66 +#else
1.67 +typedef unsigned int _Locale_mask_t;
1.68 +#endif
1.69 +
1.70 +/* Function called during STLport library load phase. Might contain any
1.71 + * code necessary to the platform localization layer.
1.72 + */
1.73 +void _Locale_init();
1.74 +
1.75 +/* Function called during STLport library unload. Might contain any
1.76 + * code necessary to the platform localization layer.
1.77 + */
1.78 +void _Locale_final();
1.79 +
1.80 +/* Create a category of the locale with the given name.
1.81 + *
1.82 + * The char* argument is a simple (not a composite) locale name, which may
1.83 + * neither be an empty string nor a null pointer.
1.84 + *
1.85 + * These functions return NULL to indicate failure.
1.86 + *
1.87 + * Note These functions return a void* instead of the appropriate
1.88 + * _Locale_* struct because they are used with __acquire_category which
1.89 + * requires that all functions have the same signature.
1.90 + */
1.91 +void * _Locale_ctype_create(const char *, struct _Locale_name_hint*);
1.92 +void * _Locale_numeric_create(const char *, struct _Locale_name_hint*);
1.93 +void * _Locale_time_create(const char *, struct _Locale_name_hint*);
1.94 +void * _Locale_collate_create(const char *, struct _Locale_name_hint*);
1.95 +void * _Locale_monetary_create(const char *, struct _Locale_name_hint*);
1.96 +void * _Locale_messages_create(const char *, struct _Locale_name_hint*);
1.97 +
1.98 +
1.99 +/* Release a category of a locale
1.100 + *
1.101 + * These functions are used to release a category acquired with the
1.102 + * according _Locale_*_create() functions.
1.103 + *
1.104 + * Note: For the same reasons as for the *_create functions, these
1.105 + * take void* instead of the correct types so that they can be used
1.106 + * with __release_category.
1.107 + */
1.108 +void _Locale_ctype_destroy(void *);
1.109 +void _Locale_numeric_destroy(void *);
1.110 +void _Locale_time_destroy(void *);
1.111 +void _Locale_collate_destroy(void *);
1.112 +void _Locale_monetary_destroy(void *);
1.113 +void _Locale_messages_destroy(void *);
1.114 +
1.115 +
1.116 +/*
1.117 + * Returns the name of the user's default locale in each
1.118 + * category, as a null-terminated string. A NULL value
1.119 + * means the default "C" locale.
1.120 + */
1.121 +const char * _Locale_ctype_default(char * __buf);
1.122 +const char * _Locale_numeric_default(char * __buf);
1.123 +const char * _Locale_time_default(char * __buf);
1.124 +const char * _Locale_collate_default(char * __buf);
1.125 +const char * _Locale_monetary_default(char * __buf);
1.126 +const char * _Locale_messages_default(char * __buf);
1.127 +
1.128 +
1.129 +/* Retrieve the name of the given category
1.130 + *
1.131 + * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME
1.132 + * characters. These functions store the name, as a null-terminated
1.133 + * string, in __buf.
1.134 + * TODO: can this fail? How is that signalled then?
1.135 + */
1.136 +char const* _Locale_ctype_name(const void *, char* __buf);
1.137 +char const* _Locale_numeric_name(const void *, char* __buf);
1.138 +char const* _Locale_time_name(const void *, char* __buf);
1.139 +char const* _Locale_collate_name(const void *, char* __buf);
1.140 +char const* _Locale_monetary_name(const void *, char* __buf);
1.141 +char const* _Locale_messages_name(const void *, char* __buf);
1.142 +
1.143 +
1.144 +/*
1.145 + * cname is a (possibly composite) locale name---i.e. a name that can
1.146 + * be passed to setlocale. __buf points to an array large enough to
1.147 + * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these
1.148 + * functions extracts the name of a single category, stores it in buf
1.149 + * as a null-terminated string, and returns buf.
1.150 + */
1.151 +char const* _Locale_extract_ctype_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
1.152 +char const* _Locale_extract_numeric_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
1.153 +char const* _Locale_extract_time_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
1.154 +char const* _Locale_extract_collate_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
1.155 +char const* _Locale_extract_monetary_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
1.156 +char const* _Locale_extract_messages_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
1.157 +
1.158 +/*
1.159 + * The inputs to this function are six null-terminated strings: the
1.160 + * names of a locale's six categories. Locale names for non-standard
1.161 + * categories are taken from __DefaultName.
1.162 + * __buf is a pointer to an array large enough to store at least
1.163 + * _Locale_MAX_COMPOSITE_NAME characters.
1.164 + * This function constructs a (possibly composite) name describing the
1.165 + * locale as a whole, stores that name in buf as a null-terminated
1.166 + * string, and returns buf.
1.167 + */
1.168 +char const* _Locale_compose_name(char *__buf,
1.169 + const char *__Ctype, const char *__Numeric,
1.170 + const char *__Time, const char *__Collate,
1.171 + const char *__Monetary, const char *__Messages,
1.172 + const char *__DefaultName);
1.173 +
1.174 +/* Funstions to improve locale creation process. For some locale API (Win32)
1.175 + * you need to find a locale identification from the name which can be a
1.176 + * rather expensive operation especially if you do so for all facets of a
1.177 + * locale. Those functions can be used to extract from a API dependent facet
1.178 + * struct the information necessary to skip this lookup process for other
1.179 + * facets creation. If not supported those function should return NULL.
1.180 + */
1.181 +struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*);
1.182 +struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*);
1.183 +struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*);
1.184 +struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*);
1.185 +struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*);
1.186 +struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*);
1.187 +
1.188 +/*
1.189 + * FUNCTIONS THAT USE CTYPE
1.190 + */
1.191 +
1.192 +/*
1.193 + * Narrow character functions:
1.194 + */
1.195 +
1.196 +/*
1.197 + * Returns a pointer to the beginning of the ctype table. The table is
1.198 + * at least 257 bytes long; if p is the pointer returned by this
1.199 + * function, then p[c] is valid if c is EOF or if p is any value of
1.200 + * type unsigned char.
1.201 + */
1.202 +const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *);
1.203 +
1.204 +/*
1.205 + * c is either EOF, or an unsigned char value.
1.206 + */
1.207 +int _Locale_toupper(struct _Locale_ctype *, int);
1.208 +int _Locale_tolower(struct _Locale_ctype *, int);
1.209 +
1.210 +
1.211 +# ifndef _STLP_NO_WCHAR_T
1.212 +/*
1.213 + * Wide character functions:
1.214 + */
1.215 +_Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype *, wint_t,
1.216 + _Locale_mask_t);
1.217 +wint_t _Locale_wchar_tolower(struct _Locale_ctype *, wint_t);
1.218 +wint_t _Locale_wchar_toupper(struct _Locale_ctype *, wint_t);
1.219 +# endif
1.220 +
1.221 +# if !defined ( _STLP_NO_MBSTATE_T )
1.222 +
1.223 +/*
1.224 + * Multibyte functions:
1.225 + */
1.226 +
1.227 +int _Locale_mb_cur_max (struct _Locale_ctype *);
1.228 +/*
1.229 + * Returns the number of bytes of the longest allowed multibyte
1.230 + * character in the current encoding.
1.231 + */
1.232 +
1.233 +int _Locale_mb_cur_min (struct _Locale_ctype *);
1.234 +/*
1.235 + * Returns the number of bytes of the shortest allowed multibyte
1.236 + * character in the current encoding.
1.237 + */
1.238 +
1.239 +int _Locale_is_stateless (struct _Locale_ctype *);
1.240 +/*
1.241 + * Returns 1 if the current multibyte encoding is stateless
1.242 + * and does not require the use of an mbstate_t value.
1.243 + */
1.244 +
1.245 +# ifndef _STLP_NO_WCHAR_T
1.246 +wint_t _Locale_btowc(struct _Locale_ctype *, int);
1.247 +int _Locale_wctob(struct _Locale_ctype *, wint_t);
1.248 +
1.249 +/*
1.250 + * Just like btowc and wctob, from 4.6.5.1 of the C standard, Normative
1.251 + * Addendum 1. (And just like widen/narrow, from clause 22 of the C++
1.252 + * standard.)
1.253 + */
1.254 +
1.255 +size_t _Locale_mbtowc(struct _Locale_ctype *,
1.256 + wchar_t *,
1.257 + const char *, size_t,
1.258 + mbstate_t *);
1.259 +
1.260 +/*
1.261 + * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only
1.262 + * important difference is that mbrtowc treats null wide characters
1.263 + * as special, and we don't. Specifically: examines the characters
1.264 + * in [from, from + n), extracts a single wide character, and stores
1.265 + * it in *to. Modifies shift_state if appropriate. The return value,
1.266 + * which is always positive, is the number of characters extracted from
1.267 + * the input sequence. Return value is (size_t) -1 if there was an
1.268 + * encoding error in the input sequence, and (size_t) -2 if
1.269 + * [from, from + n) is correct but not complete. None of the pointer
1.270 + * arguments may be null pointers.
1.271 + */
1.272 +
1.273 +size_t _Locale_wctomb(struct _Locale_ctype *,
1.274 + char *, size_t,
1.275 + const wchar_t,
1.276 + mbstate_t *);
1.277 +
1.278 +/*
1.279 + * Again, very similar to wcrtomb. The differences are that (1) it
1.280 + * doesn't treat null characters as special; and (2) it stores at most
1.281 + * n characters. Converts c to a multibyte sequence, stores that
1.282 + * sequence in the array 'to', and returns the length of the sequence.
1.283 + * Modifies shift_state if appropriate. The return value is (size_t) -1
1.284 + * if c is not a valid wide character, and (size_t) -2 if the length of
1.285 + * the multibyte character sequence is greater than n.
1.286 + */
1.287 +# endif
1.288 +
1.289 +size_t _Locale_unshift(struct _Locale_ctype *,
1.290 + mbstate_t *,
1.291 + char *, size_t, char **);
1.292 +
1.293 +/*
1.294 + * Inserts whatever characters are necessary to restore st to an
1.295 + * initial shift state. Sets *next to buf + m, where m is the number
1.296 + * of characters inserted. (0 <= m <= n.) Returns m to indicate
1.297 + * success, (size_t) -1 to indicate error, (size_t) -2 to indicate
1.298 + * partial success (more than n characters needed). For success or partial
1.299 + * success, sets *next to buf + m.
1.300 + */
1.301 +
1.302 +# endif /* _STLP_NO_MBSTATE_T */
1.303 +
1.304 +/*
1.305 + * FUNCTIONS THAT USE COLLATE
1.306 + */
1.307 +
1.308 +int _Locale_strcmp(struct _Locale_collate *,
1.309 + const char *, size_t,
1.310 + const char *, size_t);
1.311 +# ifndef _STLP_NO_WCHAR_T
1.312 +int _Locale_strwcmp(struct _Locale_collate *,
1.313 + const wchar_t *, size_t,
1.314 + const wchar_t *, size_t);
1.315 +# endif
1.316 +/*
1.317 + * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither
1.318 + * sequence is assumed to be null-terminated, and null characters
1.319 + * aren't special. If the two sequences are the same up through
1.320 + * min(n1, n2), then the sequence that compares less is whichever one
1.321 + * is shorter.
1.322 + */
1.323 +
1.324 +size_t _Locale_strxfrm(struct _Locale_collate *,
1.325 + char *, size_t,
1.326 + const char *, size_t);
1.327 +
1.328 +# ifndef _STLP_NO_WCHAR_T
1.329 +size_t _Locale_strwxfrm(struct _Locale_collate *,
1.330 + wchar_t *, size_t,
1.331 + const wchar_t *, size_t);
1.332 +# endif
1.333 +
1.334 +/*
1.335 + * Creates a transformed version of the string [s2, s2 + n2). The
1.336 + * string may contain embedded null characters; nulls aren't special.
1.337 + * The transformed string begins at s1, and contains at most n1
1.338 + * characters. The return value is the length of the transformed
1.339 + * string. If the return value is greater than n1 then this is an
1.340 + * error condition: it indicates that there wasn't enough space. In
1.341 + * that case, the contents of [s1, s1 + n1) is unspecified.
1.342 +*/
1.343 +
1.344 +/*
1.345 + * FUNCTIONS THAT USE NUMERIC
1.346 + */
1.347 +
1.348 +/*
1.349 + * Equivalent to the first three fields in struct lconv. (C standard,
1.350 + * section 7.4.)
1.351 + */
1.352 +char _Locale_decimal_point(struct _Locale_numeric *);
1.353 +char _Locale_thousands_sep(struct _Locale_numeric *);
1.354 +const char * _Locale_grouping(struct _Locale_numeric *);
1.355 +
1.356 +
1.357 +/*
1.358 + * Return "true" and "false" in English locales, and something
1.359 + * appropriate in non-English locales.
1.360 + */
1.361 +const char * _Locale_true(struct _Locale_numeric *);
1.362 +const char * _Locale_false(struct _Locale_numeric *);
1.363 +
1.364 +
1.365 +/*
1.366 + * FUNCTIONS THAT USE MONETARY
1.367 + */
1.368 +
1.369 +/*
1.370 + * Return the obvious fields of struct lconv.
1.371 + */
1.372 +const char * _Locale_int_curr_symbol(struct _Locale_monetary *);
1.373 +const char * _Locale_currency_symbol(struct _Locale_monetary *);
1.374 +char _Locale_mon_decimal_point(struct _Locale_monetary *);
1.375 +char _Locale_mon_thousands_sep(struct _Locale_monetary *);
1.376 +const char * _Locale_mon_grouping(struct _Locale_monetary *);
1.377 +const char * _Locale_positive_sign(struct _Locale_monetary *);
1.378 +const char * _Locale_negative_sign(struct _Locale_monetary *);
1.379 +char _Locale_int_frac_digits(struct _Locale_monetary *);
1.380 +char _Locale_frac_digits(struct _Locale_monetary *);
1.381 +int _Locale_p_cs_precedes(struct _Locale_monetary *);
1.382 +int _Locale_p_sep_by_space(struct _Locale_monetary *);
1.383 +int _Locale_p_sign_posn(struct _Locale_monetary *);
1.384 +int _Locale_n_cs_precedes(struct _Locale_monetary *);
1.385 +int _Locale_n_sep_by_space(struct _Locale_monetary *);
1.386 +int _Locale_n_sign_posn(struct _Locale_monetary *);
1.387 +
1.388 +
1.389 +/*
1.390 + * FUNCTIONS THAT USE TIME
1.391 + */
1.392 +
1.393 +/*
1.394 + * month is in the range [0, 12).
1.395 + */
1.396 +const char * _Locale_full_monthname(struct _Locale_time *, int);
1.397 +const char * _Locale_abbrev_monthname(struct _Locale_time *, int);
1.398 +
1.399 +
1.400 +/*
1.401 + * day is in the range [0, 7). Sunday is 0.
1.402 + */
1.403 +const char * _Locale_full_dayofweek(struct _Locale_time *, int);
1.404 +const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int);
1.405 +
1.406 +
1.407 +const char * _Locale_d_t_fmt(struct _Locale_time *);
1.408 +const char * _Locale_d_fmt(struct _Locale_time *);
1.409 +const char * _Locale_t_fmt(struct _Locale_time *);
1.410 +const char * _Locale_long_d_t_fmt(struct _Locale_time*);
1.411 +const char * _Locale_long_d_fmt(struct _Locale_time*);
1.412 +
1.413 +const char * _Locale_am_str(struct _Locale_time *);
1.414 +const char * _Locale_pm_str(struct _Locale_time *);
1.415 +const char * _Locale_t_fmt_ampm(struct _Locale_time *);
1.416 +
1.417 +
1.418 +/*
1.419 + * FUNCTIONS THAT USE MESSAGES
1.420 + */
1.421 +
1.422 +# ifdef _STLP_REAL_LOCALE_IMPLEMENTED
1.423 +# if defined (WIN32) || defined (_WIN32)
1.424 +typedef int nl_catd_type;
1.425 +# elif defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__)
1.426 +typedef nl_catd nl_catd_type;
1.427 +# else
1.428 +typedef int nl_catd_type;
1.429 +# endif
1.430 +# else
1.431 +typedef int nl_catd_type;
1.432 +# endif /* _STLP_REAL_LOCALE_IMPLEMENTED */
1.433 +
1.434 +
1.435 +/*
1.436 + * Very similar to catopen, except that it uses the given message
1.437 + * category to determine which catalog to open.
1.438 + */
1.439 +nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*);
1.440 +
1.441 +/* Complementary to _Locale_catopen.
1.442 + * The catalog must be a value that was returned by a previous call
1.443 + * to _Locale_catopen.
1.444 + */
1.445 +void _Locale_catclose(struct _Locale_messages*, nl_catd_type);
1.446 +
1.447 +/*
1.448 + * Returns a string, identified by a set index and a message index,
1.449 + * from an opened message catalog. Returns the supplied default if
1.450 + * no such string exists.
1.451 + */
1.452 +const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type,
1.453 + int, int,const char *);
1.454 +
1.455 +#ifdef __cplusplus
1.456 +}
1.457 +#endif
1.458 +
1.459 +#endif /* _STLP_C_LOCALE_IMPL_H */