1 // Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
28 #include <bits/std_clocale.h>
29 #include <bits/std_cstring.h>
30 #include <bits/std_cassert.h>
31 #include <bits/std_cctype.h>
32 #include <bits/std_limits.h>
33 #include <bits/std_exception.h>
34 #include <bits/std_stdexcept.h>
35 #include <bits/std_locale.h>
36 #include <bits/std_istream.h>
37 #include <bits/std_ostream.h>
38 #include <bits/std_vector.h>
39 #include <bits/std_memory.h> // for auto_ptr
40 #ifdef _GLIBCPP_USE_WCHAR_T
41 #include <bits/std_cwctype.h> // for towupper, etc.
45 // Definitions for static const data members of locale.
46 const locale::category locale::none;
47 const locale::category locale::collate;
48 const locale::category locale::ctype;
49 const locale::category locale::monetary;
50 const locale::category locale::numeric;
51 const locale::category locale::time;
52 const locale::category locale::messages;
53 const locale::category locale::all;
55 locale::_Impl* locale::_S_global;
56 locale::_Impl* locale::_S_classic;
57 const int locale::_S_num_categories;
59 // Definitions for static const data members of locale::_Impl
60 const locale::id* const
61 locale::_Impl::_S_id_collate[] =
63 &std::collate<char>::id,
64 #ifdef _GLIBCPP_USE_WCHAR_T
65 &std::collate<wchar_t>::id,
70 const locale::id* const
71 locale::_Impl::_S_id_ctype[] =
73 &std::ctype<char>::id,
74 #ifdef _GLIBCPP_USE_WCHAR_T
75 &std::ctype<wchar_t>::id,
77 &std::codecvt<char, char, mbstate_t>::id,
78 #ifdef _GLIBCPP_USE_WCHAR_T
79 &std::codecvt<wchar_t, char, mbstate_t>::id,
84 const locale::id* const
85 locale::_Impl::_S_id_monetary[] =
87 &std::moneypunct<char, false>::id,
88 #ifdef _GLIBCPP_USE_WCHAR_T
89 &std::moneypunct<wchar_t, false>::id,
91 &std::moneypunct<char,true >::id,
92 #ifdef _GLIBCPP_USE_WCHAR_T
93 &std::moneypunct<wchar_t,true >::id,
95 &std::money_get<char>::id,
96 #ifdef _GLIBCPP_USE_WCHAR_T
97 &std::money_get<wchar_t>::id,
99 &std::money_put<char>::id,
100 #ifdef _GLIBCPP_USE_WCHAR_T
101 &std::money_put<wchar_t>::id,
106 const locale::id* const
107 locale::_Impl::_S_id_numeric[] =
109 &std::numpunct<char>::id,
110 #ifdef _GLIBCPP_USE_WCHAR_T
111 &std::numpunct<wchar_t>::id,
113 &std::num_get<char>::id,
114 #ifdef _GLIBCPP_USE_WCHAR_T
115 &std::num_get<wchar_t>::id,
117 &std::num_put<char>::id,
118 #ifdef _GLIBCPP_USE_WCHAR_T
119 &std::num_put<wchar_t>::id,
124 const locale::id* const
125 locale::_Impl::_S_id_time[] =
127 &std::time_get<char>::id,
128 #ifdef _GLIBCPP_USE_WCHAR_T
129 &std::time_get<wchar_t>::id,
131 &std::time_put<char>::id,
132 #ifdef _GLIBCPP_USE_WCHAR_T
133 &std::time_put<wchar_t>::id,
138 const locale::id* const
139 locale::_Impl::_S_id_messages[] =
141 &std::time_get<char>::id,
142 #ifdef _GLIBCPP_USE_WCHAR_T
143 &std::time_get<wchar_t>::id,
145 &std::time_put<char>::id,
146 #ifdef _GLIBCPP_USE_WCHAR_T
147 &std::time_put<wchar_t>::id,
152 const locale::id* const* const
153 locale::_Impl::_S_facet_categories[] =
155 // order must match the decl order in class locale.
156 locale::_Impl::_S_id_collate,
157 locale::_Impl::_S_id_ctype,
158 locale::_Impl::_S_id_monetary,
159 locale::_Impl::_S_id_numeric,
160 locale::_Impl::_S_id_time,
161 locale::_Impl::_S_id_messages,
165 // Definitions for static const data members of locale::id
166 size_t locale::id::_S_highwater; // init'd to 0 by linker
168 // Definitions for static const data members of money_base
169 const money_base::pattern
170 money_base::_S_default_pattern = {{symbol, sign, none, value}};;
173 _Format_cache<char>::_Format_cache()
175 _M_decimal_point('.'), _M_thousands_sep(','),
176 _M_truename("true"), _M_falsename("false"), _M_use_grouping(false)
179 #ifdef _GLIBCPP_USE_WCHAR_T
181 _Format_cache<wchar_t>::_Format_cache()
183 _M_decimal_point(L'.'), _M_thousands_sep(L','),
184 _M_truename(L"true"), _M_falsename(L"false"), _M_use_grouping(false)
190 use_facet<const ctype<char> > (const locale& __loc)
192 size_t __i = ctype<char>::id._M_index;
193 const locale::_Impl* __tmp = __loc._M_impl;
194 return static_cast<const ctype<char>&>(* (*(__tmp->_M_facets))[__i]);
197 #ifdef _GLIBCPP_USE_WCHAR_T
199 const ctype<wchar_t>&
200 use_facet< const ctype<wchar_t> > (const locale& __loc)
202 size_t __i = ctype<wchar_t>::id._M_index;
203 const locale::_Impl* __tmp = __loc._M_impl;
204 return static_cast<const ctype<wchar_t>&>(* (*(__tmp->_M_facets))[__i]);
210 num_get<char, istreambuf_iterator<char> >::
211 _M_extract(istreambuf_iterator<char> __beg,
212 istreambuf_iterator<char> __end, ios_base& __io,
213 ios_base::iostate& __err, char* __xtrc, int& __base,
216 typedef _Format_cache<char> __cache_type;
218 // Prepare for possible failure
221 // Stage 1: determine a conversion specifier.
222 ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
223 if (__basefield == ios_base::dec)
225 else if (__basefield == ios_base::oct)
227 else if (__basefield == ios_base::hex)
231 // As far as I can tell, bases other than 10 are not available for
232 // floating point types
236 // Stage 2: extract characters.
237 __cache_type const* __fmt = __cache_type::_S_get(__io);
238 bool __valid = __beg != __end;
239 // Fail quickly if !__valid
242 __err |= (ios_base::eofbit | ios_base::failbit);
246 // Acceptable formats for numbers here are based on 22.2.3.1
250 const char* __lits = __fmt->_S_literals;
253 // Check first for sign
254 bool __testsign = false;
255 if ((__c == __lits[__cache_type::_S_minus])
256 || (__c == __lits[__cache_type::_S_plus]))
258 __xtrc[__pos++] = __c;
261 // whitespace may follow a sign
262 while ((__beg != __end) && (isspace(*__beg)))
265 // There had better be more to come...
268 __xtrc[__pos] = '\0';
269 __err |= (ios_base::eofbit | ios_base::failbit);
274 bool __testzero = false; // Has there been a leading zero?
276 // Now check if first character is a zero
278 if (__c == __lits[__cache_type::_S_digits])
283 // We have to check for __beg == __end here. If so,
284 // a plain '0' (possibly with a sign) can be got rid of now
287 __xtrc[__pos++] = __c;
288 __xtrc[__pos] = '\0';
289 __err |= ios_base::eofbit;
293 // Figure out base for integer types only
294 // Based on Table 55 of 22.2.2.1.2
295 if (!__fp && __base != 10 && __base != 8)
297 // Here, __base == 0 or 16
299 if ((__c == __lits[__cache_type::_S_x])
300 || (__c == __lits[__cache_type::_S_X]))
304 __testzero = false; // "0x" is not a leading zero
306 else if (__base == 0)
310 // Remove any more leading zeros
311 while (__beg != __end)
313 if (*__beg == __lits[__cache_type::_S_digits])
322 else if (__base == 0) // 1st character is not zero
325 // We now seek "units", i.e. digits and thousands separators.
326 // We may need to know if anything is found here. A leading zero
327 // (removed by now) would count.
328 bool __testunits = __testzero;
329 while (__valid && __beg != __end)
333 const char* __p = strchr(__fmt->_S_literals, __c);
335 // NB: strchr returns true for __c == 0x0
338 // Try first for acceptable digit; record it if found
339 if ((__p >= &__lits[__cache_type::_S_digits]
340 && __p < &__lits[__cache_type::_S_digits + __base])
341 || (__p >= &__lits[__cache_type::_S_udigits]
342 && __p < &__lits[__cache_type::_S_udigits + __base]))
344 __xtrc[__pos++] = __c;
350 else if (__c == __fmt->_M_thousands_sep
351 && __fmt->_M_use_grouping)
353 // NB: Thousands separator at the beginning of a string
354 // is a no-no, as is two consecutive thousands
358 __grp += static_cast<char>(__sep_pos);
363 __err |= ios_base::failbit;
369 // Digit grouping is checked. If _M_groupings() doesn't
370 // match, then get very very upset, and set failbit.
371 if (__fmt->_M_use_grouping && !__grp.empty())
373 // Add the ending grouping
374 __grp += static_cast<char>(__sep_pos);
376 // __grp is parsed L to R
377 // 1,222,444 == __grp of "/1/3/3"
378 // __fmt->_M_grouping is parsed R to L
379 // 1,222,444 == __fmt->_M_grouping of "/3" == "/3/3/3"
382 const int __len = __fmt->_M_grouping.size();
383 int __n = __grp.size();
386 // Parsed number groupings have to match the
387 // numpunct::grouping string exactly, starting at the
388 // right-most point of the parsed sequence of elements ...
389 while (__test && __i < __n - 1)
390 for (__j = 0; __test && __j < __len && __i < __n - 1; ++__j,++__i)
391 __test &= __fmt->_M_grouping[__j] == __grp[__n - __i - 1];
392 // ... but the last parsed grouping can be <= numpunct
394 __j == __len ? __j = 0 : __j;
395 __test &= __fmt->_M_grouping[__j] >= __grp[__n - __i - 1];
399 __err |= ios_base::failbit;
400 __xtrc[__pos] = '\0';
402 __err |= ios_base::eofbit;
407 // If there was nothing but zeros, put one in the output string
408 if (__testzero && (__pos == 0 || (__pos == 1 && __testsign)))
409 __xtrc[__pos++] = __lits[__cache_type::_S_digits];
411 // That's it for integer types. Remaining code is for floating point
412 if (__fp && __beg != __end)
415 // Check first for decimal point. There MUST be one if
416 // __testunits is false.
417 bool __testdec = false; // Is there a decimal point
418 // with digits following it?
419 if (__c == __fmt->_M_decimal_point)
421 __xtrc[__pos++] = '.';
423 // Now we get any digits after the decimal point
424 // There MUST be some if __testunits is false.
425 while (__beg != __end)
428 const char* __p = strchr(__fmt->_S_literals, __c);
429 if ((__p >= &__lits[__cache_type::_S_digits]
430 && __p < &__lits[__cache_type::_S_digits + __base])
431 || (__p >= &__lits[__cache_type::_S_udigits]
432 && __p < &__lits[__cache_type::_S_udigits + __base]))
434 __xtrc[__pos++] = __c;
442 if (!__testunits && !__testdec) // Ill formed
444 __err |= ios_base::failbit;
445 __xtrc[__pos] = '\0';
447 __err |= ios_base::eofbit;
451 // Now we may find an exponent
455 if ((__c == __lits[__cache_type::_S_ee])
456 || (__c == __lits[__cache_type::_S_Ee]))
458 __xtrc[__pos++] = __c;
460 // Now there may be a sign
464 if ((__c == __lits[__cache_type::_S_minus])
465 || (__c == __lits[__cache_type::_S_plus]))
467 __xtrc[__pos++] = __c;
469 // whitespace may follow a sign
470 while ((__beg != __end) && (isspace(*__beg)))
475 // And now there must be some digits
478 __xtrc[__pos] = '\0';
479 __err |= (ios_base::eofbit | ios_base::failbit);
482 while (__beg != __end)
485 const char* __p = strchr(__fmt->_S_literals, __c);
486 if ((__p >= &__lits[__cache_type::_S_digits]
487 && __p < &__lits[__cache_type::_S_digits + __base])
488 || (__p >= &__lits[__cache_type::_S_udigits]
489 && __p < &__lits[__cache_type::_S_udigits + __base]))
491 __xtrc[__pos++] = __c;
499 // Finally, that's it for floating point
503 __xtrc[__pos] = '\0';
505 __err |= ios_base::eofbit;
508 // The following code uses sprintf() to convert floating point
509 // values for insertion into a stream. The current implementation
510 // replicates the code in _S_pad_numeric() (in _S_output_float()) in
511 // order to prevent having to create a "wide" buffer in addition to
512 // the "narrow" buffer passed to sprintf(). An optimization would be
513 // to replace sprintf() with code that works directly on a wide
514 // buffer and then use _S_pad_numeric() to do the padding. It would
515 // be good to replace sprintf() anyway to avoid accidental buffer
516 // overruns and to gain back the efficiency that C++ provides by
517 // knowing up front the type of the values to insert. This
518 // implementation follows the C++ standard fairly directly as
519 // outlined in 22.2.2.2 [lib.locale.num.put]
521 _S_build_float_format(ios_base& __io, char* __fptr, char __modifier,
524 bool __incl_prec = false;
525 ios_base::fmtflags __flags = __io.flags();
527 // [22.2.2.2.2] Table 60
528 if (__flags & ios_base::showpos)
530 if (__flags & ios_base::showpoint)
532 // As per [22.2.2.2.2.11]
533 if (__flags & ios_base::fixed || __prec > 0)
540 *__fptr++ = __modifier;
541 ios_base::fmtflags __fltfield = __flags & ios_base::floatfield;
542 // [22.2.2.2.2] Table 58
543 if (__fltfield == ios_base::fixed)
545 else if (__fltfield == ios_base::scientific)
546 *__fptr++ = (__flags & ios_base::uppercase) ? 'E' : 'e';
548 *__fptr++ = (__flags & ios_base::uppercase) ? 'G' : 'g';
557 std::vector<facet*>::iterator it = _M_facets->begin();
558 for (; it != _M_facets->end(); ++it)
559 (*it)->_M_remove_reference();
561 delete _M_category_names;
565 _Impl(size_t __numfacets, size_t __refs)
566 : _M_num_references(__refs - 1), _M_facets(0), _M_category_names(0),
567 _M_has_name(false), _M_cached_name_ok(false), _M_cached_name(string ("*"))
569 typedef vector<facet*, allocator<facet*> > __vec_facet;
570 typedef vector<string, allocator<string> > __vec_string;
572 auto_ptr<__vec_facet> __pvf(new __vec_facet(__numfacets, (facet*)0));
573 auto_ptr<__vec_string> __pcn(new __vec_string(_S_num_categories,
575 _M_facets = __pvf.release();
576 _M_category_names = __pcn.release();
580 _Impl(const _Impl& __other, size_t __refs)
581 : _M_num_references(__refs), _M_facets(0), _M_category_names(0),
582 _M_has_name(__other._M_has_name),
583 _M_cached_name_ok(__other._M_cached_name_ok),
584 _M_cached_name(__other._M_cached_name)
586 typedef vector<facet*, allocator<facet*> > __vec_facet;
587 typedef vector<string, allocator<string> > __vec_string;
589 auto_ptr<__vec_facet> __pvf(new __vec_facet(*(__other._M_facets)));
590 auto_ptr<__vec_string>
591 __pcn(new __vec_string(*(__other._M_category_names)));
593 std::vector<facet*>::iterator __it = __pvf->begin();
594 for (; __it != __pvf->end(); ++__it)
595 (*__it)->_M_add_reference();
597 // These must be last since in the presence of an exception, the
598 // destructor for 'this' won't run until AFTER execution has passed
599 // the closing brace of the constructor.
600 _M_facets = __pvf.release();
601 _M_category_names = __pcn.release();
606 _M_replace_categories(const _Impl* __other, category __cats)
608 assert((__cats & locale::all) && !(__cats & ~locale::all));
610 unsigned mask = (locale::all & -(unsigned)locale::all);
611 for (unsigned ix = 0; (-mask & __cats) != 0; ++ix, (mask <<= 1))
615 _M_replace_category(__other, _S_facet_categories[ix]);
616 (*_M_category_names)[ix] = (*(__other->_M_category_names))[ix];
623 _M_replace_category(const _Impl* __other, const locale::id* const* __idpp)
625 for (; *__idpp; ++__idpp)
626 _M_replace_facet(__other, *__idpp);
631 _M_replace_facet(const _Impl* __other, const locale::id* __idp)
633 size_t __index = __idp->_M_index;
635 || __other->_M_facets->size() <= __index
636 || (*(__other->_M_facets))[__index] == 0)
637 throw runtime_error("no locale facet");
639 _M_install_facet(__idp, (*(__other->_M_facets))[__index]);
644 _M_install_facet(const locale::id* __idp, facet* __fp)
649 size_t& __index = __idp->_M_index;
651 __index = ++locale::id::_S_highwater; // XXX MT
653 if (__index >= _M_facets->size())
654 _M_facets->resize(__index + 1, 0); // might throw
655 facet*& __fpr = (*_M_facets)[__index];
656 // Order matters, here:
657 __fp->_M_add_reference();
659 __fpr->_M_remove_reference();
663 locale::locale(_Impl* __ip) throw()
665 { __ip->_M_add_reference(); }
667 locale::locale(const locale& __other, const locale& __one, category __cats)
669 __cats = _S_normalize_category(__cats); // might throw
670 _M_impl = new _Impl(*__other._M_impl, 1); // might throw
673 _M_impl->_M_replace_categories(__one._M_impl, __cats);
676 _M_impl->_M_remove_reference();
680 _M_impl->_M_cached_name_ok = false;
681 if (!__other._M_impl->_M_has_name)
682 _M_impl->_M_has_name = false;
686 locale::operator=(const locale& __other) throw()
688 __other._M_impl->_M_add_reference();
689 _M_impl->_M_remove_reference();
690 _M_impl = __other._M_impl;
695 locale::global(const locale& __other)
699 locale __keep(_S_global);
700 __other._M_impl->_M_add_reference();
701 _S_global->_M_remove_reference();
702 _S_global = __other._M_impl;
703 if (_S_global->_M_has_name)
704 setlocale(LC_ALL, __other.name().c_str());
718 static locale* __classic_locale;
723 // 26 Standard facets, 2 references.
724 // One reference for _M_classic, one for _M_global
725 _S_classic = _S_global = new _Impl(26, 2);
728 _S_classic->_M_facet_init(new std::collate<char>);
731 _S_classic->_M_facet_init(new std::ctype<char>);
732 _S_classic->_M_facet_init(new codecvt<char, char, mbstate_t>);
735 _S_classic->_M_facet_init(new moneypunct<char, false>);
736 _S_classic->_M_facet_init(new moneypunct<char,true >);
737 _S_classic->_M_facet_init(new money_get<char>);
738 _S_classic->_M_facet_init(new money_put<char>);
741 _S_classic->_M_facet_init(new numpunct<char>);
742 _S_classic->_M_facet_init(new num_get<char>);
743 _S_classic->_M_facet_init(new num_put<char>);
746 _S_classic->_M_facet_init(new time_get<char>);
747 _S_classic->_M_facet_init(new time_put<char>);
750 _S_classic->_M_facet_init(new std::messages<char>);
752 #ifdef _GLIBCPP_USE_WCHAR_T
753 _S_classic->_M_facet_init(new std::collate<wchar_t>);
754 _S_classic->_M_facet_init(new std::ctype<wchar_t>);
755 _S_classic->_M_facet_init(new codecvt<wchar_t, char, mbstate_t>);
756 _S_classic->_M_facet_init(new moneypunct<wchar_t, false>);
757 _S_classic->_M_facet_init(new moneypunct<wchar_t,true >);
758 _S_classic->_M_facet_init(new money_get<wchar_t>);
759 _S_classic->_M_facet_init(new money_put<wchar_t>);
760 _S_classic->_M_facet_init(new numpunct<wchar_t>);
761 _S_classic->_M_facet_init(new num_get<wchar_t>);
762 _S_classic->_M_facet_init(new num_put<wchar_t>);
763 _S_classic->_M_facet_init(new time_get<wchar_t>);
764 _S_classic->_M_facet_init(new time_put<wchar_t>);
765 _S_classic->_M_facet_init(new std::messages<wchar_t>);
768 // Finesse static init order hassles
769 __classic_locale = new locale(_S_classic);
772 delete __classic_locale;
775 _S_classic->_M_remove_reference();
776 _S_global->_M_remove_reference();
778 _S_classic = _S_global = 0;
783 return *__classic_locale;
787 locale::_S_normalize_category(int __cats)
789 if ((__cats & all) && !(__cats & ~all))
792 // NB: May be a C-style "LC_ALL" category; convert.
795 case LC_COLLATE: return collate;
796 case LC_CTYPE: return ctype;
797 case LC_MONETARY: return monetary;
798 case LC_NUMERIC: return numeric;
799 case LC_TIME: return time;
800 #ifdef _GLIBCPP_HAVE_LC_MESSAGES
801 case LC_MESSAGES: return messages;
803 case LC_ALL: return all;
806 // XXX Should throw derived class here
807 throw runtime_error("bad locale category");
812 facet(size_t __refs) throw()
813 : _M_num_references(__refs - 1)
818 _M_add_reference() throw()
826 _M_remove_reference() throw()
828 if (this && _M_num_references-- == 0)
841 { return "bad_cast thrown from use_facet"; }
844 ~_Bad_use_facet() throw() { }
846 // Platform-specific initialization code for ctype tables.
849 locale::id ctype<char>::id;
851 const size_t ctype<char>::table_size;
853 ctype<char>::~ctype()
854 { if (_M_del) delete[] this->table(); }
857 ctype<char>::do_widen(char __c) const
861 ctype<char>::do_widen(const char* __low, const char* __high,
864 memcpy(__dest, __low, __high - __low);
869 ctype<char>::do_narrow(char __c, char /*__dfault*/) const
873 ctype<char>::do_narrow(const char* __low, const char* __high,
874 char /*__dfault*/, char* __dest) const
876 memcpy(__dest, __low, __high - __low);
880 ctype_byname<char>::ctype_byname(const char* /*__s*/, size_t __refs)
881 : ctype<char>(new mask[table_size], true, __refs)
884 locale::id collate<char>::id;
886 collate<char>::collate(size_t __refs)
887 : _Collate<char>(__refs) { }
889 collate<char>::~collate() { }
892 collate<char>::do_compare(const char* __lo1, const char* __hi1,
893 const char* __lo2, const char* __hi2) const
895 for (; __lo1 < __hi1 && __lo2 < __hi2; ++__lo1, ++__lo2)
896 if (*__lo1 != *__lo2)
897 return (*__lo1 < *__lo2) ? -1 : 1;
900 else if (__lo2 < __hi2)
908 do_transform(const char* __lo, const char* __hi) const
909 { return string(__lo, __hi - __lo); }
913 do_hash(const char* __lo, const char* __hi) const
915 unsigned long __val = 0xdeadbeef;
916 for (; __lo < __hi; ++__lo)
917 __val = *__lo ^ ((__val << 7) &
918 (__val >> (numeric_limits<unsigned long>::digits - 1)));
922 collate_byname<char>::collate_byname(const char* /*__s*/, size_t __refs)
923 : collate<char>(__refs) { }
925 numpunct_byname<char>::numpunct_byname(const char* /*__s*/, size_t __refs)
926 : numpunct<char>(__refs) { }
928 moneypunct_byname<char, false>::moneypunct_byname(const char* /*__s*/,
930 : moneypunct<char, false>(__refs) { }
932 moneypunct_byname<char, true>::moneypunct_byname(const char* /*__s*/,
934 : moneypunct<char, true>(__refs) { }
936 messages_byname<char>::
937 messages_byname(const char* /*__s*/, size_t __refs)
938 : messages<char>(__refs) { }
940 #ifdef _GLIBCPP_USE_WCHAR_T
941 locale::id ctype<wchar_t>::id;
946 // NB: These ctype<wchar_t> methods are not configuration-specific,
947 // unlike the ctype<char> bits.
948 ctype<wchar_t>::ctype(size_t __refs) : _Ctype<wchar_t>(__refs) { }
951 ctype<wchar_t>::do_toupper(wchar_t __c) const
952 { return towupper(__c); }
955 ctype<wchar_t>::do_toupper(wchar_t* __low, const wchar_t* __high) const
957 while (__low < __high)
959 *__low = towupper(*__low);
966 ctype<wchar_t>::do_tolower(wchar_t __c) const
967 { return towlower(__c); }
970 ctype<wchar_t>::do_tolower(wchar_t* __low, const wchar_t* __high) const
972 while (__low < __high)
974 *__low = towlower(*__low);
982 do_is(mask __m, char_type __c) const
983 { return static_cast<bool>(iswctype(__c, _M_convert_to_wmask(__m))); }
987 do_is(const wchar_t* __low, const wchar_t* __high, mask* __m) const
989 while (__low < __high && !this->is(*__m, *__low))
996 do_scan_is(mask __m, const wchar_t* __low, const wchar_t* __high) const
998 while (__low < __high && !this->is(__m, *__low))
1005 do_scan_not(mask __m, const char_type* __low, const char_type* __high) const
1007 while (__low < __high && this->is(__m, *__low) != 0)
1014 do_widen(char __c) const
1015 { return btowc(__c); }
1019 do_widen(const char* __low, const char* __high, wchar_t* __dest) const
1022 memset(&__state, 0, sizeof(mbstate_t));
1023 mbsrtowcs(__dest, &__low, __high - __low, &__state);
1029 do_narrow(wchar_t __wc, char __dfault) const
1031 int __c = wctob(__wc);
1032 return (__c == EOF ? __dfault : static_cast<char>(__c));
1037 do_narrow(const wchar_t* __low, const wchar_t* __high, char __dfault,
1041 memset(&__state, 0, sizeof(mbstate_t));
1042 size_t __len = __high - __low;
1043 size_t __conv = wcsrtombs(__dest, &__low, __len, &__state);
1044 if (__conv == __len)
1049 ctype_byname<wchar_t>::
1050 ctype_byname(const char* /*__s*/, size_t __refs)
1051 : ctype<wchar_t>(__refs) { }
1053 locale::id collate<wchar_t>::id;
1056 collate(size_t __refs)
1057 : _Collate<wchar_t> (__refs) { }
1064 do_compare(const wchar_t* /*__lo1*/, const wchar_t* /*__hi1*/,
1065 const wchar_t* /*__lo2*/, const wchar_t* /*__hi2*/) const
1067 return 0; // XXX not done
1070 wstring collate<wchar_t>::
1071 do_transform(const wchar_t* /*__lo*/, const wchar_t* /*__hi*/) const
1073 return wstring(); // XXX not done
1076 long collate<wchar_t>::
1077 do_hash(const wchar_t* /*__lo*/, const wchar_t* /*__hi*/) const
1079 return 0; // XXX not done
1082 numpunct_byname<wchar_t>::
1083 numpunct_byname(const char* /*__s*/, size_t __refs)
1084 : numpunct<wchar_t> (__refs) { }
1086 collate_byname<wchar_t>::
1087 collate_byname(const char* /*__s*/, size_t __refs)
1088 : collate<wchar_t> (__refs) { }
1090 moneypunct_byname<wchar_t, false>::
1091 moneypunct_byname(const char* /*__s*/, size_t __refs)
1092 : moneypunct<wchar_t, false> (__refs) { }
1094 moneypunct_byname<wchar_t, true>::
1095 moneypunct_byname(const char* /*__s*/, size_t __refs)
1096 : moneypunct<wchar_t, true> (__refs) { }
1098 messages_byname<wchar_t>::
1099 messages_byname(const char* /*__s*/, size_t __refs)
1100 : messages<wchar_t> (__refs) { }
1101 #endif // _GLIBCPP_USE_WCHAR_T