stdcpp/src/facets_byname.cpp
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
       
     3  *
       
     4  * Copyright (c) 1999
       
     5  * Silicon Graphics Computer Systems, Inc.
       
     6  *
       
     7  * Copyright (c) 1999 
       
     8  * Boris Fomitchev
       
     9  *
       
    10  * This material is provided "as is", with absolutely no warranty expressed
       
    11  * or implied. Any use is at your own risk.
       
    12  *
       
    13  * Permission to use or copy this software for any purpose is hereby granted 
       
    14  * without fee, provided the above notices are retained on all copies.
       
    15  * Permission to modify the code and to distribute modified code is granted,
       
    16  * provided the above notices are retained, and a notice that the code was
       
    17  * modified is included with the above copyright notice.
       
    18  *
       
    19  */ 
       
    20 # include "stlport_prefix.h"
       
    21 
       
    22 #include <hash_map>
       
    23 #include "locale_impl.h"
       
    24 #include "c_locale.h"
       
    25 
       
    26 #include "locale_nonclassic.h"
       
    27 
       
    28 
       
    29 #include <stl/_codecvt.h>
       
    30 #include <stl/_collate.h>
       
    31 #include <stl/_ctype.h>
       
    32 #include <stl/_monetary.h>
       
    33 #include <stl/_time_facets.h>
       
    34 #include <stl/_messages_facets.h>
       
    35 #include <stl/_istream.h>
       
    36 #include <stl/_num_get.h>
       
    37 #include <stl/_num_put.h>
       
    38 
       
    39 #include <algorithm>
       
    40 // #include <stl/_ctype.h>
       
    41 #include <stl/_function.h>
       
    42 #include "c_locale.h"
       
    43 
       
    44 _STLP_BEGIN_NAMESPACE
       
    45 
       
    46 _Locale_ctype* __acquire_ctype(const char* name); 
       
    47 void __release_ctype(_Locale_ctype* cat);
       
    48 
       
    49 
       
    50 //----------------------------------------------------------------------
       
    51 // ctype_byname<char>
       
    52 
       
    53 _STLP_EXP_DECLSPEC ctype_byname<char>::ctype_byname(const char* name, size_t refs)
       
    54   : ctype<char>(_M_byname_table+1, false, refs),
       
    55   _M_ctype(__acquire_ctype(name))
       
    56 {
       
    57   
       
    58   if (!_M_ctype)
       
    59     locale::_M_throw_runtime_error();
       
    60   
       
    61   // We have to do this, instead of just pointer twiddling, because
       
    62   // ctype_base::mask isn't the same type as _Locale_mask_t.  
       
    63 
       
    64   const _Locale_mask_t* p = _Locale_ctype_table(_M_ctype);
       
    65 
       
    66    if (!p)
       
    67      locale::_M_throw_runtime_error(); 
       
    68 
       
    69   for (size_t i = 0; i < table_size + 1; ++i) {
       
    70     _Locale_mask_t __m = p[i];
       
    71     if (__m & (upper | lower))
       
    72       __m |= alpha;
       
    73     _M_byname_table[i] = ctype_base::mask(__m);
       
    74   }
       
    75 }
       
    76 
       
    77 _STLP_EXP_DECLSPEC ctype_byname<char>::~ctype_byname()
       
    78 {
       
    79   __release_ctype(_M_ctype);
       
    80 }
       
    81 
       
    82 _STLP_EXP_DECLSPEC char ctype_byname<char>::do_toupper(char c) const 
       
    83 {
       
    84   return _Locale_toupper(_M_ctype, c);
       
    85 }
       
    86 
       
    87 _STLP_EXP_DECLSPEC char ctype_byname<char>::do_tolower(char c) const 
       
    88 {
       
    89   return _Locale_tolower(_M_ctype, c);
       
    90 }
       
    91 
       
    92 _STLP_EXP_DECLSPEC const char*
       
    93 ctype_byname<char>::do_toupper(char* first, const char* last) const
       
    94 {
       
    95   for ( ; first != last ; ++first) 
       
    96     *first = _Locale_toupper(_M_ctype, *first);
       
    97   return last;
       
    98 }
       
    99 
       
   100 _STLP_EXP_DECLSPEC const char*
       
   101 ctype_byname<char>::do_tolower(char* first, const char* last) const
       
   102 {
       
   103   for ( ; first != last ; ++first) 
       
   104     *first = _Locale_tolower(_M_ctype, *first);
       
   105   return last;
       
   106 }
       
   107 
       
   108 
       
   109 // Some helper functions used in ctype<>::scan_is and scan_is_not.
       
   110 
       
   111 # ifndef _STLP_NO_WCHAR_T
       
   112 
       
   113 // ctype_byname<wchar_t>
       
   114 
       
   115   struct _Ctype_byname_w_is_mask {
       
   116     typedef wchar_t argument_type;
       
   117     typedef bool    result_type;
       
   118 
       
   119     /* ctype_base::mask*/ int  M;
       
   120     _Locale_ctype* M_ctp;
       
   121 
       
   122     _Ctype_byname_w_is_mask(/* ctype_base::mask */ int m, _Locale_ctype* c) : M((int)m), M_ctp(c) {}
       
   123     bool operator()(wchar_t c) const
       
   124       { return (M & _Locale_wchar_ctype(M_ctp, c, M)) != 0; }
       
   125   };
       
   126 
       
   127 _STLP_EXP_DECLSPEC ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
       
   128   : ctype<wchar_t>(refs),
       
   129     _M_ctype(__acquire_ctype(name))
       
   130 {
       
   131   if (!_M_ctype)
       
   132     locale::_M_throw_runtime_error();    
       
   133 }
       
   134 
       
   135 _STLP_EXP_DECLSPEC ctype_byname<wchar_t>::~ctype_byname()
       
   136 {
       
   137   __release_ctype(_M_ctype);
       
   138 }
       
   139 
       
   140 _STLP_EXP_DECLSPEC bool ctype_byname<wchar_t>::do_is(ctype_base::mask  m, wchar_t c) const
       
   141 {
       
   142   return (m & _Locale_wchar_ctype(_M_ctype, c, m)) != 0;
       
   143 }
       
   144 
       
   145 _STLP_EXP_DECLSPEC const wchar_t*
       
   146 ctype_byname<wchar_t>::do_is(const wchar_t* low, const wchar_t* high,
       
   147                              ctype_base::mask * m) const
       
   148 {
       
   149   ctype_base::mask all_bits = ctype_base::mask(
       
   150     ctype_base::space |
       
   151     ctype_base::print |
       
   152     ctype_base::cntrl |
       
   153     ctype_base::upper |
       
   154     ctype_base::lower |
       
   155     ctype_base::alpha |
       
   156     ctype_base::digit |
       
   157     ctype_base::punct |
       
   158     ctype_base::xdigit);
       
   159 
       
   160   for ( ; low < high; ++low, ++m)
       
   161     *m = ctype_base::mask (_Locale_wchar_ctype(_M_ctype, *low, all_bits));
       
   162   return high;
       
   163 }
       
   164 
       
   165     
       
   166 _STLP_EXP_DECLSPEC const wchar_t*
       
   167 ctype_byname<wchar_t>
       
   168   ::do_scan_is(ctype_base::mask  m, const wchar_t* low, const wchar_t* high) const
       
   169 {
       
   170   return find_if(low, high, _Ctype_byname_w_is_mask(m, _M_ctype));
       
   171 }
       
   172 
       
   173 _STLP_EXP_DECLSPEC const wchar_t*
       
   174 ctype_byname<wchar_t>
       
   175   ::do_scan_not(ctype_base::mask  m, const wchar_t* low, const wchar_t* high) const
       
   176 {
       
   177   return find_if(low, high, not1(_Ctype_byname_w_is_mask(m, _M_ctype)));
       
   178 }
       
   179 
       
   180 _STLP_EXP_DECLSPEC wchar_t ctype_byname<wchar_t>::do_toupper(wchar_t c) const 
       
   181 {
       
   182   return _Locale_wchar_toupper(_M_ctype, c);
       
   183 }
       
   184 
       
   185 _STLP_EXP_DECLSPEC const wchar_t* 
       
   186 ctype_byname<wchar_t>::do_toupper(wchar_t* low, const wchar_t* high) const
       
   187 {
       
   188   for ( ; low < high; ++low)
       
   189     *low = _Locale_wchar_toupper(_M_ctype, *low);
       
   190   return high;
       
   191 }
       
   192 
       
   193 _STLP_EXP_DECLSPEC wchar_t ctype_byname<wchar_t>::do_tolower(wchar_t c) const 
       
   194 {
       
   195   return _Locale_wchar_tolower(_M_ctype, c);
       
   196 }
       
   197 
       
   198 _STLP_EXP_DECLSPEC const wchar_t* 
       
   199 ctype_byname<wchar_t>::do_tolower(wchar_t* low, const wchar_t* high) const
       
   200 {
       
   201   for ( ; low < high; ++low)
       
   202     *low = _Locale_wchar_tolower(_M_ctype, *low);
       
   203   return high;
       
   204 }
       
   205 
       
   206 # endif /* WCHAR_T */
       
   207 
       
   208 _STLP_END_NAMESPACE
       
   209 
       
   210 
       
   211 // # include "collate_byname.cpp"
       
   212 
       
   213 #include "stl/_collate.h"
       
   214 #include "c_locale.h"
       
   215 #include <vector>
       
   216 
       
   217 _STLP_BEGIN_NAMESPACE
       
   218 
       
   219 // collate_byname<char>
       
   220 _Locale_collate* __acquire_collate(const char* name);
       
   221 void __release_collate(_Locale_collate* cat);
       
   222 
       
   223 _STLP_EXP_DECLSPEC collate_byname<char>::collate_byname(const char* name, size_t refs)
       
   224   : collate<char>(refs),
       
   225     _M_collate(__acquire_collate(name))
       
   226 {
       
   227   if (!_M_collate)
       
   228     locale::_M_throw_runtime_error();
       
   229 }
       
   230 
       
   231  _STLP_EXP_DECLSPEC collate_byname<char>::~collate_byname()
       
   232 {
       
   233   __release_collate(_M_collate);
       
   234 }
       
   235 
       
   236  _STLP_EXP_DECLSPEC int collate_byname<char>::do_compare(const char* __low1,
       
   237                                      const char* __high1,
       
   238                                      const char* __low2,
       
   239                                      const char* __high2) const {
       
   240   return _Locale_strcmp(_M_collate,
       
   241                         __low1, __high1 - __low1, 
       
   242                         __low2, __high2 - __low2);
       
   243 }
       
   244 
       
   245 collate_byname<char>::string_type
       
   246  _STLP_EXP_DECLSPEC collate_byname<char>::do_transform(const char* low, const char* high) const {
       
   247   size_t n = _Locale_strxfrm(_M_collate,
       
   248                              NULL, 0,
       
   249                              low, high - low);
       
   250 
       
   251   __vector__<char, allocator<char> > buf(n+1);
       
   252   _Locale_strxfrm(_M_collate, &buf.front(), n,
       
   253                               low, high - low);
       
   254 
       
   255    char& __c1 = *(buf.begin());
       
   256    char& __c2 = (n == (size_t)-1) ? *(buf.begin() + (high-low-1)) : *(buf.begin() + n);
       
   257    //   char& __c2 = *(buf.begin() + n);
       
   258    return string_type( &__c1, &__c2 );
       
   259 }
       
   260 
       
   261 
       
   262 # ifndef _STLP_NO_WCHAR_T
       
   263 
       
   264 // collate_byname<wchar_t>
       
   265 
       
   266 _STLP_EXP_DECLSPEC collate_byname<wchar_t>::collate_byname(const char* name, size_t refs)
       
   267   : collate<wchar_t>(refs),
       
   268     _M_collate(__acquire_collate(name))
       
   269 {
       
   270   if (!_M_collate)
       
   271     locale::_M_throw_runtime_error();
       
   272 }
       
   273 
       
   274  _STLP_EXP_DECLSPEC collate_byname<wchar_t>::~collate_byname() 
       
   275 {
       
   276   __release_collate(_M_collate);
       
   277 }
       
   278 
       
   279  _STLP_EXP_DECLSPEC int collate_byname<wchar_t>::do_compare(const wchar_t* low1,
       
   280                                         const wchar_t* high1,
       
   281                                         const wchar_t* low2,
       
   282                                         const wchar_t* high2) const
       
   283 {
       
   284   return _Locale_strwcmp(_M_collate,
       
   285                          low1, high1 - low1, 
       
   286                          low2, high2 - low2);
       
   287 }
       
   288 
       
   289  _STLP_EXP_DECLSPEC collate_byname<wchar_t>::string_type
       
   290 collate_byname<wchar_t>
       
   291   ::do_transform(const wchar_t* low, const wchar_t* high) const
       
   292 {
       
   293   size_t n = _Locale_strwxfrm(_M_collate,
       
   294                               NULL, 0,
       
   295                               low, high - low);
       
   296 
       
   297 //  __vector__<wchar_t, allocator<wchar_t> > buf(high - low); //gnu bug fix 3/1/07
       
   298 #ifdef	__SYMBIAN32__
       
   299 	__vector__<wchar_t, allocator<wchar_t> > buf(n+1);  
       
   300   	_Locale_strwxfrm(_M_collate, &buf.front(), n+1,
       
   301                                low, high - low);
       
   302 #else  
       
   303   __vector__<wchar_t, allocator<wchar_t> > buf(n);  
       
   304   _Locale_strwxfrm(_M_collate, &buf.front(), n,
       
   305                                low, high - low);
       
   306 #endif                               
       
   307   wchar_t& __c1 = *(buf.begin());
       
   308   wchar_t& __c2 = (n == (size_t)-1) ? *(buf.begin() + (high-low-1)) : *(buf.begin() + n);
       
   309   // wchar_t& __c2 = *(buf.begin() + n);
       
   310   return string_type( &__c1, &__c2 );
       
   311 }
       
   312 
       
   313 # endif /*  _STLP_NO_WCHAR_T */
       
   314 
       
   315 _STLP_END_NAMESPACE
       
   316 
       
   317 # ifndef _STLP_NO_MBSTATE_T
       
   318 
       
   319 #include <stl/_codecvt.h>
       
   320 #include <stl/_algobase.h>
       
   321 #include "c_locale.h"
       
   322 
       
   323 _STLP_BEGIN_NAMESPACE
       
   324 
       
   325 
       
   326 //----------------------------------------------------------------------
       
   327 // codecvt_byname<char>
       
   328 
       
   329  _STLP_EXP_DECLSPEC codecvt_byname<char, char, mbstate_t>
       
   330   ::codecvt_byname(const char* /* name */, size_t refs)
       
   331     : codecvt<char, char, mbstate_t>(refs)
       
   332 {}
       
   333 
       
   334  _STLP_EXP_DECLSPEC codecvt_byname<char, char, mbstate_t>::~codecvt_byname() {}
       
   335 
       
   336 
       
   337 # ifndef _STLP_NO_WCHAR_T
       
   338 
       
   339 //----------------------------------------------------------------------
       
   340 // codecvt_byname<wchar_t>
       
   341 
       
   342 _Locale_ctype* __acquire_ctype(const char* name);
       
   343 void __release_ctype(_Locale_ctype* cat);
       
   344 
       
   345 _STLP_EXP_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>
       
   346   ::codecvt_byname(const char* name, size_t refs)
       
   347     : codecvt<wchar_t, char, mbstate_t>(refs),
       
   348       _M_ctype(__acquire_ctype(name))
       
   349 {
       
   350   if (!_M_ctype)
       
   351     locale::_M_throw_runtime_error();
       
   352 }
       
   353 
       
   354  _STLP_EXP_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>::~codecvt_byname()
       
   355 {
       
   356   __release_ctype(_M_ctype);
       
   357 }
       
   358 
       
   359 _STLP_EXP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result  
       
   360 codecvt_byname<wchar_t, char, mbstate_t>
       
   361   ::do_out(state_type&     state,
       
   362            const wchar_t*  from,
       
   363            const wchar_t*  from_end,
       
   364            const wchar_t*& from_next,
       
   365            char*           to,
       
   366            char*           to_limit,
       
   367            char*&          to_next) const
       
   368 {
       
   369   while (from != from_end) {
       
   370     size_t chars_stored = _Locale_wctomb(_M_ctype,
       
   371                                          to, to_limit - to, *from,
       
   372                                          &state);
       
   373     if (chars_stored == (size_t) -1) {
       
   374       from_next = from;
       
   375       to_next   = to;
       
   376       return error;
       
   377     }
       
   378 
       
   379     else if (chars_stored == (size_t) -2) {
       
   380       from_next = from;
       
   381       to_next   = to;
       
   382       return partial;
       
   383     }
       
   384 
       
   385     ++from;
       
   386     to += chars_stored;
       
   387   }
       
   388 
       
   389   from_next = from;
       
   390   to_next   = to;
       
   391   return ok;
       
   392 }
       
   393 
       
   394 _STLP_EXP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result  
       
   395 codecvt_byname<wchar_t, char, mbstate_t>
       
   396   ::do_in(state_type&         state,
       
   397           const extern_type*  from,
       
   398           const extern_type*  from_end,
       
   399           const extern_type*& from_next,
       
   400           intern_type*        to,
       
   401           intern_type*        to_limit,
       
   402           intern_type*&       to_next) const
       
   403 {
       
   404   while (from != from_end) {
       
   405     int chars_write = 0;
       
   406     size_t chars_read = _Locale_mbtowc(_M_ctype,
       
   407                                        to, to_limit-to, from, from_end - from, &chars_write,
       
   408                                        &state);
       
   409     if (chars_read == (size_t) -1) {
       
   410       from_next = from;
       
   411       to_next   = to;
       
   412       return error;
       
   413     }
       
   414 
       
   415     if (chars_read == (size_t) -2) {
       
   416       from_next = from;
       
   417       to_next   = to;
       
   418       return partial;
       
   419     }
       
   420 
       
   421     from += chars_read;
       
   422     to += chars_write;
       
   423   }
       
   424 
       
   425   from_next = from;
       
   426   to_next   = to;
       
   427   return ok;
       
   428 }
       
   429 
       
   430 _STLP_EXP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result  
       
   431 codecvt_byname<wchar_t, char, mbstate_t>
       
   432   ::do_unshift(state_type&   state,
       
   433                extern_type*  to,
       
   434                extern_type*  to_limit,
       
   435                extern_type*& to_next) const
       
   436 {
       
   437   to_next = to;
       
   438   size_t result = _Locale_unshift(_M_ctype, &state,
       
   439                                   to, to_limit - to, &to_next);
       
   440   if (result == (size_t) -1)
       
   441     return error;
       
   442   else if (result == (size_t) -2)
       
   443     return partial;
       
   444   else
       
   445 #ifdef __ISCPP__
       
   446     return /*to_next == to ? noconv :*/ ok;
       
   447 #else
       
   448     return to_next == to ? noconv : ok;
       
   449 #endif
       
   450 }
       
   451 
       
   452 int  _STLP_EXP_DECLSPEC 
       
   453 codecvt_byname<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
       
   454 {
       
   455   if (_Locale_is_stateless(_M_ctype)) {
       
   456     int max_width = _Locale_mb_cur_max(_M_ctype);
       
   457     int min_width = _Locale_mb_cur_min(_M_ctype);
       
   458     return min_width == max_width ? min_width : 0;
       
   459   }
       
   460   else
       
   461     return -1;
       
   462 }
       
   463 
       
   464 
       
   465 _STLP_EXP_DECLSPEC bool codecvt_byname<wchar_t, char, mbstate_t>   
       
   466   ::do_always_noconv() const _STLP_NOTHROW
       
   467 {
       
   468   return false;
       
   469 }
       
   470 
       
   471 _STLP_EXP_DECLSPEC int   
       
   472 codecvt_byname<wchar_t, char, mbstate_t>::do_length(
       
   473                                                     const state_type&,
       
   474                                                     const  extern_type* from, const  extern_type* end,
       
   475                                                     size_t mx) const 
       
   476 {
       
   477   return (int)(min) ((size_t) (end - from), mx);
       
   478 }
       
   479 
       
   480 _STLP_EXP_DECLSPEC int 
       
   481 codecvt_byname<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
       
   482 {
       
   483   return _Locale_mb_cur_max(_M_ctype);
       
   484 }
       
   485 # endif /* WCHAR_T */
       
   486 
       
   487 _STLP_END_NAMESPACE
       
   488 
       
   489 # endif /* MBSTATE_T */
       
   490 
       
   491 #include "locale_impl.h"
       
   492 # include <stl/_numpunct.h>
       
   493 
       
   494 _STLP_BEGIN_NAMESPACE
       
   495 
       
   496 _Locale_numeric*  _STLP_CALL __acquire_numeric(const char* name);
       
   497 void  _STLP_CALL __release_numeric(_Locale_numeric* cat);
       
   498 
       
   499 // numpunct_byname<char>
       
   500 
       
   501 _STLP_EXP_DECLSPEC numpunct_byname<char>::numpunct_byname(const char* name, size_t refs)
       
   502   : numpunct<char>(refs),
       
   503     _M_numeric(__acquire_numeric(name))
       
   504 {
       
   505   if (!_M_numeric)
       
   506     locale::_M_throw_runtime_error();
       
   507 
       
   508 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   509   numpunct<char>::GetNumPunct_M_truename()  = _Locale_true(_M_numeric);
       
   510   numpunct<char>::GetNumPunct_M_falsename() = _Locale_false(_M_numeric);
       
   511 #else
       
   512   _M_truename  = _Locale_true(_M_numeric);
       
   513   _M_falsename = _Locale_false(_M_numeric);
       
   514 #endif
       
   515 }
       
   516 
       
   517 _STLP_EXP_DECLSPEC numpunct_byname<char>::~numpunct_byname()
       
   518 {
       
   519   __release_numeric(_M_numeric);
       
   520 }
       
   521 
       
   522 _STLP_EXP_DECLSPEC char numpunct_byname<char>::do_decimal_point() const {
       
   523   return _Locale_decimal_point(_M_numeric);
       
   524 }
       
   525 
       
   526 _STLP_EXP_DECLSPEC char numpunct_byname<char>::do_thousands_sep() const {
       
   527   return _Locale_thousands_sep(_M_numeric);
       
   528 }
       
   529 
       
   530 _STLP_EXP_DECLSPEC string numpunct_byname<char>::do_grouping() const {
       
   531   const char * __grouping = _Locale_grouping(_M_numeric);
       
   532   if (__grouping != NULL && __grouping[0] == CHAR_MAX)
       
   533     __grouping = "";
       
   534   return __grouping;
       
   535 }
       
   536 
       
   537 //----------------------------------------------------------------------
       
   538 // numpunct<wchar_t>
       
   539 
       
   540 # ifndef _STLP_NO_WCHAR_T
       
   541 
       
   542 // numpunct_byname<wchar_t> 
       
   543 
       
   544 _STLP_EXP_DECLSPEC numpunct_byname<wchar_t>::numpunct_byname(const char* name, size_t refs)
       
   545   : numpunct<wchar_t>(refs),
       
   546     _M_numeric(__acquire_numeric(name))
       
   547 {
       
   548   if (!_M_numeric)
       
   549     locale::_M_throw_runtime_error();
       
   550 
       
   551   const char* truename  = _Locale_true(_M_numeric);
       
   552   const char* falsename = _Locale_false(_M_numeric);
       
   553 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   554   numpunct<wchar_t>::GetNumPunct_M_Wchar_truename().resize(strlen(truename));
       
   555   numpunct<wchar_t>::GetNumPunct_M_Wchar_falsename().resize(strlen(falsename));
       
   556   copy(truename,  truename  + strlen(truename), numpunct<wchar_t>::GetNumPunct_M_Wchar_truename().begin());
       
   557   copy(falsename, falsename + strlen(falsename), numpunct<wchar_t>::GetNumPunct_M_Wchar_falsename().begin());
       
   558 #else
       
   559   _M_truename.resize(strlen(truename));
       
   560   _M_falsename.resize(strlen(falsename));
       
   561   copy(truename,  truename  + strlen(truename), _M_truename.begin());
       
   562   copy(falsename, falsename + strlen(falsename), _M_falsename.begin());
       
   563 #endif
       
   564 }
       
   565 
       
   566 _STLP_EXP_DECLSPEC numpunct_byname<wchar_t>::~numpunct_byname()
       
   567 {
       
   568   __release_numeric(_M_numeric);
       
   569 }
       
   570 
       
   571 _STLP_EXP_DECLSPEC wchar_t numpunct_byname<wchar_t>::do_decimal_point() const {
       
   572   return (wchar_t) _Locale_decimal_point(_M_numeric);
       
   573 }
       
   574 
       
   575 _STLP_EXP_DECLSPEC wchar_t numpunct_byname<wchar_t>::do_thousands_sep() const {
       
   576   return (wchar_t) _Locale_thousands_sep(_M_numeric);
       
   577 }
       
   578 
       
   579 _STLP_EXP_DECLSPEC string numpunct_byname<wchar_t>::do_grouping() const {
       
   580   const char * __grouping = _Locale_grouping(_M_numeric);
       
   581   if (__grouping != NULL && __grouping[0] == CHAR_MAX)
       
   582     __grouping = "";
       
   583   return __grouping;
       
   584 }
       
   585 
       
   586 # endif
       
   587 
       
   588 _STLP_END_NAMESPACE
       
   589 
       
   590 #include <stl/_monetary.h>
       
   591 // #include <stl/_ostream.h>
       
   592 // #include <stl/_istream.h>
       
   593 #include "c_locale.h"
       
   594 
       
   595 
       
   596 _STLP_BEGIN_NAMESPACE
       
   597 
       
   598 static void _Init_monetary_formats(money_base::pattern& pos_format,
       
   599                                     money_base::pattern& neg_format,
       
   600                                     _Locale_monetary * monetary) {
       
   601   switch (_Locale_p_sign_posn(monetary)) {
       
   602     case 0: case 1:
       
   603       pos_format.field[0] = (char) money_base::sign;
       
   604       if (_Locale_p_cs_precedes(monetary)) {
       
   605 	pos_format.field[1] = (char) money_base::symbol;
       
   606 	if (_Locale_p_sep_by_space(monetary)) {
       
   607 	  pos_format.field[2] = (char) money_base::space;
       
   608 	  pos_format.field[3] = (char) money_base::value;
       
   609 	}
       
   610 	else {
       
   611 	  pos_format.field[2] = (char) money_base::value;
       
   612 	  pos_format.field[3] = (char) money_base::none;
       
   613 	}
       
   614       }
       
   615       else {
       
   616 	//pos_format.field[2] = (char) money_base::value; //gnu bug fix, 3/1/07
       
   617 	pos_format.field[1] = (char) money_base::value;
       
   618 	if (_Locale_p_sep_by_space(monetary)) {
       
   619 	  pos_format.field[2] = (char) money_base::space;
       
   620 	  pos_format.field[3] = (char) money_base::symbol;
       
   621 	}
       
   622 	else {
       
   623 	  pos_format.field[2] = (char) money_base::symbol;
       
   624 	  pos_format.field[3] = (char) money_base::none;
       
   625 	}
       
   626       }       
       
   627       break;
       
   628     case 2:
       
   629       if (_Locale_p_cs_precedes(monetary)) {
       
   630 	pos_format.field[0] = (char) money_base::symbol;
       
   631 	if (_Locale_p_sep_by_space(monetary)) {
       
   632 	  pos_format.field[1] = (char) money_base::space;
       
   633 	  pos_format.field[2] = (char) money_base::value;
       
   634 	  pos_format.field[3] = (char) money_base::sign;
       
   635 	}
       
   636 	else {
       
   637 	  pos_format.field[1] = (char) money_base::value;
       
   638 	  pos_format.field[2] = (char) money_base::sign;
       
   639 	  pos_format.field[3] = (char) money_base::none;
       
   640 	}
       
   641       }
       
   642       else {
       
   643 	pos_format.field[1] = (char) money_base::value;
       
   644 	if (_Locale_p_sep_by_space(monetary)) {
       
   645 	  pos_format.field[1] = (char) money_base::space;
       
   646 	  pos_format.field[2] = (char) money_base::symbol;
       
   647 	  pos_format.field[3] = (char) money_base::sign;
       
   648 	}
       
   649 	else {
       
   650 	  pos_format.field[1] = (char) money_base::symbol;
       
   651 	  pos_format.field[2] = (char) money_base::sign;
       
   652 	  pos_format.field[3] = (char) money_base::none;
       
   653 	}
       
   654       }
       
   655       break;
       
   656     case 3:
       
   657       if (_Locale_p_cs_precedes(monetary)) {
       
   658 	pos_format.field[0] = (char) money_base::sign;
       
   659 	pos_format.field[1] = (char) money_base::symbol;
       
   660 	if (_Locale_p_sep_by_space(monetary)) {
       
   661 	  pos_format.field[2] = (char) money_base::space;
       
   662 	  pos_format.field[3] = (char) money_base::value;
       
   663 	}
       
   664 	else {
       
   665 	  pos_format.field[2] = (char) money_base::value;
       
   666 	  pos_format.field[3] = (char) money_base::none;
       
   667 	}
       
   668       }
       
   669       else {
       
   670 	pos_format.field[0] = (char) money_base::value;
       
   671 	pos_format.field[1] = (char) money_base::sign;
       
   672 	pos_format.field[2] = (char) money_base::symbol;
       
   673 	pos_format.field[3] = (char) money_base::none;
       
   674       }
       
   675       break;
       
   676     case 4: default:
       
   677       if (_Locale_p_cs_precedes(monetary)) {
       
   678 	pos_format.field[0] = (char) money_base::symbol;
       
   679 	pos_format.field[1] = (char) money_base::sign;
       
   680 	pos_format.field[2] = (char) money_base::value;
       
   681 	pos_format.field[3] = (char) money_base::none;
       
   682       }
       
   683       else {
       
   684 	pos_format.field[0] = (char) money_base::value;
       
   685 	if (_Locale_p_sep_by_space(monetary)) {
       
   686 	  pos_format.field[1] = (char) money_base::space;
       
   687 	  pos_format.field[2] = (char) money_base::symbol;
       
   688 	  pos_format.field[3] = (char) money_base::sign;
       
   689 	}
       
   690         else {
       
   691 	  pos_format.field[1] = (char) money_base::symbol;
       
   692 	  pos_format.field[2] = (char) money_base::sign;
       
   693 	  pos_format.field[3] = (char) money_base::none;
       
   694 	}
       
   695       }
       
   696     break;
       
   697   }
       
   698 
       
   699   switch (_Locale_n_sign_posn(monetary)) {
       
   700     case 0: case 1:
       
   701       neg_format.field[0] = (char) money_base::sign;
       
   702       if (_Locale_n_cs_precedes(monetary)) {
       
   703         neg_format.field[1] = (char) money_base::symbol;
       
   704 	if (_Locale_n_sep_by_space(monetary)) {
       
   705 	  neg_format.field[2] = (char) money_base::space;
       
   706 	  neg_format.field[3] = (char) money_base::value;
       
   707 	}
       
   708 	else {
       
   709 	  neg_format.field[2] = (char) money_base::value;
       
   710 	  neg_format.field[3] = (char) money_base::none;
       
   711 	}
       
   712       }
       
   713       else {
       
   714 	neg_format.field[2] = (char) money_base::value;
       
   715 	if (_Locale_n_sep_by_space(monetary)) {
       
   716 	  neg_format.field[2] = (char) money_base::space;
       
   717 	  neg_format.field[3] = (char) money_base::symbol;
       
   718 	}
       
   719 	else {
       
   720 	  neg_format.field[2] = (char) money_base::symbol;
       
   721 	  neg_format.field[3] = (char) money_base::none;
       
   722 	}
       
   723       }       
       
   724       break;
       
   725     case 2:
       
   726       if (_Locale_n_cs_precedes(monetary)) {
       
   727 	neg_format.field[0] = (char) money_base::symbol;
       
   728 	if (_Locale_n_sep_by_space(monetary)) {
       
   729 	  neg_format.field[1] = (char) money_base::space;
       
   730 	  neg_format.field[2] = (char) money_base::value;
       
   731 	  neg_format.field[3] = (char) money_base::sign;
       
   732 	}
       
   733 	else {
       
   734 	  neg_format.field[1] = (char) money_base::value;
       
   735 	  neg_format.field[2] = (char) money_base::sign;
       
   736 	  neg_format.field[3] = (char) money_base::none;
       
   737 	}
       
   738       }
       
   739       else {
       
   740 	neg_format.field[1] = (char) money_base::value;
       
   741 	if (_Locale_n_sep_by_space(monetary)) {
       
   742 	  neg_format.field[1] = (char) money_base::space;
       
   743 	  neg_format.field[2] = (char) money_base::symbol;
       
   744 	  neg_format.field[3] = (char) money_base::sign;
       
   745 	}
       
   746 	else {
       
   747 	  neg_format.field[1] = (char) money_base::symbol;
       
   748 	  neg_format.field[2] = (char) money_base::sign;
       
   749 	  neg_format.field[3] = (char) money_base::none;
       
   750 	}
       
   751       }
       
   752       break;
       
   753     case 3:
       
   754       if (_Locale_n_cs_precedes(monetary)) {
       
   755 	neg_format.field[0] = (char) money_base::sign;
       
   756 	neg_format.field[1] = (char) money_base::symbol;
       
   757 	if (_Locale_n_sep_by_space(monetary)) {
       
   758 	  neg_format.field[2] = (char) money_base::space;
       
   759 	  neg_format.field[3] = (char) money_base::value;
       
   760 	}
       
   761 	else {
       
   762 	  neg_format.field[2] = (char) money_base::value;
       
   763 	  neg_format.field[3] = (char) money_base::none;
       
   764 	}
       
   765       }
       
   766       else {
       
   767 	neg_format.field[0] = (char) money_base::value;
       
   768 	neg_format.field[1] = (char) money_base::sign;
       
   769 	neg_format.field[2] = (char) money_base::symbol;
       
   770 	neg_format.field[3] = (char) money_base::none;
       
   771       }
       
   772       break;
       
   773     case 4: default:
       
   774       if (_Locale_n_cs_precedes(monetary)) {
       
   775 	neg_format.field[0] = (char) money_base::symbol;
       
   776 	neg_format.field[1] = (char) money_base::sign;
       
   777 	neg_format.field[2] = (char) money_base::value;
       
   778 	neg_format.field[3] = (char) money_base::none;
       
   779       }
       
   780       else {
       
   781 	neg_format.field[0] = (char) money_base::value;
       
   782 	if (_Locale_n_sep_by_space(monetary)) {
       
   783 	  neg_format.field[1] = (char) money_base::space;
       
   784 	  neg_format.field[2] = (char) money_base::symbol;
       
   785 	  neg_format.field[3] = (char) money_base::sign;
       
   786 	}
       
   787         else {
       
   788 	  neg_format.field[1] = (char) money_base::symbol;
       
   789 	  neg_format.field[2] = (char) money_base::sign;
       
   790 	  neg_format.field[3] = (char) money_base::none;
       
   791 	}
       
   792       }
       
   793       break;
       
   794   }
       
   795 }
       
   796 
       
   797 
       
   798 //
       
   799 // moneypunct_byname<>
       
   800 //
       
   801 
       
   802 _Locale_monetary* __acquire_monetary(const char* name);
       
   803 void __release_monetary(_Locale_monetary* mon);
       
   804 
       
   805 _STLP_EXP_DECLSPEC moneypunct_byname<char, true>::moneypunct_byname(const char * name,
       
   806 						 size_t refs):
       
   807   moneypunct<char, true>(refs),
       
   808   _M_monetary(__acquire_monetary(name))
       
   809 {
       
   810   if (!_M_monetary)
       
   811     locale::_M_throw_runtime_error();
       
   812   _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
       
   813 }
       
   814 
       
   815 _STLP_EXP_DECLSPEC moneypunct_byname<char, true>::~moneypunct_byname()
       
   816 {
       
   817   __release_monetary(_M_monetary);
       
   818 }
       
   819 
       
   820 _STLP_EXP_DECLSPEC char moneypunct_byname<char, true>::do_decimal_point() const 
       
   821   {return _Locale_mon_decimal_point(_M_monetary);}
       
   822 
       
   823 _STLP_EXP_DECLSPEC char moneypunct_byname<char, true>::do_thousands_sep() const
       
   824   {return _Locale_mon_thousands_sep(_M_monetary);}
       
   825 
       
   826 _STLP_EXP_DECLSPEC string moneypunct_byname<char, true>::do_grouping() const
       
   827   {return _Locale_mon_grouping(_M_monetary);}
       
   828 
       
   829 _STLP_EXP_DECLSPEC string moneypunct_byname<char, true>::do_curr_symbol() const
       
   830   {return _Locale_int_curr_symbol(_M_monetary);}
       
   831 
       
   832 _STLP_EXP_DECLSPEC string moneypunct_byname<char, true>::do_positive_sign() const
       
   833   {return _Locale_positive_sign(_M_monetary);}
       
   834 
       
   835 _STLP_EXP_DECLSPEC string moneypunct_byname<char, true>::do_negative_sign() const
       
   836   {return _Locale_negative_sign(_M_monetary);}
       
   837 
       
   838 _STLP_EXP_DECLSPEC int moneypunct_byname<char, true>::do_frac_digits() const 
       
   839   {return _Locale_int_frac_digits(_M_monetary);}
       
   840 
       
   841 _STLP_EXP_DECLSPEC moneypunct_byname<char, false>::moneypunct_byname(const char * name,
       
   842 						  size_t refs):
       
   843   moneypunct<char, false>(refs),
       
   844   _M_monetary(__acquire_monetary(name))
       
   845 {
       
   846   if (!_M_monetary)
       
   847     locale::_M_throw_runtime_error();
       
   848   _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
       
   849 }
       
   850 
       
   851 _STLP_EXP_DECLSPEC moneypunct_byname<char, false>::~moneypunct_byname()
       
   852 {
       
   853   __release_monetary(_M_monetary);
       
   854 }
       
   855 
       
   856 _STLP_EXP_DECLSPEC char moneypunct_byname<char, false>::do_decimal_point() const
       
   857   {return _Locale_mon_decimal_point(_M_monetary);}
       
   858 
       
   859 _STLP_EXP_DECLSPEC char moneypunct_byname<char, false>::do_thousands_sep() const
       
   860   {return _Locale_mon_thousands_sep(_M_monetary);}
       
   861 
       
   862 _STLP_EXP_DECLSPEC string moneypunct_byname<char, false>::do_grouping() const
       
   863   {return _Locale_mon_grouping(_M_monetary);}
       
   864 
       
   865 _STLP_EXP_DECLSPEC string moneypunct_byname<char, false>::do_curr_symbol() const
       
   866   {return _Locale_currency_symbol(_M_monetary);}
       
   867 
       
   868 _STLP_EXP_DECLSPEC string moneypunct_byname<char, false>::do_positive_sign() const
       
   869   {return _Locale_positive_sign(_M_monetary);}
       
   870 
       
   871 _STLP_EXP_DECLSPEC string moneypunct_byname<char, false>::do_negative_sign() const
       
   872   {return _Locale_negative_sign(_M_monetary);}
       
   873 
       
   874 _STLP_EXP_DECLSPEC int moneypunct_byname<char, false>::do_frac_digits() const 
       
   875   {return _Locale_frac_digits(_M_monetary);}
       
   876 
       
   877 //
       
   878 // moneypunct_byname<wchar_t>
       
   879 //
       
   880 # ifndef _STLP_NO_WCHAR_T
       
   881 
       
   882 _STLP_EXP_DECLSPEC moneypunct_byname<wchar_t, true>::moneypunct_byname(const char * name,
       
   883 						 size_t refs):
       
   884   moneypunct<wchar_t, true>(refs),
       
   885   _M_monetary(__acquire_monetary(name))
       
   886 {
       
   887   if (!_M_monetary)
       
   888     locale::_M_throw_runtime_error();
       
   889   _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
       
   890 }
       
   891 
       
   892 _STLP_EXP_DECLSPEC moneypunct_byname<wchar_t, true>::~moneypunct_byname() 
       
   893 {
       
   894   __release_monetary(_M_monetary);
       
   895 }
       
   896 
       
   897 _STLP_EXP_DECLSPEC wchar_t moneypunct_byname<wchar_t, true>::do_decimal_point() const
       
   898   {return _Locale_mon_decimal_point(_M_monetary);}
       
   899 
       
   900 _STLP_EXP_DECLSPEC wchar_t moneypunct_byname<wchar_t, true>::do_thousands_sep() const
       
   901   {return _Locale_mon_thousands_sep(_M_monetary);}
       
   902 
       
   903 _STLP_EXP_DECLSPEC string moneypunct_byname<wchar_t, true>::do_grouping() const
       
   904   {return _Locale_mon_grouping(_M_monetary);}
       
   905 
       
   906 _STLP_EXP_DECLSPEC wstring moneypunct_byname<wchar_t, true>::do_curr_symbol() const
       
   907 {
       
   908   string str = _Locale_int_curr_symbol(_M_monetary);
       
   909 # if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC) || defined(__MRC__) || defined(__SC__)		//*ty 05/26/2001 - added workaround for mpw
       
   910   wstring result(wstring::_Reserve_t(), str.size());
       
   911   copy(str.begin(), str.end(), result.begin());
       
   912 # else
       
   913   wstring result(str.begin(), str.end());
       
   914 # endif
       
   915   return result;
       
   916 }
       
   917 
       
   918 _STLP_EXP_DECLSPEC wstring moneypunct_byname<wchar_t, true>::do_positive_sign() const
       
   919 {
       
   920   string str = _Locale_positive_sign(_M_monetary);
       
   921 # if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC) || defined(__MRC__) || defined(__SC__)		//*ty 05/26/2001 - added workaround for mpw
       
   922   wstring result(wstring::_Reserve_t(), str.size());
       
   923   copy(str.begin(), str.end(), result.begin());
       
   924 # else
       
   925   wstring result(str.begin(), str.end());
       
   926 # endif
       
   927   return result;
       
   928 }
       
   929 
       
   930 
       
   931 _STLP_EXP_DECLSPEC wstring moneypunct_byname<wchar_t, true>::do_negative_sign() const
       
   932 {
       
   933   string str = _Locale_negative_sign(_M_monetary);
       
   934 # if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC)  || defined(__MRC__) || defined(__SC__)		//*ty 05/26/2001 - added workaround for mpw
       
   935   wstring result(wstring::_Reserve_t(), str.size());
       
   936   copy(str.begin(), str.end(), result.begin());
       
   937 # else
       
   938   wstring result(str.begin(), str.end());
       
   939 # endif
       
   940   return result;
       
   941 }
       
   942 
       
   943 _STLP_EXP_DECLSPEC int moneypunct_byname<wchar_t, true>::do_frac_digits() const 
       
   944   {return _Locale_int_frac_digits(_M_monetary);}
       
   945 
       
   946 _STLP_EXP_DECLSPEC  moneypunct_byname<wchar_t, false>::moneypunct_byname(const char * name,
       
   947 						 size_t refs):
       
   948   moneypunct<wchar_t, false>(refs),
       
   949   _M_monetary(__acquire_monetary(name))
       
   950 {
       
   951   if (!_M_monetary)
       
   952     locale::_M_throw_runtime_error() ;
       
   953   _Init_monetary_formats(_M_pos_format, _M_neg_format, _M_monetary);
       
   954 }
       
   955 
       
   956 _STLP_EXP_DECLSPEC moneypunct_byname<wchar_t, false>::~moneypunct_byname()
       
   957 {
       
   958   __release_monetary(_M_monetary);
       
   959 }
       
   960 
       
   961 _STLP_EXP_DECLSPEC wchar_t moneypunct_byname<wchar_t, false>::do_decimal_point() const
       
   962   {return _Locale_mon_decimal_point(_M_monetary);}
       
   963 
       
   964 _STLP_EXP_DECLSPEC wchar_t moneypunct_byname<wchar_t, false>::do_thousands_sep() const
       
   965   {return _Locale_mon_thousands_sep(_M_monetary);}
       
   966 
       
   967 _STLP_EXP_DECLSPEC string moneypunct_byname<wchar_t, false>::do_grouping() const
       
   968   {return _Locale_mon_grouping(_M_monetary);}
       
   969 
       
   970 _STLP_EXP_DECLSPEC wstring moneypunct_byname<wchar_t, false>::do_curr_symbol() const
       
   971 {
       
   972   string str =  _Locale_currency_symbol(_M_monetary);
       
   973 # if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC) || defined(__MRC__) || defined(__SC__)		//*ty 05/26/2001 - added workaround for mpw
       
   974   wstring result(wstring::_Reserve_t(), str.size());
       
   975   copy(str.begin(), str.end(), result.begin());
       
   976 # else
       
   977   wstring result(str.begin(), str.end());
       
   978 # endif
       
   979   return result;
       
   980 }
       
   981 
       
   982 _STLP_EXP_DECLSPEC wstring moneypunct_byname<wchar_t, false>::do_positive_sign() const
       
   983 {
       
   984   string str = _Locale_positive_sign(_M_monetary);
       
   985 # if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC) || defined(__MRC__) || defined(__SC__)		//*ty 05/26/2001 - added workaround for mpw
       
   986   wstring result(wstring::_Reserve_t(), str.size());
       
   987   copy(str.begin(), str.end(), result.begin());
       
   988 # else
       
   989   wstring result(str.begin(), str.end());
       
   990 # endif
       
   991   return result;
       
   992 }
       
   993 
       
   994 _STLP_EXP_DECLSPEC wstring moneypunct_byname<wchar_t, false>::do_negative_sign() const
       
   995 {
       
   996   string str = _Locale_negative_sign(_M_monetary);
       
   997 # if defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_MSVC) || defined(__MRC__) || defined(__SC__)		//*ty 05/26/2001 - added workaround for mpw
       
   998   wstring result(wstring::_Reserve_t(), str.size());
       
   999   copy(str.begin(), str.end(), result.begin());
       
  1000 # else
       
  1001   wstring result(str.begin(), str.end());
       
  1002 # endif
       
  1003   return result;
       
  1004 }
       
  1005 
       
  1006 _STLP_EXP_DECLSPEC int moneypunct_byname<wchar_t, false>::do_frac_digits() const 
       
  1007   {return _Locale_frac_digits(_M_monetary);}
       
  1008 
       
  1009 # endif
       
  1010 
       
  1011 _STLP_END_NAMESPACE  
       
  1012 
       
  1013 #include <stl/_messages_facets.h>
       
  1014 #include "message_facets.h"
       
  1015 #include <typeinfo>
       
  1016 
       
  1017 _STLP_BEGIN_NAMESPACE
       
  1018 
       
  1019 void _Catalog_locale_map::insert(int key, const locale& L)
       
  1020 {
       
  1021 # ifdef _STLP_NO_WCHAR_T
       
  1022   typedef char _Char;
       
  1023 # else
       
  1024   typedef wchar_t _Char;
       
  1025 # endif
       
  1026 #if !defined(_STLP_NO_TYPEINFO)
       
  1027   // Don't bother to do anything unless we're using a non-default ctype facet
       
  1028   _STLP_TRY {
       
  1029     typedef ctype<_Char> wctype;
       
  1030     wctype& wct = (wctype &)use_facet<wctype>(L);
       
  1031     wctype* zz;
       
  1032     if (typeid(&wct) != typeid(zz)) {
       
  1033       if (!M)
       
  1034         M = new hash_map<int, locale, hash<int>, equal_to<int> >;
       
  1035 
       
  1036 #if defined(__SC__)
       
  1037       if (!M) delete M;
       
  1038 #endif
       
  1039       if (M->find(key) == M->end())
       
  1040         M->insert(pair<const int, locale>(key, L));
       
  1041     }
       
  1042   }
       
  1043   _STLP_CATCH_ALL {}
       
  1044 # endif /* _STLP_NO_TYPEINFO */
       
  1045 }
       
  1046 
       
  1047 void _Catalog_locale_map::erase(int key)
       
  1048 {
       
  1049   if (M)
       
  1050     M->erase(key);
       
  1051 }
       
  1052 
       
  1053 locale _Catalog_locale_map::lookup(int key) const
       
  1054 {
       
  1055   if (M) {
       
  1056     hash_map<int, locale, hash<int>, equal_to<int> >::iterator i = M->find(key);
       
  1057     return i != M->end() ? (*i).second : locale::classic();
       
  1058   }
       
  1059   else
       
  1060     return locale::classic();
       
  1061 }
       
  1062 
       
  1063 
       
  1064 //----------------------------------------------------------------------
       
  1065 //
       
  1066 //
       
  1067 
       
  1068 _Messages_impl::_Messages_impl(bool is_wide) : 
       
  1069   _M_message_obj(0), _M_map(0)
       
  1070 { 
       
  1071   _M_delete = true;
       
  1072   if (is_wide) 
       
  1073     _M_map = new _Catalog_locale_map;
       
  1074   _M_message_obj = __acquire_messages("C");
       
  1075 }
       
  1076 
       
  1077 _Messages_impl::_Messages_impl(bool is_wide, _Locale_messages* msg_obj ) : 
       
  1078   _M_message_obj(msg_obj), _M_map(0)
       
  1079 { 
       
  1080   _M_delete = true;
       
  1081   if (is_wide) 
       
  1082     _M_map = new _Catalog_locale_map;
       
  1083 }
       
  1084 
       
  1085 _Messages_impl::~_Messages_impl()
       
  1086 {
       
  1087   __release_messages(_M_message_obj);
       
  1088   if (_M_map) delete _M_map;
       
  1089 }
       
  1090 
       
  1091 int _Messages_impl::do_open(const string& filename, const locale& L) const
       
  1092 {  
       
  1093   int result = _M_message_obj
       
  1094     ? _Locale_catopen(_M_message_obj, filename.c_str())
       
  1095     : -1;
       
  1096 
       
  1097   if (result >= 0 && _M_map != 0)
       
  1098     _M_map->insert(result, L);
       
  1099 
       
  1100   return result;
       
  1101 }
       
  1102 
       
  1103 string _Messages_impl::do_get(catalog cat,
       
  1104                               int set, int p_id, const string& dfault) const
       
  1105 {
       
  1106   return _M_message_obj != 0 && cat >= 0
       
  1107     ? string(_Locale_catgets(_M_message_obj, cat, set, p_id, dfault.c_str()))
       
  1108     : dfault;
       
  1109 }
       
  1110 
       
  1111 # ifndef _STLP_NO_WCHAR_T
       
  1112 
       
  1113 wstring
       
  1114 _Messages_impl::do_get(catalog thecat,
       
  1115 		       int set, int p_id, const wstring& dfault) const
       
  1116 {
       
  1117   typedef ctype<wchar_t> wctype;
       
  1118   const wctype& ct = use_facet<wctype>(_M_map->lookup(thecat));
       
  1119 
       
  1120   const char* str = _Locale_catgets(_M_message_obj, thecat, set, p_id, "");
       
  1121 
       
  1122   // Verify that the lookup failed; an empty string might represent success.
       
  1123   if (!str)
       
  1124     return dfault;
       
  1125   else if (str[0] == '\0') {
       
  1126     const char* str2 = _Locale_catgets(_M_message_obj, thecat, set, p_id, "*");
       
  1127     if (!str2 || strcmp(str2, "*") == 0)
       
  1128       return dfault;
       
  1129   }
       
  1130 
       
  1131   // str is correct.  Now we must widen it to get a wstring.
       
  1132   size_t n = strlen(str);
       
  1133 
       
  1134   // NOT PORTABLE.  What we're doing relies on internal details of the 
       
  1135   // string implementation.  (Contiguity of string elements.)
       
  1136   wstring result(n, wchar_t(0));
       
  1137   ct.widen(str, str + n, &*result.begin());
       
  1138   return result;
       
  1139 }
       
  1140 
       
  1141 # endif
       
  1142 
       
  1143 void _Messages_impl::do_close(catalog thecat) const
       
  1144 {
       
  1145   if (_M_message_obj)
       
  1146     _Locale_catclose(_M_message_obj, thecat);
       
  1147   if (_M_map) _M_map->erase(thecat);
       
  1148 }
       
  1149 
       
  1150 
       
  1151 //----------------------------------------------------------------------
       
  1152 // messages<char>
       
  1153 
       
  1154 _STLP_EXP_DECLSPEC messages<char>::messages(size_t refs)  : 
       
  1155   _BaseFacet(refs), _M_impl(new _Messages_impl(false))
       
  1156 {}
       
  1157 
       
  1158 _STLP_EXP_DECLSPEC messages<char>::messages(size_t refs, _Locale_messages* msg_obj) : _BaseFacet(refs), 
       
  1159   _M_impl(new _Messages_impl(false, msg_obj))
       
  1160 {}
       
  1161 
       
  1162 
       
  1163 //----------------------------------------------------------------------
       
  1164 // messages_byname<char>
       
  1165 
       
  1166 _STLP_EXP_DECLSPEC messages_byname<char>::messages_byname(const char* name, size_t refs)
       
  1167   : messages<char>(refs, name ? __acquire_messages(name) : 0)
       
  1168 {}
       
  1169 
       
  1170 _STLP_EXP_DECLSPEC messages_byname<char>::~messages_byname()
       
  1171 {}
       
  1172 
       
  1173 # ifndef _STLP_NO_WCHAR_T
       
  1174 
       
  1175 //----------------------------------------------------------------------
       
  1176 // messages<wchar_t>
       
  1177 
       
  1178 _STLP_EXP_DECLSPEC messages<wchar_t>::messages(size_t refs)  : 
       
  1179   _BaseFacet(refs), _M_impl(new _Messages_impl(true))
       
  1180 {}
       
  1181 
       
  1182 _STLP_EXP_DECLSPEC messages<wchar_t>::messages(size_t refs, _Locale_messages* msg_obj)
       
  1183   : _BaseFacet(refs),
       
  1184     _M_impl(new _Messages_impl(true, msg_obj))
       
  1185 {}
       
  1186 
       
  1187 //----------------------------------------------------------------------
       
  1188 // messages_byname<wchar_t>
       
  1189 
       
  1190 
       
  1191 _STLP_EXP_DECLSPEC messages_byname<wchar_t>::messages_byname(const char* name, size_t refs)
       
  1192   : messages<wchar_t>(refs, name ? __acquire_messages(name) : 0)
       
  1193 {}
       
  1194 
       
  1195 _STLP_EXP_DECLSPEC messages_byname<wchar_t>::~messages_byname()
       
  1196 {}
       
  1197 
       
  1198 # endif
       
  1199 
       
  1200 _STLP_END_NAMESPACE
       
  1201