1 // Wrapper for underlying C-language localization -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
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 _GLIBCXX_BEGIN_NAMESPACE(std)
42 __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
43 const __c_locale& __cloc)
46 __v = __strtof_l(__s, &__sanity, __cloc);
48 // _GLIBCXX_RESOLVE_LIB_DEFECTS
49 // 23. Num_get overflow result.
50 if (__sanity == __s || *__sanity != '\0')
53 __err = ios_base::failbit;
55 else if (__v == numeric_limits<float>::infinity())
57 __v = numeric_limits<float>::max();
58 __err = ios_base::failbit;
60 else if (__v == -numeric_limits<float>::infinity())
62 __v = -numeric_limits<float>::max();
63 __err = ios_base::failbit;
69 __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
70 const __c_locale& __cloc)
73 __v = __strtod_l(__s, &__sanity, __cloc);
75 // _GLIBCXX_RESOLVE_LIB_DEFECTS
76 // 23. Num_get overflow result.
77 if (__sanity == __s || *__sanity != '\0')
80 __err = ios_base::failbit;
82 else if (__v == numeric_limits<double>::infinity())
84 __v = numeric_limits<double>::max();
85 __err = ios_base::failbit;
87 else if (__v == -numeric_limits<double>::infinity())
89 __v = -numeric_limits<double>::max();
90 __err = ios_base::failbit;
96 __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
97 const __c_locale& __cloc)
100 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
101 // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
103 __v = strtold_l(__s, &__sanity, __cloc);
105 __v = __strtold_l(__s, &__sanity, __cloc);
108 // _GLIBCXX_RESOLVE_LIB_DEFECTS
109 // 23. Num_get overflow result.
110 if (__sanity == __s || *__sanity != '\0')
113 __err = ios_base::failbit;
115 else if (__v == numeric_limits<long double>::infinity())
117 __v = numeric_limits<long double>::max();
118 __err = ios_base::failbit;
120 else if (__v == -numeric_limits<long double>::infinity())
122 __v = -numeric_limits<long double>::max();
123 __err = ios_base::failbit;
128 locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
131 __cloc = __newlocale(1 << LC_ALL, __s, __old);
134 // This named locale is not supported by the underlying OS.
135 __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
141 locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
143 if (__cloc && _S_get_c_locale() != __cloc)
144 __freelocale(__cloc);
148 locale::facet::_S_clone_c_locale(__c_locale& __cloc)
149 { return __duplocale(__cloc); }
151 _GLIBCXX_END_NAMESPACE
153 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
155 const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
171 _GLIBCXX_END_NAMESPACE
173 _GLIBCXX_BEGIN_NAMESPACE(std)
175 const char* const* const locale::_S_categories = __gnu_cxx::category_names;
177 _GLIBCXX_END_NAMESPACE
179 // XXX GLIBCXX_ABI Deprecated
180 #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
181 #define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
182 extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
183 _GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
184 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT