1 // std::numpunct implementation details, DragonFly version -*- C++ -*-
3 // Copyright (C) 2015 Free Software Foundation, Inc.
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)
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.
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.
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/>.
26 // ISO C++ 14882: 22.2.3.1.2 numpunct virtual functions
29 // Written by Benjamin Kosnik <bkoz@redhat.com>
30 // Modified for DragonFly by John Marino <gnugcc@marino.st>
36 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
42 numpunct<char>::_M_initialize_numpunct(__c_locale __cloc)
45 _M_data = new __numpunct_cache<char>;
50 _M_data->_M_grouping = "";
51 _M_data->_M_grouping_size = 0;
52 _M_data->_M_use_grouping = false;
54 _M_data->_M_decimal_point = '.';
55 _M_data->_M_thousands_sep = ',';
57 for (size_t __i = 0; __i < __num_base::_S_oend; ++__i)
58 _M_data->_M_atoms_out[__i] = __num_base::_S_atoms_out[__i];
60 for (size_t __j = 0; __j < __num_base::_S_iend; ++__j)
61 _M_data->_M_atoms_in[__j] = __num_base::_S_atoms_in[__j];
66 lconv* lc = localeconv_l((locale_t) __cloc);
68 // Decimal point should always be defined, but check null anyway
69 if (lc->decimal_point == NULL)
71 // Not defined, so use "C" locale default
72 _M_data->_M_decimal_point = '.';
76 _M_data->_M_decimal_point = lc->decimal_point[0];
78 // Check for NULL, which implies no grouping.
79 if (lc->thousands_sep == NULL || lc->thousands_sep[0] == '\0')
81 // Like in "C" locale.
82 _M_data->_M_grouping = "";
83 _M_data->_M_grouping_size = 0;
84 _M_data->_M_use_grouping = false;
85 _M_data->_M_thousands_sep = ',';
89 _M_data->_M_thousands_sep = lc->thousands_sep[0];
91 const char* __src = lc->grouping;
92 const size_t __len = strlen(__src);
97 char* __dst = new char[__len + 1];
98 memcpy(__dst, __src, __len + 1);
99 _M_data->_M_grouping = __dst;
100 _M_data->_M_use_grouping = true;
106 __throw_exception_again;
111 _M_data->_M_grouping = "";
112 _M_data->_M_use_grouping = false;
114 _M_data->_M_grouping_size = __len;
118 // NB: There is no way to extact this info from posix locales.
119 // _M_truename = __nl_langinfo_l(YESSTR, __cloc);
120 _M_data->_M_truename = "true";
121 _M_data->_M_truename_size = 4;
122 // _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
123 _M_data->_M_falsename = "false";
124 _M_data->_M_falsename_size = 5;
128 numpunct<char>::~numpunct()
130 if (_M_data->_M_grouping_size)
131 delete [] _M_data->_M_grouping;
135 #ifdef _GLIBCXX_USE_WCHAR_T
138 numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc)
141 _M_data = new __numpunct_cache<wchar_t>;
146 _M_data->_M_grouping = "";
147 _M_data->_M_grouping_size = 0;
148 _M_data->_M_use_grouping = false;
150 _M_data->_M_decimal_point = L'.';
151 _M_data->_M_thousands_sep = L',';
153 // Use ctype::widen code without the facet...
154 for (size_t __i = 0; __i < __num_base::_S_oend; ++__i)
155 _M_data->_M_atoms_out[__i] =
156 static_cast<wchar_t>(__num_base::_S_atoms_out[__i]);
158 for (size_t __j = 0; __j < __num_base::_S_iend; ++__j)
159 _M_data->_M_atoms_in[__j] =
160 static_cast<wchar_t>(__num_base::_S_atoms_in[__j]);
165 lconv* lc = localeconv_l((locale_t) __cloc);
167 // Decimal point should always be defined, but check null anyway
168 if (lc->decimal_point == NULL)
170 // Not defined, so use "C" locale default
171 _M_data->_M_decimal_point = L'.';
175 _M_data->_M_decimal_point = (wchar_t)lc->decimal_point[0];
177 // Check for NULL, which implies no grouping.
178 if (lc->thousands_sep == NULL || lc->thousands_sep[0] == '\0')
180 // Like in "C" locale.
181 _M_data->_M_grouping = "";
182 _M_data->_M_grouping_size = 0;
183 _M_data->_M_use_grouping = false;
184 _M_data->_M_thousands_sep = L',';
188 _M_data->_M_thousands_sep = (wchar_t)lc->thousands_sep[0];
190 const char* __src = lc->grouping;
191 const size_t __len = strlen(__src);
196 char* __dst = new char[__len + 1];
197 memcpy(__dst, __src, __len + 1);
198 _M_data->_M_grouping = __dst;
204 __throw_exception_again;
209 _M_data->_M_grouping = "";
210 _M_data->_M_use_grouping = false;
212 _M_data->_M_grouping_size = __len;
216 // NB: There is no way to extact this info from posix locales.
217 // _M_truename = __nl_langinfo_l(YESSTR, __cloc);
218 _M_data->_M_truename = L"true";
219 _M_data->_M_truename_size = 4;
220 // _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
221 _M_data->_M_falsename = L"false";
222 _M_data->_M_falsename_size = 5;
226 numpunct<wchar_t>::~numpunct()
228 if (_M_data->_M_grouping_size)
229 delete [] _M_data->_M_grouping;
234 _GLIBCXX_END_NAMESPACE_VERSION