c_locale.h

00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999 
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted 
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */ 
00018 
00019 /*
00020  * It is impossible to write the C++ locale library in terms of locales
00021  * as defined in the C standard.  Instead, we write the C++ locale and I/O
00022  * library in terms of a low level C-like interface.  This file defines
00023  * that interface.
00024  *
00025  * The low-level locale interface can't be written portably; there
00026  * must be a version of it for each platform that the C++ library
00027  * is ported to.  On many systems this interface may be a thin wrapper
00028  * for existing functionality.
00029  */
00030 
00031 #ifndef _STLP_C_LOCALE_IMPL_H
00032 # define _STLP_C_LOCALE_IMPL_H
00033 
00034 # include <stl/c_locale.h>
00035 // # include <wchar.h>
00036 # include <stl/_cwchar.h>
00037 
00038 #define _Locale_MAX_SIMPLE_NAME 256
00039 
00040 /*
00041  * A number: the maximum length of a simple locale name.
00042  * (i.e. a name like like en_US, as opposed to a name like
00043  * en_US/de_AT/de_AT/es_MX/en_US/en_US) */
00044 #define _Locale_MAX_COMPOSITE_NAME 6*(_Locale_MAX_SIMPLE_NAME+3)
00045 
00046 /*
00047  * Maximum length of a composite locale.
00048  */
00049 
00050 #ifdef __cplusplus
00051 _STLP_BEGIN_NAMESPACE
00052 extern "C" {
00053 #endif
00054 
00055 /*
00056  * Typedefs:
00057  */
00058 
00059 #if (defined (__GNUC__) && !defined (__SYMBIAN32__)) || defined (_KCC)
00060 typedef unsigned short int _Locale_mask_t;
00061 #else
00062 typedef unsigned int _Locale_mask_t;
00063 #endif
00064 
00065 void * _Locale_ctype_create(const char *);
00066 void * _Locale_numeric_create(const char *);
00067 void * _Locale_time_create(const char *);
00068 void * _Locale_collate_create(const char *);
00069 void * _Locale_monetary_create(const char *);
00070 void * _Locale_messages_create(const char *);
00071 
00072 /*
00073  * The char* argument is a simple locale name.
00074  * These functions return NULL to indicate failure.
00075  * The char* argument is a simple locale name, which may not
00076  * be "".  These functions return NULL to indicate failure.
00077  */
00078 
00079 const char * _Locale_ctype_default(char * __buf);
00080 const char * _Locale_numeric_default(char * __buf);
00081 const char * _Locale_time_default(char * __buf);
00082 const char * _Locale_collate_default(char * __buf);
00083 const char * _Locale_monetary_default(char * __buf);
00084 const char * _Locale_messages_default(char * __buf);
00085 
00086 /*
00087  * Returns the name of the user's default locale in each
00088  * category, as a null-terminated string.  A NULL value
00089  * means the default "C" locale.
00090  */
00091 
00092 char * _Locale_ctype_name(const void *, char *);
00093 char * _Locale_numeric_name(const void *, char *);
00094 char * _Locale_time_name(const void *, char *);
00095 char * _Locale_collate_name(const void *, char *);
00096 char * _Locale_monetary_name(const void *, char *);
00097 char * _Locale_messages_name(const void *, char *);
00098 
00099 /*
00100  * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME
00101  * characters.  These functions store the name, as a null-terminated
00102  * string, in __buf.
00103  */
00104 
00105 void _Locale_ctype_destroy(void *);
00106 void _Locale_numeric_destroy(void *);
00107 void _Locale_time_destroy(void *);
00108 void _Locale_collate_destroy(void *);
00109 void _Locale_monetary_destroy(void *);
00110 void _Locale_messages_destroy(void *);
00111 
00112 char * _Locale_extract_ctype_name(const char *cname, char *__buf);
00113 char * _Locale_extract_numeric_name(const char *cname, char *__buf);
00114 char * _Locale_extract_time_name(const char *cname, char *__buf);
00115 char * _Locale_extract_collate_name(const char *cname, char *__buf);
00116 char * _Locale_extract_monetary_name(const char *cname, char *__buf);
00117 char * _Locale_extract_messages_name(const char *cname, char *__buf);
00118 
00119 /*
00120  * cname is a (possibly composite) locale name---i.e. a name that can
00121  * be passed to setlocale.  _buf points to an array large enough to
00122  * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these
00123  * functions extracts the name of a single category, stores it in buf
00124  * as a null-terminated string, and returns buf.
00125  */
00126 
00127 char * _Locale_compose_name(char *__buf,
00128                             const char *__Ctype, const char *__Numeric,
00129                             const char *__Time, const char *__Collate,
00130                             const char *__Monetary, const char *__Messages);
00131 
00132 /*
00133  * The inputs to this function are six null-terminated strings: the
00134  * names of a locale's six categories.  __buf is a pointer to an array
00135  * large enough to store at least _Locale_MAX_COMPOSITE_NAME characters.
00136  * This function constructs a (possibly composite) name describing the
00137  * locale as a whole, stores that name in buf as a null-terminated
00138  * string, and returns buf.
00139  */
00140 
00141 /*
00142  * FUNCTIONS THAT USE CTYPE
00143  */
00144 
00145 /*
00146  * Narrow character functions:
00147  */
00148 
00149 _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *);
00150 
00151 /*
00152  * Returns a pointer to the beginning of the ctype table.  The table is
00153  * at least 257 bytes long; if p is the pointer returned by this
00154  * function, then p[c] is valid if c is EOF or if p is any value of
00155  * type unsigned char.
00156  */
00157 
00158 int _Locale_toupper(struct _Locale_ctype *, int);
00159 int _Locale_tolower(struct _Locale_ctype *, int);
00160 
00161 /*
00162  * c is either EOF, or an unsigned char value.
00163  */
00164 
00165 # ifndef _STLP_NO_WCHAR_T
00166 /*
00167  * Wide character functions:
00168  */
00169 _Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype *, wint_t);
00170 wint_t _Locale_wchar_tolower(struct _Locale_ctype *, wint_t);
00171 wint_t _Locale_wchar_toupper(struct _Locale_ctype *, wint_t);
00172 # endif
00173 
00174 # if !defined ( _STLP_NO_MBSTATE_T )
00175 
00176 /*
00177  * Multibyte functions:
00178  */
00179 
00180 int _Locale_mb_cur_max (struct _Locale_ctype *);
00181 /*
00182  * Returns the number of bytes of the longest allowed multibyte
00183  * character in the current encoding.
00184  */
00185 
00186 int _Locale_mb_cur_min (struct _Locale_ctype *);
00187 /*
00188  * Returns the number of bytes of the shortest allowed multibyte
00189  * character in the current encoding.
00190  */
00191 
00192 int _Locale_is_stateless (struct _Locale_ctype *);
00193 /*
00194  * Returns 1 if the current multibyte encoding is stateless
00195  * and does not require the use of an mbstate_t value.
00196  */
00197 
00198 # ifndef _STLP_NO_WCHAR_T
00199 wint_t _Locale_btowc(struct _Locale_ctype *, int);
00200 int _Locale_wctob(struct _Locale_ctype *, wint_t);
00201 
00202 /*
00203  * Just like btowc and wctob, from 4.6.5.1 of the C standard, Normative
00204  * Addendum 1.  (And just like widen/narrow, from clause 22 of the C++
00205  * standard.)
00206  */
00207 
00208 size_t _Locale_mbtowc(struct _Locale_ctype *,
00209                       wchar_t *,
00210                       const char *, size_t,
00211                       mbstate_t *);
00212 
00213 /*
00214  * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1.  The only
00215  * important difference is that mbrtowc treats null wide characters
00216  * as special, and we don't.  Specifically: examines the characters
00217  * in [from, from + n), extracts a single wide character, and stores
00218  * it in *to.  Modifies shift_state if appropriate.  The return value,
00219  * which is always positive, is the number of characters extracted from
00220  * the input sequence.  Return value is (size_t) -1 if there was an
00221  * encoding error in the input sequence, and (size_t) -2 if
00222  * [from, from + n) is correct but not complete.  None of the pointer
00223  * arguments may be null pointers.
00224  */
00225 
00226 size_t _Locale_wctomb(struct _Locale_ctype *,
00227                       char *, size_t,
00228                       const wchar_t,
00229                       mbstate_t *);
00230 
00231 /*
00232  * Again, very similar to wcrtomb.  The differences are that (1) it
00233  * doesn't treat null characters as special; and (2) it stores at most
00234  * n characters.  Converts c to a multibyte sequence, stores that
00235  * sequence in the array 'to', and returns the length of the sequence.
00236  * Modifies shift_state if appropriate.  The return value is (size_t) -1
00237  * if c is not a valid wide character, and (size_t) -2 if the length of
00238  * the multibyte character sequence is greater than n.
00239  */
00240 # endif
00241 
00242 size_t _Locale_unshift(struct _Locale_ctype *,
00243                        mbstate_t *,
00244                        char *, size_t, char **);
00245 
00246 /*
00247  * Inserts whatever characters are necessary to restore st to an
00248  * initial shift state.  Sets *next to buf + m, where m is the number
00249  * of characters inserted.  (0 <= m <= n.)  Returns m to indicate
00250  * success, (size_t) -1 to indicate error, (size_t) -2 to indicate
00251  * partial success (more than n characters needed).  For success or partial
00252  * success, sets *next to buf + m.
00253  */
00254 
00255 # endif /*  _STLP_NO_MBSTATE_T */
00256 
00257 /*
00258  * FUNCTIONS THAT USE COLLATE
00259  */
00260 
00261 int _Locale_strcmp(struct _Locale_collate *,
00262                    const char *, size_t,
00263                    const char *, size_t);
00264 # ifndef _STLP_NO_WCHAR_T
00265 int _Locale_strwcmp(struct _Locale_collate *,
00266                     const wchar_t *, size_t,
00267                     const wchar_t *, size_t);
00268 # endif
00269 /*
00270  * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2).  Neither
00271  * sequence is assumed to be null-terminated, and null characters
00272  * aren't special.  If the two sequences are the same up through
00273  * min(n1, n2), then the sequence that compares less is whichever one
00274  * is shorter.
00275  */
00276 
00277 size_t _Locale_strxfrm(struct _Locale_collate *,
00278                        char *, size_t,
00279                        const char *, size_t);
00280 
00281 # ifndef _STLP_NO_WCHAR_T
00282 size_t _Locale_strwxfrm(struct _Locale_collate *,
00283                         wchar_t *, size_t,
00284                         const wchar_t *, size_t);
00285 # endif
00286 
00287 /*
00288  * Creates a transformed version of the string [s2, s2 + n2).  The
00289  * string may contain embedded null characters; nulls aren't special.
00290  * The transformed string begins at s1, and contains at most n1
00291  * characters.  The return value is the length of the transformed
00292  * string.  If the return value is greater than n1 then this is an
00293  * error condition: it indicates that there wasn't enough space.  In
00294  * that case, the contents of [s1, s1 + n1) is unspecified.
00295 */
00296 
00297 /*
00298  * FUNCTIONS THAT USE NUMERIC
00299  */
00300 
00301 char _Locale_decimal_point(struct _Locale_numeric *);
00302 char _Locale_thousands_sep(struct _Locale_numeric *);
00303 const char * _Locale_grouping(struct _Locale_numeric *);
00304 
00305 /*
00306  * Equivalent to the first three fields in struct lconv.  (C standard,
00307  * section 7.4.)
00308  */
00309 
00310 const char * _Locale_true(struct _Locale_numeric *);
00311 const char * _Locale_false(struct _Locale_numeric *);
00312 
00313 /*
00314  * Return "true" and "false" in English locales, and something
00315  * appropriate in non-English locales.
00316  */
00317 
00318 /*
00319  * FUNCTIONS THAT USE MONETARY
00320  */
00321 
00322 const char * _Locale_int_curr_symbol(struct _Locale_monetary *);
00323 const char * _Locale_currency_symbol(struct _Locale_monetary *);
00324 char         _Locale_mon_decimal_point(struct _Locale_monetary *);
00325 char         _Locale_mon_thousands_sep(struct _Locale_monetary *);
00326 const char * _Locale_mon_grouping(struct _Locale_monetary *);
00327 const char * _Locale_positive_sign(struct _Locale_monetary *);
00328 const char * _Locale_negative_sign(struct _Locale_monetary *);
00329 char         _Locale_int_frac_digits(struct _Locale_monetary *);
00330 char         _Locale_frac_digits(struct _Locale_monetary *);
00331 int          _Locale_p_cs_precedes(struct _Locale_monetary *);
00332 int          _Locale_p_sep_by_space(struct _Locale_monetary *);
00333 int          _Locale_p_sign_posn(struct _Locale_monetary *);
00334 int          _Locale_n_cs_precedes(struct _Locale_monetary *);
00335 int          _Locale_n_sep_by_space(struct _Locale_monetary *);
00336 int          _Locale_n_sign_posn(struct _Locale_monetary *);
00337 
00338 /*
00339  * Return the obvious fields of struct lconv.
00340  */
00341 
00342 /*
00343  * FUNCTIONS THAT USE TIME
00344  */
00345 
00346 const char ** _Locale_full_monthname(struct _Locale_time *);
00347 const char ** _Locale_abbrev_monthname(struct _Locale_time *);
00348 
00349 /*
00350  * month is in the range [0, 12).
00351  */
00352 
00353 const char ** _Locale_full_dayofweek(struct _Locale_time *);
00354 const char ** _Locale_abbrev_dayofweek(struct _Locale_time *);
00355 
00356 /*
00357  * day is in the range [0, 7).  Sunday is 0.
00358  */
00359 
00360 const char * _Locale_d_t_fmt(struct _Locale_time *);
00361 const char * _Locale_d_fmt(struct _Locale_time *);
00362 const char * _Locale_t_fmt(struct _Locale_time *);
00363 const char * _Locale_long_d_t_fmt(struct _Locale_time*);
00364 const char * _Locale_long_d_fmt(struct _Locale_time*);
00365 
00366 const char * _Locale_am_str(struct _Locale_time *);
00367 const char * _Locale_pm_str(struct _Locale_time *);
00368 const char * _Locale_t_fmt_ampm(struct _Locale_time *);
00369 
00370 
00371 /*
00372  * FUNCTIONS THAT USE MESSAGES
00373  */
00374 
00375 int _Locale_catopen(struct _Locale_messages*, const char*);
00376 
00377 /*
00378  * Very similar to catopen, except that it uses L to determine
00379  * which catalog to open.
00380  */
00381 
00382 void _Locale_catclose(struct _Locale_messages*, int);
00383 
00384 /*
00385  * catalog is a value that was returned by a previous call to
00386  * _Locale_catopen
00387  */
00388 
00389 const char * _Locale_catgets(struct _Locale_messages *, int,
00390                              int, int,const char *);
00391 
00392 /*
00393  * Returns a string, identified by a set index and a message index,
00394  * from an opened message catalog.  Returns default if no such
00395  * string exists.
00396  */
00397 
00398 # ifdef __cplusplus
00399 }
00400 _STLP_END_NAMESPACE
00401 # endif
00402 
00403 # endif /* _STLP_C_LOCALE_IMPL_H */

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6