1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/src/c_locale.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,408 @@
1.4 +/*
1.5 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.6 + * Copyright (c) 1999
1.7 + * Silicon Graphics Computer Systems, Inc.
1.8 + *
1.9 + * Copyright (c) 1999
1.10 + * Boris Fomitchev
1.11 + *
1.12 + * This material is provided "as is", with absolutely no warranty expressed
1.13 + * or implied. Any use is at your own risk.
1.14 + *
1.15 + * Permission to use or copy this software for any purpose is hereby granted
1.16 + * without fee, provided the above notices are retained on all copies.
1.17 + * Permission to modify the code and to distribute modified code is granted,
1.18 + * provided the above notices are retained, and a notice that the code was
1.19 + * modified is included with the above copyright notice.
1.20 + *
1.21 + */
1.22 +
1.23 +/*
1.24 + * It is impossible to write the C++ locale library in terms of locales
1.25 + * as defined in the C standard. Instead, we write the C++ locale and I/O
1.26 + * library in terms of a low level C-like interface. This file defines
1.27 + * that interface.
1.28 + *
1.29 + * The low-level locale interface can't be written portably; there
1.30 + * must be a version of it for each platform that the C++ library
1.31 + * is ported to. On many systems this interface may be a thin wrapper
1.32 + * for existing functionality.
1.33 + */
1.34 +
1.35 +#ifndef _STLP_C_LOCALE_IMPL_H
1.36 +# define _STLP_C_LOCALE_IMPL_H
1.37 +
1.38 +# include <stl/c_locale.h>
1.39 +// # include <wchar.h>
1.40 +# include <stl/_cwchar.h>
1.41 +
1.42 +#define _Locale_MAX_SIMPLE_NAME 256
1.43 +
1.44 +/*
1.45 + * A number: the maximum length of a simple locale name.
1.46 + * (i.e. a name like like en_US, as opposed to a name like
1.47 + * en_US/de_AT/de_AT/es_MX/en_US/en_US) */
1.48 +#define _Locale_MAX_COMPOSITE_NAME 6*(_Locale_MAX_SIMPLE_NAME+3)
1.49 +
1.50 +/*
1.51 + * Maximum length of a composite locale.
1.52 + */
1.53 +
1.54 +#ifdef __cplusplus
1.55 +_STLP_BEGIN_NAMESPACE
1.56 +extern "C" {
1.57 +#endif
1.58 +
1.59 +/*
1.60 + * Typedefs:
1.61 + */
1.62 +
1.63 +#if defined (__GNUC__) || defined (_KCC) || defined(__ICC)
1.64 +typedef unsigned short int _Locale_mask_t;
1.65 +#else
1.66 +typedef unsigned int _Locale_mask_t;
1.67 +#endif
1.68 +
1.69 +void * _Locale_ctype_create(const char *);
1.70 +void * _Locale_numeric_create(const char *);
1.71 +void * _Locale_time_create(const char *);
1.72 +void * _Locale_collate_create(const char *);
1.73 +void * _Locale_monetary_create(const char *);
1.74 +void * _Locale_messages_create(const char *);
1.75 +
1.76 +/*
1.77 + * The char* argument is a simple locale name.
1.78 + * These functions return NULL to indicate failure.
1.79 + * The char* argument is a simple locale name, which may not
1.80 + * be "". These functions return NULL to indicate failure.
1.81 + */
1.82 +
1.83 +const char * _Locale_ctype_default(char * __buf);
1.84 +const char * _Locale_numeric_default(char * __buf);
1.85 +const char * _Locale_time_default(char * __buf);
1.86 +const char * _Locale_collate_default(char * __buf);
1.87 +const char * _Locale_monetary_default(char * __buf);
1.88 +const char * _Locale_messages_default(char * __buf);
1.89 +
1.90 +/*
1.91 + * Returns the name of the user's default locale in each
1.92 + * category, as a null-terminated string. A NULL value
1.93 + * means the default "C" locale.
1.94 + */
1.95 +
1.96 +char * _Locale_ctype_name(const void *, char *);
1.97 +char * _Locale_numeric_name(const void *, char *);
1.98 +char * _Locale_time_name(const void *, char *);
1.99 +char * _Locale_collate_name(const void *, char *);
1.100 +char * _Locale_monetary_name(const void *, char *);
1.101 +char * _Locale_messages_name(const void *, char *);
1.102 +
1.103 +/*
1.104 + * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME
1.105 + * characters. These functions store the name, as a null-terminated
1.106 + * string, in __buf.
1.107 + */
1.108 +
1.109 +void _Locale_ctype_destroy(void *);
1.110 +void _Locale_numeric_destroy(void *);
1.111 +void _Locale_time_destroy(void *);
1.112 +void _Locale_collate_destroy(void *);
1.113 +void _Locale_monetary_destroy(void *);
1.114 +void _Locale_messages_destroy(void *);
1.115 +
1.116 +char * _Locale_extract_ctype_name(const char *cname, char *__buf);
1.117 +char * _Locale_extract_numeric_name(const char *cname, char *__buf);
1.118 +char * _Locale_extract_time_name(const char *cname, char *__buf);
1.119 +char * _Locale_extract_collate_name(const char *cname, char *__buf);
1.120 +char * _Locale_extract_monetary_name(const char *cname, char *__buf);
1.121 +char * _Locale_extract_messages_name(const char *cname, char *__buf);
1.122 +
1.123 +/*
1.124 + * cname is a (possibly composite) locale name---i.e. a name that can
1.125 + * be passed to setlocale. _buf points to an array large enough to
1.126 + * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these
1.127 + * functions extracts the name of a single category, stores it in buf
1.128 + * as a null-terminated string, and returns buf.
1.129 + */
1.130 +
1.131 +char * _Locale_compose_name(char *__buf,
1.132 + const char *__Ctype, const char *__Numeric,
1.133 + const char *__Time, const char *__Collate,
1.134 + const char *__Monetary, const char *__Messages,
1.135 + const char *__DefaultName);
1.136 +
1.137 +/*
1.138 + * The inputs to this function are six null-terminated strings: the
1.139 + * names of a locale's six categories. Locale names for non-standard
1.140 + * categories are taken from __DefaultName.
1.141 + * __buf is a pointer to an array large enough to store at least
1.142 + * _Locale_MAX_COMPOSITE_NAME characters.
1.143 + * This function constructs a (possibly composite) name describing the
1.144 + * locale as a whole, stores that name in buf as a null-terminated
1.145 + * string, and returns buf.
1.146 + */
1.147 +
1.148 +/*
1.149 + * FUNCTIONS THAT USE CTYPE
1.150 + */
1.151 +
1.152 +/*
1.153 + * Narrow character functions:
1.154 + */
1.155 +
1.156 +const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *);
1.157 +
1.158 +/*
1.159 + * Returns a pointer to the beginning of the ctype table. The table is
1.160 + * at least 257 bytes long; if p is the pointer returned by this
1.161 + * function, then p[c] is valid if c is EOF or if p is any value of
1.162 + * type unsigned char.
1.163 + */
1.164 +
1.165 +int _Locale_toupper(struct _Locale_ctype *, int);
1.166 +int _Locale_tolower(struct _Locale_ctype *, int);
1.167 +
1.168 +/*
1.169 + * c is either EOF, or an unsigned char value.
1.170 + */
1.171 +
1.172 +# ifndef _STLP_NO_WCHAR_T
1.173 +/*
1.174 + * Wide character functions:
1.175 + */
1.176 +_Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype *, wint_t,
1.177 + _Locale_mask_t);
1.178 +wint_t _Locale_wchar_tolower(struct _Locale_ctype *, wint_t);
1.179 +wint_t _Locale_wchar_toupper(struct _Locale_ctype *, wint_t);
1.180 +# endif
1.181 +
1.182 +# if !defined ( _STLP_NO_MBSTATE_T )
1.183 +
1.184 +/*
1.185 + * Multibyte functions:
1.186 + */
1.187 +
1.188 +int _Locale_mb_cur_max (struct _Locale_ctype *);
1.189 +/*
1.190 + * Returns the number of bytes of the longest allowed multibyte
1.191 + * character in the current encoding.
1.192 + */
1.193 +
1.194 +int _Locale_mb_cur_min (struct _Locale_ctype *);
1.195 +/*
1.196 + * Returns the number of bytes of the shortest allowed multibyte
1.197 + * character in the current encoding.
1.198 + */
1.199 +
1.200 +int _Locale_is_stateless (struct _Locale_ctype *);
1.201 +/*
1.202 + * Returns 1 if the current multibyte encoding is stateless
1.203 + * and does not require the use of an mbstate_t value.
1.204 + */
1.205 +
1.206 +# ifndef _STLP_NO_WCHAR_T
1.207 +wint_t _Locale_btowc(struct _Locale_ctype *, int);
1.208 +int _Locale_wctob(struct _Locale_ctype *, wint_t);
1.209 +
1.210 +/*
1.211 + * Just like btowc and wctob, from 4.6.5.1 of the C standard, Normative
1.212 + * Addendum 1. (And just like widen/narrow, from clause 22 of the C++
1.213 + * standard.)
1.214 + */
1.215 +
1.216 +size_t _Locale_mbtowc(struct _Locale_ctype *,
1.217 + wchar_t *,size_t,
1.218 + const char *, size_t, int * chars_write,
1.219 + mbstate_t *);
1.220 +
1.221 +/*
1.222 + * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only
1.223 + * important difference is that mbrtowc treats null wide characters
1.224 + * as special, and we don't. Specifically: examines the characters
1.225 + * in [from, from + n), extracts a single wide character, and stores
1.226 + * it in *to. Modifies shift_state if appropriate. The return value,
1.227 + * which is always positive, is the number of characters extracted from
1.228 + * the input sequence. Return value is (size_t) -1 if there was an
1.229 + * encoding error in the input sequence, and (size_t) -2 if
1.230 + * [from, from + n) is correct but not complete. None of the pointer
1.231 + * arguments may be null pointers.
1.232 + */
1.233 +
1.234 +size_t _Locale_wctomb(struct _Locale_ctype *,
1.235 + char *, size_t,
1.236 + const wchar_t,
1.237 + mbstate_t *);
1.238 +
1.239 +/*
1.240 + * Again, very similar to wcrtomb. The differences are that (1) it
1.241 + * doesn't treat null characters as special; and (2) it stores at most
1.242 + * n characters. Converts c to a multibyte sequence, stores that
1.243 + * sequence in the array 'to', and returns the length of the sequence.
1.244 + * Modifies shift_state if appropriate. The return value is (size_t) -1
1.245 + * if c is not a valid wide character, and (size_t) -2 if the length of
1.246 + * the multibyte character sequence is greater than n.
1.247 + */
1.248 +# endif
1.249 +
1.250 +size_t _Locale_unshift(struct _Locale_ctype *,
1.251 + mbstate_t *,
1.252 + char *, size_t, char **);
1.253 +
1.254 +/*
1.255 + * Inserts whatever characters are necessary to restore st to an
1.256 + * initial shift state. Sets *next to buf + m, where m is the number
1.257 + * of characters inserted. (0 <= m <= n.) Returns m to indicate
1.258 + * success, (size_t) -1 to indicate error, (size_t) -2 to indicate
1.259 + * partial success (more than n characters needed). For success or partial
1.260 + * success, sets *next to buf + m.
1.261 + */
1.262 +
1.263 +# endif /* _STLP_NO_MBSTATE_T */
1.264 +
1.265 +/*
1.266 + * FUNCTIONS THAT USE COLLATE
1.267 + */
1.268 +
1.269 +int _Locale_strcmp(struct _Locale_collate *,
1.270 + const char *, size_t,
1.271 + const char *, size_t);
1.272 +# ifndef _STLP_NO_WCHAR_T
1.273 +int _Locale_strwcmp(struct _Locale_collate *,
1.274 + const wchar_t *, size_t,
1.275 + const wchar_t *, size_t);
1.276 +# endif
1.277 +/*
1.278 + * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither
1.279 + * sequence is assumed to be null-terminated, and null characters
1.280 + * aren't special. If the two sequences are the same up through
1.281 + * min(n1, n2), then the sequence that compares less is whichever one
1.282 + * is shorter.
1.283 + */
1.284 +
1.285 +size_t _Locale_strxfrm(struct _Locale_collate *,
1.286 + char *, size_t,
1.287 + const char *, size_t);
1.288 +
1.289 +# ifndef _STLP_NO_WCHAR_T
1.290 +size_t _Locale_strwxfrm(struct _Locale_collate *,
1.291 + wchar_t *, size_t,
1.292 + const wchar_t *, size_t);
1.293 +# endif
1.294 +
1.295 +/*
1.296 + * Creates a transformed version of the string [s2, s2 + n2). The
1.297 + * string may contain embedded null characters; nulls aren't special.
1.298 + * The transformed string begins at s1, and contains at most n1
1.299 + * characters. The return value is the length of the transformed
1.300 + * string. If the return value is greater than n1 then this is an
1.301 + * error condition: it indicates that there wasn't enough space. In
1.302 + * that case, the contents of [s1, s1 + n1) is unspecified.
1.303 +*/
1.304 +
1.305 +/*
1.306 + * FUNCTIONS THAT USE NUMERIC
1.307 + */
1.308 +
1.309 +char _Locale_decimal_point(struct _Locale_numeric *);
1.310 +char _Locale_thousands_sep(struct _Locale_numeric *);
1.311 +const char * _Locale_grouping(struct _Locale_numeric *);
1.312 +
1.313 +/*
1.314 + * Equivalent to the first three fields in struct lconv. (C standard,
1.315 + * section 7.4.)
1.316 + */
1.317 +
1.318 +const char * _Locale_true(struct _Locale_numeric *);
1.319 +const char * _Locale_false(struct _Locale_numeric *);
1.320 +
1.321 +/*
1.322 + * Return "true" and "false" in English locales, and something
1.323 + * appropriate in non-English locales.
1.324 + */
1.325 +
1.326 +/*
1.327 + * FUNCTIONS THAT USE MONETARY
1.328 + */
1.329 +
1.330 +const char * _Locale_int_curr_symbol(struct _Locale_monetary *);
1.331 +const char * _Locale_currency_symbol(struct _Locale_monetary *);
1.332 +char _Locale_mon_decimal_point(struct _Locale_monetary *);
1.333 +char _Locale_mon_thousands_sep(struct _Locale_monetary *);
1.334 +const char * _Locale_mon_grouping(struct _Locale_monetary *);
1.335 +const char * _Locale_positive_sign(struct _Locale_monetary *);
1.336 +const char * _Locale_negative_sign(struct _Locale_monetary *);
1.337 +char _Locale_int_frac_digits(struct _Locale_monetary *);
1.338 +char _Locale_frac_digits(struct _Locale_monetary *);
1.339 +int _Locale_p_cs_precedes(struct _Locale_monetary *);
1.340 +int _Locale_p_sep_by_space(struct _Locale_monetary *);
1.341 +int _Locale_p_sign_posn(struct _Locale_monetary *);
1.342 +int _Locale_n_cs_precedes(struct _Locale_monetary *);
1.343 +int _Locale_n_sep_by_space(struct _Locale_monetary *);
1.344 +int _Locale_n_sign_posn(struct _Locale_monetary *);
1.345 +
1.346 +/*
1.347 + * Return the obvious fields of struct lconv.
1.348 + */
1.349 +
1.350 +/*
1.351 + * FUNCTIONS THAT USE TIME
1.352 + */
1.353 +
1.354 +const char * _Locale_full_monthname(struct _Locale_time *, int);
1.355 +const char * _Locale_abbrev_monthname(struct _Locale_time *, int);
1.356 +
1.357 +/*
1.358 + * month is in the range [0, 12).
1.359 + */
1.360 +
1.361 +const char * _Locale_full_dayofweek(struct _Locale_time *, int);
1.362 +const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int);
1.363 +
1.364 +/*
1.365 + * day is in the range [0, 7). Sunday is 0.
1.366 + */
1.367 +
1.368 +const char * _Locale_d_t_fmt(struct _Locale_time *);
1.369 +const char * _Locale_d_fmt(struct _Locale_time *);
1.370 +const char * _Locale_t_fmt(struct _Locale_time *);
1.371 +const char * _Locale_long_d_t_fmt(struct _Locale_time*);
1.372 +const char * _Locale_long_d_fmt(struct _Locale_time*);
1.373 +
1.374 +const char * _Locale_am_str(struct _Locale_time *);
1.375 +const char * _Locale_pm_str(struct _Locale_time *);
1.376 +const char * _Locale_t_fmt_ampm(struct _Locale_time *);
1.377 +
1.378 +
1.379 +/*
1.380 + * FUNCTIONS THAT USE MESSAGES
1.381 + */
1.382 +
1.383 +int _Locale_catopen(struct _Locale_messages*, const char*);
1.384 +
1.385 +/*
1.386 + * Very similar to catopen, except that it uses L to determine
1.387 + * which catalog to open.
1.388 + */
1.389 +
1.390 +void _Locale_catclose(struct _Locale_messages*, int);
1.391 +
1.392 +/*
1.393 + * catalog is a value that was returned by a previous call to
1.394 + * _Locale_catopen
1.395 + */
1.396 +
1.397 +const char * _Locale_catgets(struct _Locale_messages *, int,
1.398 + int, int,const char *);
1.399 +
1.400 +/*
1.401 + * Returns a string, identified by a set index and a message index,
1.402 + * from an opened message catalog. Returns default if no such
1.403 + * string exists.
1.404 + */
1.405 +
1.406 +# ifdef __cplusplus
1.407 +}
1.408 +_STLP_END_NAMESPACE
1.409 +# endif
1.410 +
1.411 +# endif /* _STLP_C_LOCALE_IMPL_H */