xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/config/locale/generic/numeric_members.cc (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 // std::numpunct implementation details, generic version -*- C++ -*-
2 
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 //
26 // ISO C++ 14882: 22.2.3.1.2  numpunct virtual functions
27 //
28 
29 // Written by Benjamin Kosnik <bkoz@redhat.com>
30 
31 #include <locale>
32 
33 _GLIBCXX_BEGIN_NAMESPACE(std)
34 
35   template<>
36     void
37     numpunct<char>::_M_initialize_numpunct(__c_locale)
38     {
39       // "C" locale
40       if (!_M_data)
41 	_M_data = new __numpunct_cache<char>;
42 
43       _M_data->_M_grouping = "";
44       _M_data->_M_grouping_size = 0;
45       _M_data->_M_use_grouping = false;
46 
47       _M_data->_M_decimal_point = '.';
48       _M_data->_M_thousands_sep = ',';
49 
50       for (size_t __i = 0; __i < __num_base::_S_oend; ++__i)
51 	_M_data->_M_atoms_out[__i] = __num_base::_S_atoms_out[__i];
52 
53       for (size_t __i = 0; __i < __num_base::_S_iend; ++__i)
54 	_M_data->_M_atoms_in[__i] = __num_base::_S_atoms_in[__i];
55 
56       _M_data->_M_truename = "true";
57       _M_data->_M_truename_size = 4;
58       _M_data->_M_falsename = "false";
59       _M_data->_M_falsename_size = 5;
60     }
61 
62   template<>
63     numpunct<char>::~numpunct()
64     { delete _M_data; }
65 
66 #ifdef _GLIBCXX_USE_WCHAR_T
67   template<>
68     void
69     numpunct<wchar_t>::_M_initialize_numpunct(__c_locale)
70     {
71       // "C" locale
72       if (!_M_data)
73 	_M_data = new __numpunct_cache<wchar_t>;
74 
75       _M_data->_M_grouping = "";
76       _M_data->_M_grouping_size = 0;
77       _M_data->_M_use_grouping = false;
78 
79       _M_data->_M_decimal_point = L'.';
80       _M_data->_M_thousands_sep = L',';
81 
82       // Use ctype::widen code without the facet...
83       for (size_t __i = 0; __i < __num_base::_S_oend; ++__i)
84 	_M_data->_M_atoms_out[__i] =
85 	  static_cast<wchar_t>(__num_base::_S_atoms_out[__i]);
86 
87       for (size_t __i = 0; __i < __num_base::_S_iend; ++__i)
88 	_M_data->_M_atoms_in[__i] =
89 	  static_cast<wchar_t>(__num_base::_S_atoms_in[__i]);
90 
91       _M_data->_M_truename = L"true";
92       _M_data->_M_truename_size = 4;
93       _M_data->_M_falsename = L"false";
94       _M_data->_M_falsename_size = 5;
95     }
96 
97   template<>
98     numpunct<wchar_t>::~numpunct()
99     { delete _M_data; }
100 #endif
101 
102 _GLIBCXX_END_NAMESPACE
103 
104