1
/*
2
 * Copyright (c) 1999
3
 * Silicon Graphics Computer Systems, Inc.
4
 *
5
 * Copyright (c) 1999
6
 * Boris Fomitchev
7
 *
8
 * This material is provided "as is", with absolutely no warranty expressed
9
 * or implied. Any use is at your own risk.
10
 *
11
 * Permission to use or copy this software for any purpose is hereby granted
12
 * without fee, provided the above notices are retained on all copies.
13
 * Permission to modify the code and to distribute modified code is granted,
14
 * provided the above notices are retained, and a notice that the code was
15
 * modified is included with the above copyright notice.
16
 *
17
 */
18
19
/*
20
 * It is impossible to write the C++ locale library in terms of locales
21
 * as defined in the C standard.  Instead, we write the C++ locale and I/O
22
 * library in terms of a low level C-like interface.  This file defines
23
 * that interface.
24
 *
25
 * The low-level locale interface can't be written portably; there
26
 * must be a version of it for each platform that the C++ library
27
 * is ported to.  On many systems this interface may be a thin wrapper
28
 * for existing functionality.
29
 */
30
31
#ifndef _STLP_C_LOCALE_IMPL_H
32
#define _STLP_C_LOCALE_IMPL_H
33
34
#include "stlport_prefix.h"
35
36
#include <wchar.h> /* for mbstate_t */
37
#include <stddef.h>
38
#include <stl/c_locale.h>
39
40
struct _Locale_name_hint;
41
42
#if defined (_GNU_SOURCE) && defined (__GLIBC__) && \
43
    ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
44
#  define _STLP_USE_GLIBC2_LOCALIZATION
45
#  include <nl_types.h>
46
typedef nl_catd nl_catd_type;
47
#else
48
typedef int nl_catd_type;
49
#endif
50
51
/*
52
 * A number: the maximum length of a simple locale name.
53
 * (i.e. a name like like en_US, as opposed to a name like
54
 * en_US/de_AT/de_AT/es_MX/en_US/en_US) */
55
#define _Locale_MAX_SIMPLE_NAME 256
56
57
#ifdef __cplusplus
58
extern "C" {
59
#endif
60
61
/*
62
 * Typedefs:
63
 */
64
typedef unsigned short int _Locale_mask_t;
65
66
/* Function called during STLport library load phase. Might contain any
67
 * code necessary to the platform localization layer.
68
 */
69
void _Locale_init(void);
70
71
/* Function called during STLport library unload. Might contain any
72
 * code necessary to the platform localization layer.
73
 */
74
void _Locale_final(void);
75
76
/* Create a category of the locale with the given name.
77
 *
78
 * The char* argument is a simple (not a composite) locale name, which may
79
 * neither be an empty string nor a null pointer.
80
 *
81
 * These functions return NULL to indicate failure. Failure reason should be reported
82
 * using the __err_code pointer.
83
 */
84
struct _Locale_ctype* _Locale_ctype_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
85
struct _Locale_codecvt* _Locale_codecvt_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
86
struct _Locale_numeric* _Locale_numeric_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
87
struct _Locale_time* _Locale_time_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
88
struct _Locale_collate* _Locale_collate_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
89
struct _Locale_monetary* _Locale_monetary_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
90
struct _Locale_messages* _Locale_messages_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
91
92
/* Give error reason on failure of one of the _Locale_*_create functions. Available
93
 * reasons are:
94
 * 0: No specific error reason has been reported.
95
 * 1: No platform support for the given facet.
96
 * 2: Unknown locale name
97
 * 3: No platform API for localization support.
98
 * 4: No more memory
99
 */
100
#define _STLP_LOC_UNDEFINED 0
101
#define _STLP_LOC_UNSUPPORTED_FACET_CATEGORY 1
102
#define _STLP_LOC_UNKNOWN_NAME 2
103
#define _STLP_LOC_NO_PLATFORM_SUPPORT 3
104
#define _STLP_LOC_NO_MEMORY 4
105
106
/* Release a category of a locale
107
 *
108
 * These functions are used to release a category acquired with the
109
 * according _Locale_*_create() functions.
110
 */
111
void _Locale_ctype_destroy(struct _Locale_ctype *);
112
void _Locale_codecvt_destroy(struct _Locale_codecvt *);
113
void _Locale_numeric_destroy(struct _Locale_numeric *);
114
void _Locale_time_destroy(struct _Locale_time *);
115
void _Locale_collate_destroy(struct _Locale_collate *);
116
void _Locale_monetary_destroy(struct _Locale_monetary *);
117
void _Locale_messages_destroy(struct _Locale_messages *);
118
119
/*
120
 * Returns the name of the user's default locale in each
121
 * category, as a null-terminated string.  A NULL value
122
 * means the default "C" locale.
123
 */
124
const char * _Locale_ctype_default(char * __buf);
125
const char * _Locale_numeric_default(char * __buf);
126
const char * _Locale_time_default(char * __buf);
127
const char * _Locale_collate_default(char * __buf);
128
const char * _Locale_monetary_default(char * __buf);
129
const char * _Locale_messages_default(char * __buf);
130
131
/* Retrieve the name of the given category
132
 *
133
 * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME
134
 * characters.  These functions store the name, as a null-terminated
135
 * string, in __buf. This function can't fail, at worst name is truncated.
136
 */
137
char const* _Locale_ctype_name(const struct _Locale_ctype *, char* __buf);
138
char const* _Locale_codecvt_name(const struct _Locale_codecvt *, char* __buf);
139
char const* _Locale_numeric_name(const struct _Locale_numeric *, char* __buf);
140
char const* _Locale_time_name(const struct _Locale_time *, char* __buf);
141
char const* _Locale_collate_name(const struct _Locale_collate *, char*  __buf);
142
char const* _Locale_monetary_name(const struct _Locale_monetary *, char* __buf);
143
char const* _Locale_messages_name(const struct _Locale_messages *, char* __buf);
144
145
/*
146
 * cname is a (possibly composite) locale name---i.e. a name that can
147
 * be passed to setlocale. __buf points to an array large enough to
148
 * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these
149
 * functions extracts the name of a single category, stores it in buf
150
 * as a null-terminated string, and returns buf.
151
 */
152
char const* _Locale_extract_ctype_name(const char *cname, char *__buf,
153
                                       struct _Locale_name_hint* __hint, int *__err_code);
154
char const* _Locale_extract_numeric_name(const char *cname, char *__buf,
155
                                         struct _Locale_name_hint* __hint, int *__err_code);
156
char const* _Locale_extract_time_name(const char *cname, char *__buf,
157
                                      struct _Locale_name_hint* __hint, int *__err_code);
158
char const* _Locale_extract_collate_name(const char *cname, char *__buf,
159
                                         struct _Locale_name_hint* __hint, int *__err_code);
160
char const* _Locale_extract_monetary_name(const char *cname, char *__buf,
161
                                          struct _Locale_name_hint* __hint, int *__err_code);
162
char const* _Locale_extract_messages_name(const char *cname, char *__buf,
163
                                          struct _Locale_name_hint* __hint, int *__err_code);
164
165
/* Functions to improve locale creation process. For some locale API (Win32)
166
 * you need to find a locale identification from the name which can be a
167
 * rather expensive operation especially if you do so for all facets of a
168
 * locale. Those functions can be used to extract from a API dependent facet
169
 * struct the information necessary to skip this lookup process for other
170
 * facets creation. If not supported those function should return NULL.
171
 */
172
struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*);
173
struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*);
174
struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*);
175
struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*);
176
struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*);
177
struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*);
178
179
/*
180
 * FUNCTIONS THAT USE CTYPE
181
 */
182
183
/*
184
 * Narrow character functions:
185
 */
186
187
/*
188
 * Returns a pointer to the beginning of the ctype table.  The table is
189
 * at least 257 bytes long; if p is the pointer returned by this
190
 * function, then p[c] is valid if c is EOF or if p is any value of
191
 * type unsigned char.
192
 */
193
const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *);
194
195
/*
196
 * c is either EOF, or an unsigned char value.
197
 */
198
int _Locale_toupper(struct _Locale_ctype *, int /* c */);
199
int _Locale_tolower(struct _Locale_ctype *, int /* c */);
200
201
202
#ifndef _STLP_NO_WCHAR_T
203
/*
204
 * Wide character functions:
205
 */
206
_Locale_mask_t _WLocale_ctype(struct _Locale_ctype *, wint_t, _Locale_mask_t);
207
wint_t _WLocale_tolower(struct _Locale_ctype *, wint_t);
208
wint_t _WLocale_toupper(struct _Locale_ctype *, wint_t);
209
210
/*
211
 * Multibyte functions:
212
 */
213
214
/*
215
 * Returns the number of bytes of the longest allowed multibyte
216
 * character in the current encoding.
217
 */
218
int _WLocale_mb_cur_max(struct _Locale_codecvt *);
219
220
/*
221
 * Returns the number of bytes of the shortest allowed multibyte
222
 * character in the current encoding.
223
 */
224
int _WLocale_mb_cur_min(struct _Locale_codecvt *);
225
226
/*
227
 * Returns 1 if the current multibyte encoding is stateless
228
 * and does not require the use of an mbstate_t value.
229
 */
230
int _WLocale_is_stateless(struct _Locale_codecvt *);
231
232
/*
233
 * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1.  The only
234
 * important difference is that mbrtowc treats null wide characters
235
 * as special, and we don't.  Specifically: examines the characters
236
 * in [from, from + n), extracts a single wide character, and stores
237
 * it in *to.  Modifies shift_state if appropriate.  The return value,
238
 * which is always positive, is the number of characters extracted from
239
 * the input sequence.  Return value is (size_t) -1 if there was an
240
 * encoding error in the input sequence, and (size_t) -2 if
241
 * [from, from + n) is correct but not complete.  None of the pointer
242
 * arguments may be null pointers.
243
 */
244
size_t _WLocale_mbtowc(struct _Locale_codecvt *,
245
                       wchar_t * /* to */,
246
                       const char * /* from */, size_t /* n */,
247
                       mbstate_t *);
248
249
/*
250
 * Again, very similar to wcrtomb.  The differences are that (1) it
251
 * doesn't treat null characters as special; and (2) it stores at most
252
 * n characters.  Converts c to a multibyte sequence, stores that
253
 * sequence in the array 'to', and returns the length of the sequence.
254
 * Modifies shift_state if appropriate.  The return value is (size_t) -1
255
 * if c is not a valid wide character, and (size_t) -2 if the length of
256
 * the multibyte character sequence is greater than n.
257
 */
258
size_t _WLocale_wctomb(struct _Locale_codecvt *,
259
                       char *, size_t,
260
                       const wchar_t,
261
                       mbstate_t *);
262
263
/*
264
 * Inserts whatever characters are necessary to restore st to an
265
 * initial shift state.  Sets *next to buf + m, where m is the number
266
 * of characters inserted.  (0 <= m <= n.)  Returns m to indicate
267
 * success, (size_t) -1 to indicate error, (size_t) -2 to indicate
268
 * partial success (more than n characters needed).  For success or partial
269
 * success, sets *next to buf + m.
270
 */
271
size_t _WLocale_unshift(struct _Locale_codecvt *,
272
                        mbstate_t *,
273
                        char *, size_t, char **);
274
#endif
275
276
/*
277
 * FUNCTIONS THAT USE COLLATE
278
 */
279
280
/*
281
 * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2).  Neither
282
 * sequence is assumed to be null-terminated, and null characters
283
 * aren't special.  If the two sequences are the same up through
284
 * min(n1, n2), then the sequence that compares less is whichever one
285
 * is shorter.
286
 */
287
int _Locale_strcmp(struct _Locale_collate *,
288
                   const char * /* s1 */, size_t /* n1 */,
289
                   const char * /* s2 */, size_t /* n2 */);
290
#ifndef _STLP_NO_WCHAR_T
291
int _WLocale_strcmp(struct _Locale_collate *,
292
                    const wchar_t * /* s1 */, size_t /* n1 */,
293
                    const wchar_t * /* s2 */, size_t /* n2 */);
294
#endif
295
296
/*
297
 * Creates a transformed version of the string [s2, s2 + n2).  The
298
 * string may contain embedded null characters; nulls aren't special.
299
 * The transformed string begins at s1, and contains at most n1
300
 * characters.  The return value is the length of the transformed
301
 * string.  If the return value is greater than n1 then this is an
302
 * error condition: it indicates that there wasn't enough space.  In
303
 * that case, the contents of [s1, s1 + n1) is unspecified.
304
*/
305
size_t _Locale_strxfrm(struct _Locale_collate *,
306
                       char * /* s1 */, size_t /* n1 */,
307
                       const char * /* s2 */, size_t /* n2 */);
308
309
#ifndef _STLP_NO_WCHAR_T
310
size_t _WLocale_strxfrm(struct _Locale_collate *,
311
                        wchar_t * /* s1 */, size_t /* n1 */,
312
                        const wchar_t * /* s2 */, size_t /* n2 */);
313
#endif
314
315
316
/*
317
 * FUNCTIONS THAT USE NUMERIC
318
 */
319
320
/*
321
 * Equivalent to the first three fields in struct lconv.  (C standard,
322
 * section 7.4.)
323
 */
324
char _Locale_decimal_point(struct _Locale_numeric *);
325
char _Locale_thousands_sep(struct _Locale_numeric *);
326
const char * _Locale_grouping(struct _Locale_numeric *);
327
328
#ifndef _STLP_NO_WCHAR_T
329
wchar_t _WLocale_decimal_point(struct _Locale_numeric *);
330
wchar_t _WLocale_thousands_sep(struct _Locale_numeric *);
331
#endif
332
333
/*
334
 * Return "true" and "false" in English locales, and something
335
 * appropriate in non-English locales.
336
 */
337
const char * _Locale_true(struct _Locale_numeric *);
338
const char * _Locale_false(struct _Locale_numeric *);
339
340
#ifndef _STLP_NO_WCHAR_T
341
const wchar_t * _WLocale_true(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */);
342
const wchar_t * _WLocale_false(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */);
343
#endif
344
345
/*
346
 * FUNCTIONS THAT USE MONETARY
347
 */
348
349
/*
350
 * Return the obvious fields of struct lconv.
351
 */
352
const char * _Locale_int_curr_symbol(struct _Locale_monetary *);
353
const char * _Locale_currency_symbol(struct _Locale_monetary *);
354
char         _Locale_mon_decimal_point(struct _Locale_monetary *);
355
char         _Locale_mon_thousands_sep(struct _Locale_monetary *);
356
const char * _Locale_mon_grouping(struct _Locale_monetary *);
357
const char * _Locale_positive_sign(struct _Locale_monetary *);
358
const char * _Locale_negative_sign(struct _Locale_monetary *);
359
char         _Locale_int_frac_digits(struct _Locale_monetary *);
360
char         _Locale_frac_digits(struct _Locale_monetary *);
361
int          _Locale_p_cs_precedes(struct _Locale_monetary *);
362
int          _Locale_p_sep_by_space(struct _Locale_monetary *);
363
int          _Locale_p_sign_posn(struct _Locale_monetary *);
364
int          _Locale_n_cs_precedes(struct _Locale_monetary *);
365
int          _Locale_n_sep_by_space(struct _Locale_monetary *);
366
int          _Locale_n_sign_posn(struct _Locale_monetary *);
367
368
#ifndef _STLP_NO_WCHAR_T
369
const wchar_t * _WLocale_int_curr_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
370
const wchar_t * _WLocale_currency_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
371
wchar_t         _WLocale_mon_decimal_point(struct _Locale_monetary *);
372
wchar_t         _WLocale_mon_thousands_sep(struct _Locale_monetary *);
373
const wchar_t * _WLocale_positive_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
374
const wchar_t * _WLocale_negative_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
375
#endif
376
377
/*
378
 * FUNCTIONS THAT USE TIME
379
 */
380
381
/*
382
 * month is in the range [0, 12).
383
 */
384
const char * _Locale_full_monthname(struct _Locale_time *, int /* month */);
385
const char * _Locale_abbrev_monthname(struct _Locale_time *, int /* month */);
386
387
#ifndef _STLP_NO_WCHAR_T
388
const wchar_t * _WLocale_full_monthname(struct _Locale_time *, int /* month */,
389
                                        wchar_t* /* buf */, size_t /* bufSize */);
390
const wchar_t * _WLocale_abbrev_monthname(struct _Locale_time *, int /* month */,
391
                                          wchar_t* /* buf */, size_t /* bufSize */);
392
#endif
393
394
/*
395
 * day is in the range [0, 7).  Sunday is 0.
396
 */
397
const char * _Locale_full_dayofweek(struct _Locale_time *, int /* day */);
398
const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int /* day */);
399
400
#ifndef _STLP_NO_WCHAR_T
401
const wchar_t * _WLocale_full_dayofweek(struct _Locale_time *, int /* day */,
402
                                        wchar_t* /* buf */, size_t /* bufSize */);
403
const wchar_t * _WLocale_abbrev_dayofweek(struct _Locale_time *, int /* day */,
404
                                          wchar_t* /* buf */, size_t /* bufSize */);
405
#endif
406
407
const char * _Locale_d_t_fmt(struct _Locale_time *);
408
const char * _Locale_d_fmt(struct _Locale_time *);
409
const char * _Locale_t_fmt(struct _Locale_time *);
410
const char * _Locale_long_d_t_fmt(struct _Locale_time*);
411
const char * _Locale_long_d_fmt(struct _Locale_time*);
412
413
const char * _Locale_am_str(struct _Locale_time *);
414
const char * _Locale_pm_str(struct _Locale_time *);
415
416
#ifndef _STLP_NO_WCHAR_T
417
const wchar_t * _WLocale_am_str(struct _Locale_time *,
418
                                wchar_t* /* buf */, size_t /* bufSize */);
419
const wchar_t * _WLocale_pm_str(struct _Locale_time *,
420
                                wchar_t* /* buf */, size_t /* bufSize */);
421
#endif
422
423
/*
424
 * FUNCTIONS THAT USE MESSAGES
425
 */
426
427
/*
428
 * Very similar to catopen, except that it uses the given message
429
 * category to determine which catalog to open.
430
 */
431
nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*);
432
433
/* Complementary to _Locale_catopen.
434
 * The catalog must be a value that was returned by a previous call
435
 * to _Locale_catopen.
436
 */
437
void _Locale_catclose(struct _Locale_messages*, nl_catd_type);
438
439
/*
440
 * Returns a string, identified by a set index and a message index,
441
 * from an opened message catalog.  Returns the supplied default if
442
 * no such string exists.
443
 */
444
const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type,
445
                             int, int,const char *);
446
447
#ifdef __cplusplus
448
}
449
#endif
450
451
#endif /* _STLP_C_LOCALE_IMPL_H */