|
1 /* |
|
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. |
|
3 * Copyright (c) 1999 |
|
4 * Silicon Graphics Computer Systems, Inc. |
|
5 * |
|
6 * Copyright (c) 1999 |
|
7 * Boris Fomitchev |
|
8 * |
|
9 * This material is provided "as is", with absolutely no warranty expressed |
|
10 * or implied. Any use is at your own risk. |
|
11 * |
|
12 * Permission to use or copy this software for any purpose is hereby granted |
|
13 * without fee, provided the above notices are retained on all copies. |
|
14 * Permission to modify the code and to distribute modified code is granted, |
|
15 * provided the above notices are retained, and a notice that the code was |
|
16 * modified is included with the above copyright notice. |
|
17 * |
|
18 */ |
|
19 |
|
20 /* |
|
21 * It is impossible to write the C++ locale library in terms of locales |
|
22 * as defined in the C standard. Instead, we write the C++ locale and I/O |
|
23 * library in terms of a low level C-like interface. This file defines |
|
24 * that interface. |
|
25 * |
|
26 * The low-level locale interface can't be written portably; there |
|
27 * must be a version of it for each platform that the C++ library |
|
28 * is ported to. On many systems this interface may be a thin wrapper |
|
29 * for existing functionality. |
|
30 */ |
|
31 |
|
32 #ifndef _STLP_C_LOCALE_IMPL_H |
|
33 # define _STLP_C_LOCALE_IMPL_H |
|
34 |
|
35 # include <stl/c_locale.h> |
|
36 // # include <wchar.h> |
|
37 # include <stl/_cwchar.h> |
|
38 |
|
39 #define _Locale_MAX_SIMPLE_NAME 256 |
|
40 |
|
41 /* |
|
42 * A number: the maximum length of a simple locale name. |
|
43 * (i.e. a name like like en_US, as opposed to a name like |
|
44 * en_US/de_AT/de_AT/es_MX/en_US/en_US) */ |
|
45 #define _Locale_MAX_COMPOSITE_NAME 6*(_Locale_MAX_SIMPLE_NAME+3) |
|
46 |
|
47 /* |
|
48 * Maximum length of a composite locale. |
|
49 */ |
|
50 |
|
51 #ifdef __cplusplus |
|
52 _STLP_BEGIN_NAMESPACE |
|
53 extern "C" { |
|
54 #endif |
|
55 |
|
56 /* |
|
57 * Typedefs: |
|
58 */ |
|
59 |
|
60 #if defined (__GNUC__) || defined (_KCC) || defined(__ICC) |
|
61 typedef unsigned short int _Locale_mask_t; |
|
62 #else |
|
63 typedef unsigned int _Locale_mask_t; |
|
64 #endif |
|
65 |
|
66 void * _Locale_ctype_create(const char *); |
|
67 void * _Locale_numeric_create(const char *); |
|
68 void * _Locale_time_create(const char *); |
|
69 void * _Locale_collate_create(const char *); |
|
70 void * _Locale_monetary_create(const char *); |
|
71 void * _Locale_messages_create(const char *); |
|
72 |
|
73 /* |
|
74 * The char* argument is a simple locale name. |
|
75 * These functions return NULL to indicate failure. |
|
76 * The char* argument is a simple locale name, which may not |
|
77 * be "". These functions return NULL to indicate failure. |
|
78 */ |
|
79 |
|
80 const char * _Locale_ctype_default(char * __buf); |
|
81 const char * _Locale_numeric_default(char * __buf); |
|
82 const char * _Locale_time_default(char * __buf); |
|
83 const char * _Locale_collate_default(char * __buf); |
|
84 const char * _Locale_monetary_default(char * __buf); |
|
85 const char * _Locale_messages_default(char * __buf); |
|
86 |
|
87 /* |
|
88 * Returns the name of the user's default locale in each |
|
89 * category, as a null-terminated string. A NULL value |
|
90 * means the default "C" locale. |
|
91 */ |
|
92 |
|
93 char * _Locale_ctype_name(const void *, char *); |
|
94 char * _Locale_numeric_name(const void *, char *); |
|
95 char * _Locale_time_name(const void *, char *); |
|
96 char * _Locale_collate_name(const void *, char *); |
|
97 char * _Locale_monetary_name(const void *, char *); |
|
98 char * _Locale_messages_name(const void *, char *); |
|
99 |
|
100 /* |
|
101 * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME |
|
102 * characters. These functions store the name, as a null-terminated |
|
103 * string, in __buf. |
|
104 */ |
|
105 |
|
106 void _Locale_ctype_destroy(void *); |
|
107 void _Locale_numeric_destroy(void *); |
|
108 void _Locale_time_destroy(void *); |
|
109 void _Locale_collate_destroy(void *); |
|
110 void _Locale_monetary_destroy(void *); |
|
111 void _Locale_messages_destroy(void *); |
|
112 |
|
113 char * _Locale_extract_ctype_name(const char *cname, char *__buf); |
|
114 char * _Locale_extract_numeric_name(const char *cname, char *__buf); |
|
115 char * _Locale_extract_time_name(const char *cname, char *__buf); |
|
116 char * _Locale_extract_collate_name(const char *cname, char *__buf); |
|
117 char * _Locale_extract_monetary_name(const char *cname, char *__buf); |
|
118 char * _Locale_extract_messages_name(const char *cname, char *__buf); |
|
119 |
|
120 /* |
|
121 * cname is a (possibly composite) locale name---i.e. a name that can |
|
122 * be passed to setlocale. _buf points to an array large enough to |
|
123 * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these |
|
124 * functions extracts the name of a single category, stores it in buf |
|
125 * as a null-terminated string, and returns buf. |
|
126 */ |
|
127 |
|
128 char * _Locale_compose_name(char *__buf, |
|
129 const char *__Ctype, const char *__Numeric, |
|
130 const char *__Time, const char *__Collate, |
|
131 const char *__Monetary, const char *__Messages, |
|
132 const char *__DefaultName); |
|
133 |
|
134 /* |
|
135 * The inputs to this function are six null-terminated strings: the |
|
136 * names of a locale's six categories. Locale names for non-standard |
|
137 * categories are taken from __DefaultName. |
|
138 * __buf is a pointer to an array large enough to store at least |
|
139 * _Locale_MAX_COMPOSITE_NAME characters. |
|
140 * This function constructs a (possibly composite) name describing the |
|
141 * locale as a whole, stores that name in buf as a null-terminated |
|
142 * string, and returns buf. |
|
143 */ |
|
144 |
|
145 /* |
|
146 * FUNCTIONS THAT USE CTYPE |
|
147 */ |
|
148 |
|
149 /* |
|
150 * Narrow character functions: |
|
151 */ |
|
152 |
|
153 const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *); |
|
154 |
|
155 /* |
|
156 * Returns a pointer to the beginning of the ctype table. The table is |
|
157 * at least 257 bytes long; if p is the pointer returned by this |
|
158 * function, then p[c] is valid if c is EOF or if p is any value of |
|
159 * type unsigned char. |
|
160 */ |
|
161 |
|
162 int _Locale_toupper(struct _Locale_ctype *, int); |
|
163 int _Locale_tolower(struct _Locale_ctype *, int); |
|
164 |
|
165 /* |
|
166 * c is either EOF, or an unsigned char value. |
|
167 */ |
|
168 |
|
169 # ifndef _STLP_NO_WCHAR_T |
|
170 /* |
|
171 * Wide character functions: |
|
172 */ |
|
173 _Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype *, wint_t, |
|
174 _Locale_mask_t); |
|
175 wint_t _Locale_wchar_tolower(struct _Locale_ctype *, wint_t); |
|
176 wint_t _Locale_wchar_toupper(struct _Locale_ctype *, wint_t); |
|
177 # endif |
|
178 |
|
179 # if !defined ( _STLP_NO_MBSTATE_T ) |
|
180 |
|
181 /* |
|
182 * Multibyte functions: |
|
183 */ |
|
184 |
|
185 int _Locale_mb_cur_max (struct _Locale_ctype *); |
|
186 /* |
|
187 * Returns the number of bytes of the longest allowed multibyte |
|
188 * character in the current encoding. |
|
189 */ |
|
190 |
|
191 int _Locale_mb_cur_min (struct _Locale_ctype *); |
|
192 /* |
|
193 * Returns the number of bytes of the shortest allowed multibyte |
|
194 * character in the current encoding. |
|
195 */ |
|
196 |
|
197 int _Locale_is_stateless (struct _Locale_ctype *); |
|
198 /* |
|
199 * Returns 1 if the current multibyte encoding is stateless |
|
200 * and does not require the use of an mbstate_t value. |
|
201 */ |
|
202 |
|
203 # ifndef _STLP_NO_WCHAR_T |
|
204 wint_t _Locale_btowc(struct _Locale_ctype *, int); |
|
205 int _Locale_wctob(struct _Locale_ctype *, wint_t); |
|
206 |
|
207 /* |
|
208 * Just like btowc and wctob, from 4.6.5.1 of the C standard, Normative |
|
209 * Addendum 1. (And just like widen/narrow, from clause 22 of the C++ |
|
210 * standard.) |
|
211 */ |
|
212 |
|
213 size_t _Locale_mbtowc(struct _Locale_ctype *, |
|
214 wchar_t *,size_t, |
|
215 const char *, size_t, int * chars_write, |
|
216 mbstate_t *); |
|
217 |
|
218 /* |
|
219 * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only |
|
220 * important difference is that mbrtowc treats null wide characters |
|
221 * as special, and we don't. Specifically: examines the characters |
|
222 * in [from, from + n), extracts a single wide character, and stores |
|
223 * it in *to. Modifies shift_state if appropriate. The return value, |
|
224 * which is always positive, is the number of characters extracted from |
|
225 * the input sequence. Return value is (size_t) -1 if there was an |
|
226 * encoding error in the input sequence, and (size_t) -2 if |
|
227 * [from, from + n) is correct but not complete. None of the pointer |
|
228 * arguments may be null pointers. |
|
229 */ |
|
230 |
|
231 size_t _Locale_wctomb(struct _Locale_ctype *, |
|
232 char *, size_t, |
|
233 const wchar_t, |
|
234 mbstate_t *); |
|
235 |
|
236 /* |
|
237 * Again, very similar to wcrtomb. The differences are that (1) it |
|
238 * doesn't treat null characters as special; and (2) it stores at most |
|
239 * n characters. Converts c to a multibyte sequence, stores that |
|
240 * sequence in the array 'to', and returns the length of the sequence. |
|
241 * Modifies shift_state if appropriate. The return value is (size_t) -1 |
|
242 * if c is not a valid wide character, and (size_t) -2 if the length of |
|
243 * the multibyte character sequence is greater than n. |
|
244 */ |
|
245 # endif |
|
246 |
|
247 size_t _Locale_unshift(struct _Locale_ctype *, |
|
248 mbstate_t *, |
|
249 char *, size_t, char **); |
|
250 |
|
251 /* |
|
252 * Inserts whatever characters are necessary to restore st to an |
|
253 * initial shift state. Sets *next to buf + m, where m is the number |
|
254 * of characters inserted. (0 <= m <= n.) Returns m to indicate |
|
255 * success, (size_t) -1 to indicate error, (size_t) -2 to indicate |
|
256 * partial success (more than n characters needed). For success or partial |
|
257 * success, sets *next to buf + m. |
|
258 */ |
|
259 |
|
260 # endif /* _STLP_NO_MBSTATE_T */ |
|
261 |
|
262 /* |
|
263 * FUNCTIONS THAT USE COLLATE |
|
264 */ |
|
265 |
|
266 int _Locale_strcmp(struct _Locale_collate *, |
|
267 const char *, size_t, |
|
268 const char *, size_t); |
|
269 # ifndef _STLP_NO_WCHAR_T |
|
270 int _Locale_strwcmp(struct _Locale_collate *, |
|
271 const wchar_t *, size_t, |
|
272 const wchar_t *, size_t); |
|
273 # endif |
|
274 /* |
|
275 * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither |
|
276 * sequence is assumed to be null-terminated, and null characters |
|
277 * aren't special. If the two sequences are the same up through |
|
278 * min(n1, n2), then the sequence that compares less is whichever one |
|
279 * is shorter. |
|
280 */ |
|
281 |
|
282 size_t _Locale_strxfrm(struct _Locale_collate *, |
|
283 char *, size_t, |
|
284 const char *, size_t); |
|
285 |
|
286 # ifndef _STLP_NO_WCHAR_T |
|
287 size_t _Locale_strwxfrm(struct _Locale_collate *, |
|
288 wchar_t *, size_t, |
|
289 const wchar_t *, size_t); |
|
290 # endif |
|
291 |
|
292 /* |
|
293 * Creates a transformed version of the string [s2, s2 + n2). The |
|
294 * string may contain embedded null characters; nulls aren't special. |
|
295 * The transformed string begins at s1, and contains at most n1 |
|
296 * characters. The return value is the length of the transformed |
|
297 * string. If the return value is greater than n1 then this is an |
|
298 * error condition: it indicates that there wasn't enough space. In |
|
299 * that case, the contents of [s1, s1 + n1) is unspecified. |
|
300 */ |
|
301 |
|
302 /* |
|
303 * FUNCTIONS THAT USE NUMERIC |
|
304 */ |
|
305 |
|
306 char _Locale_decimal_point(struct _Locale_numeric *); |
|
307 char _Locale_thousands_sep(struct _Locale_numeric *); |
|
308 const char * _Locale_grouping(struct _Locale_numeric *); |
|
309 |
|
310 /* |
|
311 * Equivalent to the first three fields in struct lconv. (C standard, |
|
312 * section 7.4.) |
|
313 */ |
|
314 |
|
315 const char * _Locale_true(struct _Locale_numeric *); |
|
316 const char * _Locale_false(struct _Locale_numeric *); |
|
317 |
|
318 /* |
|
319 * Return "true" and "false" in English locales, and something |
|
320 * appropriate in non-English locales. |
|
321 */ |
|
322 |
|
323 /* |
|
324 * FUNCTIONS THAT USE MONETARY |
|
325 */ |
|
326 |
|
327 const char * _Locale_int_curr_symbol(struct _Locale_monetary *); |
|
328 const char * _Locale_currency_symbol(struct _Locale_monetary *); |
|
329 char _Locale_mon_decimal_point(struct _Locale_monetary *); |
|
330 char _Locale_mon_thousands_sep(struct _Locale_monetary *); |
|
331 const char * _Locale_mon_grouping(struct _Locale_monetary *); |
|
332 const char * _Locale_positive_sign(struct _Locale_monetary *); |
|
333 const char * _Locale_negative_sign(struct _Locale_monetary *); |
|
334 char _Locale_int_frac_digits(struct _Locale_monetary *); |
|
335 char _Locale_frac_digits(struct _Locale_monetary *); |
|
336 int _Locale_p_cs_precedes(struct _Locale_monetary *); |
|
337 int _Locale_p_sep_by_space(struct _Locale_monetary *); |
|
338 int _Locale_p_sign_posn(struct _Locale_monetary *); |
|
339 int _Locale_n_cs_precedes(struct _Locale_monetary *); |
|
340 int _Locale_n_sep_by_space(struct _Locale_monetary *); |
|
341 int _Locale_n_sign_posn(struct _Locale_monetary *); |
|
342 |
|
343 /* |
|
344 * Return the obvious fields of struct lconv. |
|
345 */ |
|
346 |
|
347 /* |
|
348 * FUNCTIONS THAT USE TIME |
|
349 */ |
|
350 |
|
351 const char * _Locale_full_monthname(struct _Locale_time *, int); |
|
352 const char * _Locale_abbrev_monthname(struct _Locale_time *, int); |
|
353 |
|
354 /* |
|
355 * month is in the range [0, 12). |
|
356 */ |
|
357 |
|
358 const char * _Locale_full_dayofweek(struct _Locale_time *, int); |
|
359 const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int); |
|
360 |
|
361 /* |
|
362 * day is in the range [0, 7). Sunday is 0. |
|
363 */ |
|
364 |
|
365 const char * _Locale_d_t_fmt(struct _Locale_time *); |
|
366 const char * _Locale_d_fmt(struct _Locale_time *); |
|
367 const char * _Locale_t_fmt(struct _Locale_time *); |
|
368 const char * _Locale_long_d_t_fmt(struct _Locale_time*); |
|
369 const char * _Locale_long_d_fmt(struct _Locale_time*); |
|
370 |
|
371 const char * _Locale_am_str(struct _Locale_time *); |
|
372 const char * _Locale_pm_str(struct _Locale_time *); |
|
373 const char * _Locale_t_fmt_ampm(struct _Locale_time *); |
|
374 |
|
375 |
|
376 /* |
|
377 * FUNCTIONS THAT USE MESSAGES |
|
378 */ |
|
379 |
|
380 int _Locale_catopen(struct _Locale_messages*, const char*); |
|
381 |
|
382 /* |
|
383 * Very similar to catopen, except that it uses L to determine |
|
384 * which catalog to open. |
|
385 */ |
|
386 |
|
387 void _Locale_catclose(struct _Locale_messages*, int); |
|
388 |
|
389 /* |
|
390 * catalog is a value that was returned by a previous call to |
|
391 * _Locale_catopen |
|
392 */ |
|
393 |
|
394 const char * _Locale_catgets(struct _Locale_messages *, int, |
|
395 int, int,const char *); |
|
396 |
|
397 /* |
|
398 * Returns a string, identified by a set index and a message index, |
|
399 * from an opened message catalog. Returns default if no such |
|
400 * string exists. |
|
401 */ |
|
402 |
|
403 # ifdef __cplusplus |
|
404 } |
|
405 _STLP_END_NAMESPACE |
|
406 # endif |
|
407 |
|
408 # endif /* _STLP_C_LOCALE_IMPL_H */ |