]>
Commit | Line | Data |
---|---|---|
a98e4e62 | 1 | // localization implementation details, DragonFly version -*- C++ -*- |
dbed5a9b | 2 | |
5624e564 | 3 | // Copyright (C) 2014-2015 Free Software Foundation, Inc. |
dbed5a9b JM |
4 | // |
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) | |
9 | // any later version. | |
10 | ||
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. | |
15 | ||
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. | |
19 | ||
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/>. | |
24 | ||
25 | // | |
26 | // ISO C++ 14882: 22.8 Standard locale categories. | |
27 | // | |
28 | ||
29 | // Written by Benjamin Kosnik <bkoz@redhat.com> | |
a98e4e62 | 30 | // Modified for DragonFly by John Marino <gnugcc@marino.st> |
dbed5a9b | 31 | |
a98e4e62 | 32 | #include <cstdlib> |
dbed5a9b | 33 | #include <locale> |
a98e4e62 | 34 | #include <stdexcept> |
dbed5a9b | 35 | #include <limits> |
a98e4e62 JM |
36 | #include <langinfo.h> |
37 | #include <xlocale.h> | |
dbed5a9b JM |
38 | |
39 | namespace std _GLIBCXX_VISIBILITY(default) | |
40 | { | |
41 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
42 | ||
43 | template<> | |
44 | void | |
45 | __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, | |
a98e4e62 | 46 | const __c_locale& __cloc) throw() |
dbed5a9b | 47 | { |
dbed5a9b | 48 | char* __sanity; |
a98e4e62 | 49 | __v = strtof_l(__s, &__sanity, (locale_t)__cloc); |
dbed5a9b JM |
50 | |
51 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
52 | // 23. Num_get overflow result. | |
53 | if (__sanity == __s || *__sanity != '\0') | |
54 | { | |
55 | __v = 0.0f; | |
56 | __err = ios_base::failbit; | |
57 | } | |
a98e4e62 | 58 | else if (__v == numeric_limits<float>::infinity()) |
dbed5a9b | 59 | { |
a98e4e62 JM |
60 | __v = numeric_limits<float>::max(); |
61 | __err = ios_base::failbit; | |
62 | } | |
63 | else if (__v == -numeric_limits<float>::infinity()) | |
64 | { | |
65 | __v = -numeric_limits<float>::max(); | |
dbed5a9b JM |
66 | __err = ios_base::failbit; |
67 | } | |
dbed5a9b JM |
68 | } |
69 | ||
70 | template<> | |
71 | void | |
72 | __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err, | |
a98e4e62 | 73 | const __c_locale& __cloc) throw() |
dbed5a9b | 74 | { |
dbed5a9b | 75 | char* __sanity; |
a98e4e62 | 76 | __v = strtod_l(__s, &__sanity, (locale_t)__cloc); |
dbed5a9b JM |
77 | |
78 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
79 | // 23. Num_get overflow result. | |
80 | if (__sanity == __s || *__sanity != '\0') | |
81 | { | |
82 | __v = 0.0; | |
83 | __err = ios_base::failbit; | |
84 | } | |
a98e4e62 | 85 | else if (__v == numeric_limits<double>::infinity()) |
dbed5a9b | 86 | { |
a98e4e62 JM |
87 | __v = numeric_limits<double>::max(); |
88 | __err = ios_base::failbit; | |
89 | } | |
90 | else if (__v == -numeric_limits<double>::infinity()) | |
91 | { | |
92 | __v = -numeric_limits<double>::max(); | |
dbed5a9b JM |
93 | __err = ios_base::failbit; |
94 | } | |
dbed5a9b JM |
95 | } |
96 | ||
97 | template<> | |
98 | void | |
a98e4e62 JM |
99 | __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err, |
100 | const __c_locale& __cloc) throw() | |
dbed5a9b | 101 | { |
dbed5a9b | 102 | char* __sanity; |
a98e4e62 | 103 | __v = strtold_l(__s, &__sanity, (locale_t)__cloc); |
dbed5a9b JM |
104 | |
105 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
106 | // 23. Num_get overflow result. | |
107 | if (__sanity == __s || *__sanity != '\0') | |
dbed5a9b JM |
108 | { |
109 | __v = 0.0l; | |
110 | __err = ios_base::failbit; | |
111 | } | |
a98e4e62 | 112 | else if (__v == numeric_limits<long double>::infinity()) |
dbed5a9b | 113 | { |
a98e4e62 JM |
114 | __v = numeric_limits<long double>::max(); |
115 | __err = ios_base::failbit; | |
116 | } | |
117 | else if (__v == -numeric_limits<long double>::infinity()) | |
118 | { | |
119 | __v = -numeric_limits<long double>::max(); | |
dbed5a9b JM |
120 | __err = ios_base::failbit; |
121 | } | |
dbed5a9b JM |
122 | } |
123 | ||
dbed5a9b JM |
124 | void |
125 | locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s, | |
a98e4e62 | 126 | __c_locale __old) |
dbed5a9b | 127 | { |
a98e4e62 JM |
128 | __cloc = (__c_locale)newlocale(LC_ALL_MASK, __s, (locale_t)__old); |
129 | if (!__cloc) | |
130 | { | |
131 | // This named locale is not supported by the underlying OS. | |
132 | __throw_runtime_error(__N("locale::facet::_S_create_c_locale " | |
133 | "name not valid")); | |
134 | } | |
dbed5a9b JM |
135 | } |
136 | ||
137 | void | |
138 | locale::facet::_S_destroy_c_locale(__c_locale& __cloc) | |
a98e4e62 JM |
139 | { |
140 | if (__cloc && _S_get_c_locale() != __cloc) | |
141 | freelocale((locale_t)__cloc); | |
142 | } | |
dbed5a9b JM |
143 | |
144 | __c_locale | |
a98e4e62 JM |
145 | locale::facet::_S_clone_c_locale(__c_locale& __cloc) throw() |
146 | { return (__c_locale)duplocale((locale_t)__cloc); } | |
dbed5a9b JM |
147 | |
148 | __c_locale | |
a98e4e62 JM |
149 | locale::facet::_S_lc_ctype_c_locale(__c_locale __cloc, const char* __s) |
150 | { | |
151 | __c_locale __dup = (__c_locale)duplocale((locale_t)__cloc); | |
152 | if (__dup == __c_locale(0)) | |
153 | __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale " | |
154 | "duplocale error")); | |
155 | __c_locale __changed = (__c_locale)newlocale(LC_CTYPE_MASK, __s, | |
156 | (locale_t)__dup); | |
157 | if (__changed == __c_locale(0)) | |
158 | { | |
159 | freelocale((locale_t)__dup); | |
160 | __throw_runtime_error(__N("locale::facet::_S_lc_ctype_c_locale " | |
161 | "newlocale error")); | |
162 | } | |
163 | return __changed; | |
164 | } | |
dbed5a9b JM |
165 | |
166 | _GLIBCXX_END_NAMESPACE_VERSION | |
167 | } // namespace | |
168 | ||
169 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) | |
170 | { | |
171 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
172 | ||
173 | const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] = | |
174 | { | |
175 | "LC_CTYPE", | |
176 | "LC_NUMERIC", | |
177 | "LC_TIME", | |
178 | "LC_COLLATE", | |
179 | "LC_MONETARY", | |
180 | "LC_MESSAGES" | |
181 | }; | |
182 | ||
183 | _GLIBCXX_END_NAMESPACE_VERSION | |
184 | } // namespace | |
185 | ||
186 | namespace std _GLIBCXX_VISIBILITY(default) | |
187 | { | |
188 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
189 | ||
190 | const char* const* const locale::_S_categories = __gnu_cxx::category_names; | |
191 | ||
192 | _GLIBCXX_END_NAMESPACE_VERSION | |
193 | } // namespace | |
194 | ||
195 | // XXX GLIBCXX_ABI Deprecated | |
196 | #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT | |
197 | #define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \ | |
198 | extern "C" void ldbl (void) __attribute__ ((alias (#dbl))) | |
a98e4e62 | 199 | _GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct); |
dbed5a9b | 200 | #endif // _GLIBCXX_LONG_DOUBLE_COMPAT |