1 // Wrapper for underlying C-language localization -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
27 // ISO C++ 14882: 22.8 Standard locale categories.
30 // Written by Benjamin Kosnik <bkoz@redhat.com>
36 #include <bits/c++locale_internal.h>
38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
45 const __c_locale& __cloc) throw()
48 __v = __strtof_l(__s, &__sanity, __cloc);
50 // _GLIBCXX_RESOLVE_LIB_DEFECTS
51 // 23. Num_get overflow result.
52 if (__sanity == __s || *__sanity != '\0')
55 __err = ios_base::failbit;
57 else if (__v == numeric_limits<float>::infinity())
59 __v = numeric_limits<float>::max();
60 __err = ios_base::failbit;
62 else if (__v == -numeric_limits<float>::infinity())
64 __v = -numeric_limits<float>::max();
65 __err = ios_base::failbit;
71 __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
72 const __c_locale& __cloc) throw()
75 __v = __strtod_l(__s, &__sanity, __cloc);
77 // _GLIBCXX_RESOLVE_LIB_DEFECTS
78 // 23. Num_get overflow result.
79 if (__sanity == __s || *__sanity != '\0')
82 __err = ios_base::failbit;
84 else if (__v == numeric_limits<double>::infinity())
86 __v = numeric_limits<double>::max();
87 __err = ios_base::failbit;
89 else if (__v == -numeric_limits<double>::infinity())
91 __v = -numeric_limits<double>::max();
92 __err = ios_base::failbit;
98 __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
99 const __c_locale& __cloc) throw()
102 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
103 // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
105 __v = strtold_l(__s, &__sanity, __cloc);
107 __v = __strtold_l(__s, &__sanity, __cloc);
110 // _GLIBCXX_RESOLVE_LIB_DEFECTS
111 // 23. Num_get overflow result.
112 if (__sanity == __s || *__sanity != '\0')
115 __err = ios_base::failbit;
117 else if (__v == numeric_limits<long double>::infinity())
119 __v = numeric_limits<long double>::max();
120 __err = ios_base::failbit;
122 else if (__v == -numeric_limits<long double>::infinity())
124 __v = -numeric_limits<long double>::max();
125 __err = ios_base::failbit;
130 locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
133 __cloc = __newlocale(1 << LC_ALL, __s, __old);
136 // This named locale is not supported by the underlying OS.
137 __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
143 locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
145 if (__cloc && _S_get_c_locale() != __cloc)
146 __freelocale(__cloc);
150 locale::facet::_S_clone_c_locale(__c_locale& __cloc) throw()
151 { return __duplocale(__cloc); }
154 locale::facet::_S_lc_ctype_c_locale(__c_locale __cloc, const char* __s)
156 __c_locale __dup = __duplocale(__cloc);
157 if (__dup == __c_locale(0))
158 __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
160 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
161 __c_locale __changed = __newlocale(LC_CTYPE_MASK, __s, __dup);
163 __c_locale __changed = __newlocale(1 << LC_CTYPE, __s, __dup);
165 if (__changed == __c_locale(0))
168 __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale "
174 _GLIBCXX_END_NAMESPACE_VERSION
177 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
179 _GLIBCXX_BEGIN_NAMESPACE_VERSION
181 const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
197 _GLIBCXX_END_NAMESPACE_VERSION
200 namespace std _GLIBCXX_VISIBILITY(default)
202 _GLIBCXX_BEGIN_NAMESPACE_VERSION
204 const char* const* const locale::_S_categories = __gnu_cxx::category_names;
206 _GLIBCXX_END_NAMESPACE_VERSION
209 // XXX GLIBCXX_ABI Deprecated
210 #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
211 #define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
212 extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
213 _GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
214 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT