1 // std::numpunct implementation details, GNU version -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 22.2.3.1.2 numpunct virtual functions
35 // Written by Benjamin Kosnik <bkoz@redhat.com>
38 #include <bits/c++locale_internal.h>
40 _GLIBCXX_BEGIN_NAMESPACE(std
)
44 numpunct
<char>::_M_initialize_numpunct(__c_locale __cloc
)
47 _M_data
= new __numpunct_cache
<char>;
52 _M_data
->_M_grouping
= "";
53 _M_data
->_M_grouping_size
= 0;
54 _M_data
->_M_use_grouping
= false;
56 _M_data
->_M_decimal_point
= '.';
57 _M_data
->_M_thousands_sep
= ',';
59 for (size_t __i
= 0; __i
< __num_base::_S_oend
; ++__i
)
60 _M_data
->_M_atoms_out
[__i
] = __num_base::_S_atoms_out
[__i
];
62 for (size_t __j
= 0; __j
< __num_base::_S_iend
; ++__j
)
63 _M_data
->_M_atoms_in
[__j
] = __num_base::_S_atoms_in
[__j
];
68 _M_data
->_M_decimal_point
= *(__nl_langinfo_l(DECIMAL_POINT
,
70 _M_data
->_M_thousands_sep
= *(__nl_langinfo_l(THOUSANDS_SEP
,
73 // Check for NULL, which implies no grouping.
74 if (_M_data
->_M_thousands_sep
== '\0')
76 // Like in "C" locale.
77 _M_data
->_M_grouping
= "";
78 _M_data
->_M_grouping_size
= 0;
79 _M_data
->_M_use_grouping
= false;
80 _M_data
->_M_thousands_sep
= ',';
84 _M_data
->_M_grouping
= __nl_langinfo_l(GROUPING
, __cloc
);
85 _M_data
->_M_grouping_size
= strlen(_M_data
->_M_grouping
);
89 // NB: There is no way to extact this info from posix locales.
90 // _M_truename = __nl_langinfo_l(YESSTR, __cloc);
91 _M_data
->_M_truename
= "true";
92 _M_data
->_M_truename_size
= 4;
93 // _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
94 _M_data
->_M_falsename
= "false";
95 _M_data
->_M_falsename_size
= 5;
99 numpunct
<char>::~numpunct()
102 #ifdef _GLIBCXX_USE_WCHAR_T
105 numpunct
<wchar_t>::_M_initialize_numpunct(__c_locale __cloc
)
108 _M_data
= new __numpunct_cache
<wchar_t>;
113 _M_data
->_M_grouping
= "";
114 _M_data
->_M_grouping_size
= 0;
115 _M_data
->_M_use_grouping
= false;
117 _M_data
->_M_decimal_point
= L
'.';
118 _M_data
->_M_thousands_sep
= L
',';
120 // Use ctype::widen code without the facet...
121 for (size_t __i
= 0; __i
< __num_base::_S_oend
; ++__i
)
122 _M_data
->_M_atoms_out
[__i
] =
123 static_cast<wchar_t>(__num_base::_S_atoms_out
[__i
]);
125 for (size_t __j
= 0; __j
< __num_base::_S_iend
; ++__j
)
126 _M_data
->_M_atoms_in
[__j
] =
127 static_cast<wchar_t>(__num_base::_S_atoms_in
[__j
]);
132 // NB: In the GNU model wchar_t is always 32 bit wide.
133 union { char *__s
; wchar_t __w
; } __u
;
134 __u
.__s
= __nl_langinfo_l(_NL_NUMERIC_DECIMAL_POINT_WC
, __cloc
);
135 _M_data
->_M_decimal_point
= __u
.__w
;
137 __u
.__s
= __nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC
, __cloc
);
138 _M_data
->_M_thousands_sep
= __u
.__w
;
140 // Check for NULL, which implies no grouping.
141 if (_M_data
->_M_thousands_sep
== L
'\0')
143 // Like in "C" locale.
144 _M_data
->_M_grouping
= "";
145 _M_data
->_M_grouping_size
= 0;
146 _M_data
->_M_use_grouping
= false;
147 _M_data
->_M_thousands_sep
= L
',';
151 _M_data
->_M_grouping
= __nl_langinfo_l(GROUPING
, __cloc
);
152 _M_data
->_M_grouping_size
= strlen(_M_data
->_M_grouping
);
156 // NB: There is no way to extact this info from posix locales.
157 // _M_truename = __nl_langinfo_l(YESSTR, __cloc);
158 _M_data
->_M_truename
= L
"true";
159 _M_data
->_M_truename_size
= 4;
160 // _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
161 _M_data
->_M_falsename
= L
"false";
162 _M_data
->_M_falsename_size
= 5;
166 numpunct
<wchar_t>::~numpunct()
170 _GLIBCXX_END_NAMESPACE