/home/ntakagi/work/STLport-5.1.5/src/c_locale.h

Go to the documentation of this file.
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 "stlport_prefix.h"
00035 #include <stl/c_locale.h>
00036 
00037 #ifdef _STLP_REAL_LOCALE_IMPLEMENTED
00038 #  if defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__)
00039 #    include <nl_types.h>
00040 #  endif
00041 #endif
00042 
00043 /*
00044  * A number: the maximum length of a simple locale name.
00045  * (i.e. a name like like en_US, as opposed to a name like
00046  * en_US/de_AT/de_AT/es_MX/en_US/en_US) */
00047 #define _Locale_MAX_SIMPLE_NAME 256
00048 
00049 /*
00050  * Maximum length of a composite locale.
00051  */
00052 #define _Locale_MAX_COMPOSITE_NAME 6*(_Locale_MAX_SIMPLE_NAME+3)
00053 
00054 #ifdef __cplusplus
00055 extern "C" {
00056 #endif
00057 
00058 /*
00059  * Typedefs:
00060  */
00061 #if (defined (__GNUC__) && !defined (__MINGW32__)) || defined (_KCC) || defined (__ICC)
00062 typedef unsigned short int _Locale_mask_t;
00063 #else
00064 typedef unsigned int _Locale_mask_t;
00065 #endif
00066 
00067 /* Function called during STLport library load phase. Might contain any
00068  * code necessary to the platform localization layer.
00069  */
00070 void _Locale_init();
00071 
00072 /* Function called during STLport library unload. Might contain any
00073  * code necessary to the platform localization layer.
00074  */
00075 void _Locale_final();
00076 
00077 /* Create a category of the locale with the given name.
00078  *
00079  * The char* argument is a simple (not a composite) locale name, which may
00080  * neither be an empty string nor a null pointer.
00081  *
00082  * These functions return NULL to indicate failure.
00083  *
00084  * Note These functions return a void* instead of the appropriate
00085  * _Locale_* struct because they are used with __acquire_category which
00086  * requires that all functions have the same signature.
00087  */
00088 void * _Locale_ctype_create(const char *, struct _Locale_name_hint*);
00089 void * _Locale_numeric_create(const char *, struct _Locale_name_hint*);
00090 void * _Locale_time_create(const char *, struct _Locale_name_hint*);
00091 void * _Locale_collate_create(const char *, struct _Locale_name_hint*);
00092 void * _Locale_monetary_create(const char *, struct _Locale_name_hint*);
00093 void * _Locale_messages_create(const char *, struct _Locale_name_hint*);
00094 
00095 
00096 /* Release a category of a locale
00097  *
00098  * These functions are used to release a category acquired with the
00099  * according _Locale_*_create() functions.
00100  *
00101  * Note: For the same reasons as for the *_create functions, these
00102  * take void* instead of the correct types so that they can be used
00103  * with __release_category.
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 
00113 /*
00114  * Returns the name of the user's default locale in each
00115  * category, as a null-terminated string.  A NULL value
00116  * means the default "C" locale.
00117  */
00118 const char * _Locale_ctype_default(char * __buf);
00119 const char * _Locale_numeric_default(char * __buf);
00120 const char * _Locale_time_default(char * __buf);
00121 const char * _Locale_collate_default(char * __buf);
00122 const char * _Locale_monetary_default(char * __buf);
00123 const char * _Locale_messages_default(char * __buf);
00124 
00125 
00126 /* Retrieve the name of the given category
00127  *
00128  * __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME
00129  * characters.  These functions store the name, as a null-terminated
00130  * string, in __buf.
00131  * TODO: can this fail? How is that signalled then?
00132  */
00133 char const* _Locale_ctype_name(const void *, char* __buf);
00134 char const* _Locale_numeric_name(const void *, char* __buf);
00135 char const* _Locale_time_name(const void *, char* __buf);
00136 char const* _Locale_collate_name(const void *, char*  __buf);
00137 char const* _Locale_monetary_name(const void *, char* __buf);
00138 char const* _Locale_messages_name(const void *, char* __buf);
00139 
00140 
00141 /*
00142  * cname is a (possibly composite) locale name---i.e. a name that can
00143  * be passed to setlocale. __buf points to an array large enough to
00144  * store at least _Locale_MAX_SIMPLE_NAME characters, and each of these
00145  * functions extracts the name of a single category, stores it in buf
00146  * as a null-terminated string, and returns buf.
00147  */
00148 char const* _Locale_extract_ctype_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
00149 char const* _Locale_extract_numeric_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
00150 char const* _Locale_extract_time_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
00151 char const* _Locale_extract_collate_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
00152 char const* _Locale_extract_monetary_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
00153 char const* _Locale_extract_messages_name(const char *cname, char *__buf, struct _Locale_name_hint* __hint);
00154 
00155 /*
00156  * The inputs to this function are six null-terminated strings: the
00157  * names of a locale's six categories.  Locale names for non-standard
00158  * categories are taken from __DefaultName.
00159  * __buf is a pointer to an array large enough to store at least
00160  * _Locale_MAX_COMPOSITE_NAME characters.
00161  * This function constructs a (possibly composite) name describing the
00162  * locale as a whole, stores that name in buf as a null-terminated
00163  * string, and returns buf.
00164  */
00165 char const* _Locale_compose_name(char *__buf,
00166                                  const char *__Ctype, const char *__Numeric,
00167                                  const char *__Time, const char *__Collate,
00168                                  const char *__Monetary, const char *__Messages,
00169                                  const char *__DefaultName);
00170 
00171 /* Funstions to improve locale creation process. For some locale API (Win32)
00172  * you need to find a locale identification from the name which can be a
00173  * rather expensive operation especially if you do so for all facets of a
00174  * locale. Those functions can be used to extract from a API dependent facet
00175  * struct the information necessary to skip this lookup process for other
00176  * facets creation. If not supported those function should return NULL.
00177  */
00178 struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*);
00179 struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*);
00180 struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*);
00181 struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*);
00182 struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*);
00183 struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*);
00184 
00185 /*
00186  * FUNCTIONS THAT USE CTYPE
00187  */
00188 
00189 /*
00190  * Narrow character functions:
00191  */
00192 
00193 /*
00194  * Returns a pointer to the beginning of the ctype table.  The table is
00195  * at least 257 bytes long; if p is the pointer returned by this
00196  * function, then p[c] is valid if c is EOF or if p is any value of
00197  * type unsigned char.
00198  */
00199 const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *);
00200 
00201 /*
00202  * c is either EOF, or an unsigned char value.
00203  */
00204 int _Locale_toupper(struct _Locale_ctype *, int);
00205 int _Locale_tolower(struct _Locale_ctype *, int);
00206 
00207 
00208 # ifndef _STLP_NO_WCHAR_T
00209 /*
00210  * Wide character functions:
00211  */
00212 _Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype *, wint_t,
00213   _Locale_mask_t);
00214 wint_t _Locale_wchar_tolower(struct _Locale_ctype *, wint_t);
00215 wint_t _Locale_wchar_toupper(struct _Locale_ctype *, wint_t);
00216 # endif
00217 
00218 # if !defined ( _STLP_NO_MBSTATE_T )
00219 
00220 /*
00221  * Multibyte functions:
00222  */
00223 
00224 int _Locale_mb_cur_max (struct _Locale_ctype *);
00225 /*
00226  * Returns the number of bytes of the longest allowed multibyte
00227  * character in the current encoding.
00228  */
00229 
00230 int _Locale_mb_cur_min (struct _Locale_ctype *);
00231 /*
00232  * Returns the number of bytes of the shortest allowed multibyte
00233  * character in the current encoding.
00234  */
00235 
00236 int _Locale_is_stateless (struct _Locale_ctype *);
00237 /*
00238  * Returns 1 if the current multibyte encoding is stateless
00239  * and does not require the use of an mbstate_t value.
00240  */
00241 
00242 # ifndef _STLP_NO_WCHAR_T
00243 wint_t _Locale_btowc(struct _Locale_ctype *, int);
00244 int _Locale_wctob(struct _Locale_ctype *, wint_t);
00245 
00246 /*
00247  * Just like btowc and wctob, from 4.6.5.1 of the C standard, Normative
00248  * Addendum 1.  (And just like widen/narrow, from clause 22 of the C++
00249  * standard.)
00250  */
00251 
00252 size_t _Locale_mbtowc(struct _Locale_ctype *,
00253                       wchar_t *,
00254                       const char *, size_t,
00255                       mbstate_t *);
00256 
00257 /*
00258  * Almost identical to mbrtowc, from 4.6.5.3.2 of NA1.  The only
00259  * important difference is that mbrtowc treats null wide characters
00260  * as special, and we don't.  Specifically: examines the characters
00261  * in [from, from + n), extracts a single wide character, and stores
00262  * it in *to.  Modifies shift_state if appropriate.  The return value,
00263  * which is always positive, is the number of characters extracted from
00264  * the input sequence.  Return value is (size_t) -1 if there was an
00265  * encoding error in the input sequence, and (size_t) -2 if
00266  * [from, from + n) is correct but not complete.  None of the pointer
00267  * arguments may be null pointers.
00268  */
00269 
00270 size_t _Locale_wctomb(struct _Locale_ctype *,
00271                       char *, size_t,
00272                       const wchar_t,
00273                       mbstate_t *);
00274 
00275 /*
00276  * Again, very similar to wcrtomb.  The differences are that (1) it
00277  * doesn't treat null characters as special; and (2) it stores at most
00278  * n characters.  Converts c to a multibyte sequence, stores that
00279  * sequence in the array 'to', and returns the length of the sequence.
00280  * Modifies shift_state if appropriate.  The return value is (size_t) -1
00281  * if c is not a valid wide character, and (size_t) -2 if the length of
00282  * the multibyte character sequence is greater than n.
00283  */
00284 # endif
00285 
00286 size_t _Locale_unshift(struct _Locale_ctype *,
00287                        mbstate_t *,
00288                        char *, size_t, char **);
00289 
00290 /*
00291  * Inserts whatever characters are necessary to restore st to an
00292  * initial shift state.  Sets *next to buf + m, where m is the number
00293  * of characters inserted.  (0 <= m <= n.)  Returns m to indicate
00294  * success, (size_t) -1 to indicate error, (size_t) -2 to indicate
00295  * partial success (more than n characters needed).  For success or partial
00296  * success, sets *next to buf + m.
00297  */
00298 
00299 # endif /*  _STLP_NO_MBSTATE_T */
00300 
00301 /*
00302  * FUNCTIONS THAT USE COLLATE
00303  */
00304 
00305 int _Locale_strcmp(struct _Locale_collate *,
00306                    const char *, size_t,
00307                    const char *, size_t);
00308 # ifndef _STLP_NO_WCHAR_T
00309 int _Locale_strwcmp(struct _Locale_collate *,
00310                     const wchar_t *, size_t,
00311                     const wchar_t *, size_t);
00312 # endif
00313 /*
00314  * Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2).  Neither
00315  * sequence is assumed to be null-terminated, and null characters
00316  * aren't special.  If the two sequences are the same up through
00317  * min(n1, n2), then the sequence that compares less is whichever one
00318  * is shorter.
00319  */
00320 
00321 size_t _Locale_strxfrm(struct _Locale_collate *,
00322                        char *, size_t,
00323                        const char *, size_t);
00324 
00325 # ifndef _STLP_NO_WCHAR_T
00326 size_t _Locale_strwxfrm(struct _Locale_collate *,
00327                         wchar_t *, size_t,
00328                         const wchar_t *, size_t);
00329 # endif
00330 
00331 /*
00332  * Creates a transformed version of the string [s2, s2 + n2).  The
00333  * string may contain embedded null characters; nulls aren't special.
00334  * The transformed string begins at s1, and contains at most n1
00335  * characters.  The return value is the length of the transformed
00336  * string.  If the return value is greater than n1 then this is an
00337  * error condition: it indicates that there wasn't enough space.  In
00338  * that case, the contents of [s1, s1 + n1) is unspecified.
00339 */
00340 
00341 /*
00342  * FUNCTIONS THAT USE NUMERIC
00343  */
00344 
00345 /*
00346  * Equivalent to the first three fields in struct lconv.  (C standard,
00347  * section 7.4.)
00348  */
00349 char _Locale_decimal_point(struct _Locale_numeric *);
00350 char _Locale_thousands_sep(struct _Locale_numeric *);
00351 const char * _Locale_grouping(struct _Locale_numeric *);
00352 
00353 
00354 /*
00355  * Return "true" and "false" in English locales, and something
00356  * appropriate in non-English locales.
00357  */
00358 const char * _Locale_true(struct _Locale_numeric *);
00359 const char * _Locale_false(struct _Locale_numeric *);
00360 
00361 
00362 /*
00363  * FUNCTIONS THAT USE MONETARY
00364  */
00365 
00366 /*
00367  * Return the obvious fields of struct lconv.
00368  */
00369 const char * _Locale_int_curr_symbol(struct _Locale_monetary *);
00370 const char * _Locale_currency_symbol(struct _Locale_monetary *);
00371 char         _Locale_mon_decimal_point(struct _Locale_monetary *);
00372 char         _Locale_mon_thousands_sep(struct _Locale_monetary *);
00373 const char * _Locale_mon_grouping(struct _Locale_monetary *);
00374 const char * _Locale_positive_sign(struct _Locale_monetary *);
00375 const char * _Locale_negative_sign(struct _Locale_monetary *);
00376 char         _Locale_int_frac_digits(struct _Locale_monetary *);
00377 char         _Locale_frac_digits(struct _Locale_monetary *);
00378 int          _Locale_p_cs_precedes(struct _Locale_monetary *);
00379 int          _Locale_p_sep_by_space(struct _Locale_monetary *);
00380 int          _Locale_p_sign_posn(struct _Locale_monetary *);
00381 int          _Locale_n_cs_precedes(struct _Locale_monetary *);
00382 int          _Locale_n_sep_by_space(struct _Locale_monetary *);
00383 int          _Locale_n_sign_posn(struct _Locale_monetary *);
00384 
00385 
00386 /*
00387  * FUNCTIONS THAT USE TIME
00388  */
00389 
00390 /*
00391  * month is in the range [0, 12).
00392  */
00393 const char * _Locale_full_monthname(struct _Locale_time *, int);
00394 const char * _Locale_abbrev_monthname(struct _Locale_time *, int);
00395 
00396 
00397 /*
00398  * day is in the range [0, 7).  Sunday is 0.
00399  */
00400 const char * _Locale_full_dayofweek(struct _Locale_time *, int);
00401 const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int);
00402 
00403 
00404 const char * _Locale_d_t_fmt(struct _Locale_time *);
00405 const char * _Locale_d_fmt(struct _Locale_time *);
00406 const char * _Locale_t_fmt(struct _Locale_time *);
00407 const char * _Locale_long_d_t_fmt(struct _Locale_time*);
00408 const char * _Locale_long_d_fmt(struct _Locale_time*);
00409 
00410 const char * _Locale_am_str(struct _Locale_time *);
00411 const char * _Locale_pm_str(struct _Locale_time *);
00412 const char * _Locale_t_fmt_ampm(struct _Locale_time *);
00413 
00414 
00415 /*
00416  * FUNCTIONS THAT USE MESSAGES
00417  */
00418 
00419 # ifdef _STLP_REAL_LOCALE_IMPLEMENTED
00420 #  if defined (WIN32) || defined (_WIN32)
00421 typedef int nl_catd_type;
00422 #  elif defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__)
00423 typedef nl_catd nl_catd_type;
00424 #  else
00425 typedef int nl_catd_type;
00426 #  endif
00427 # else
00428 typedef int nl_catd_type;
00429 # endif /* _STLP_REAL_LOCALE_IMPLEMENTED */
00430 
00431 
00432 /*
00433  * Very similar to catopen, except that it uses the given message
00434  * category to determine which catalog to open.
00435  */
00436 nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*);
00437 
00438 /* Complementary to _Locale_catopen.
00439  * The catalog must be a value that was returned by a previous call
00440  * to _Locale_catopen.
00441  */
00442 void _Locale_catclose(struct _Locale_messages*, nl_catd_type);
00443 
00444 /*
00445  * Returns a string, identified by a set index and a message index,
00446  * from an opened message catalog.  Returns the supplied default if
00447  * no such string exists.
00448  */
00449 const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type,
00450                              int, int,const char *);
00451 
00452 #ifdef __cplusplus
00453 }
00454 #endif
00455 
00456 #endif /* _STLP_C_LOCALE_IMPL_H */



Generated on Mon Mar 10 15:32:46 2008 by  doxygen 1.5.1