1 // Wrapper for underlying C-language localization -*- C++ -*-
3 // Copyright (C) 2001-2013 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.8 Standard locale categories.
29 // Written by Benjamin Kosnik <bkoz@redhat.com>
35 #include <bits/c++locale_internal.h>
37 namespace std _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
43 __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
44 const __c_locale& __cloc) throw()
47 __v = __strtof_l(__s, &__sanity, __cloc);
49 // _GLIBCXX_RESOLVE_LIB_DEFECTS
50 // 23. Num_get overflow result.
51 if (__sanity == __s || *__sanity != '\0')
54 __err = ios_base::failbit;
56 else if (__v == numeric_limits<float>::infinity())
58 __v = numeric_limits<float>::max();
59 __err = ios_base::failbit;
61 else if (__v == -numeric_limits<float>::infinity())
63 __v = -numeric_limits<float>::max();
64 __err = ios_base::failbit;
70 __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
71 const __c_locale& __cloc) throw()
74 __v = __strtod_l(__s, &__sanity, __cloc);
76 // _GLIBCXX_RESOLVE_LIB_DEFECTS
77 // 23. Num_get overflow result.
78 if (__sanity == __s || *__sanity != '\0')
81 __err = ios_base::failbit;
83 else if (__v == numeric_limits<double>::infinity())
85 __v = numeric_limits<double>::max();
86 __err = ios_base::failbit;
88 else if (__v == -numeric_limits<double>::infinity())
90 __v = -numeric_limits<double>::max();
91 __err = ios_base::failbit;
97 __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
98 const __c_locale& __cloc) throw()
101 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
102 // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
104 __v = strtold_l(__s, &__sanity, __cloc);
106 __v = __strtold_l(__s, &__sanity, __cloc);
109 // _GLIBCXX_RESOLVE_LIB_DEFECTS
110 // 23. Num_get overflow result.
111 if (__sanity == __s || *__sanity != '\0')
114 __err = ios_base::failbit;
116 else if (__v == numeric_limits<long double>::infinity())
118 __v = numeric_limits<long double>::max();
119 __err = ios_base::failbit;
121 else if (__v == -numeric_limits<long double>::infinity())
123 __v = -numeric_limits<long double>::max();
124 __err = ios_base::failbit;
129 locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
132 __cloc = __newlocale(1 << LC_ALL, __s, __old);
135 // This named locale is not supported by the underlying OS.
136 __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
142 locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
144 if (__cloc && _S_get_c_locale() != __cloc)
145 __freelocale(__cloc);
149 locale::facet::_S_clone_c_locale(__c_locale& __cloc) throw()
150 { return __duplocale(__cloc); }
153 locale::facet::_S_lc_ctype_c_locale(__c_locale __cloc, const char* __s)
155 __c_locale __dup = __duplocale(__cloc);
156 if (__dup == __c_locale(0))
157 __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
159 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
160 __c_locale __changed = __newlocale(LC_CTYPE_MASK, __s, __dup);
162 __c_locale __changed = __newlocale(1 << LC_CTYPE, __s, __dup);
164 if (__changed == __c_locale(0))
167 __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
173 _GLIBCXX_END_NAMESPACE_VERSION
176 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
178 _GLIBCXX_BEGIN_NAMESPACE_VERSION
180 const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
196 _GLIBCXX_END_NAMESPACE_VERSION
199 namespace std _GLIBCXX_VISIBILITY(default)
201 _GLIBCXX_BEGIN_NAMESPACE_VERSION
203 const char* const* const locale::_S_categories = __gnu_cxx::category_names;
205 _GLIBCXX_END_NAMESPACE_VERSION
208 // XXX GLIBCXX_ABI Deprecated
209 #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
210 #define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
211 extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
212 _GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
213 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT