]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/config/locale/gnu/c_locale.cc
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / config / locale / gnu / c_locale.cc
1 // Wrapper for underlying C-language localization -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
5 //
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 2, or (at your option)
10 // any later version.
11
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.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 //
32 // ISO C++ 14882: 22.8  Standard locale categories.
33 //
34
35 // Written by Benjamin Kosnik <bkoz@redhat.com>
36
37 #include <locale>
38 #include <stdexcept>
39 #include <langinfo.h>
40 #include <bits/c++locale_internal.h>
41
42 _GLIBCXX_BEGIN_NAMESPACE(std)
43
44   template<>
45     void
46     __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, 
47                    const __c_locale& __cloc)
48     {
49       char* __sanity;
50       float __f = __strtof_l(__s, &__sanity, __cloc);
51       if (__sanity != __s && __f != __builtin_huge_valf()
52           && __f != -__builtin_huge_valf())
53         __v = __f;
54       else
55         __err |= ios_base::failbit;
56     }
57
58   template<>
59     void
60     __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err, 
61                    const __c_locale& __cloc)
62     {
63       char* __sanity;
64       double __d = __strtod_l(__s, &__sanity, __cloc);
65       if (__sanity != __s && __d != __builtin_huge_val()
66           && __d != -__builtin_huge_val())
67         __v = __d;
68       else
69         __err |= ios_base::failbit;
70     }
71
72   template<>
73     void
74     __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
75                    const __c_locale& __cloc)
76     {
77       char* __sanity;
78 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
79       // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
80       // glibc versions.
81       long double __ld = strtold_l(__s, &__sanity, __cloc);
82 #else
83       long double __ld = __strtold_l(__s, &__sanity, __cloc);
84 #endif
85       if (__sanity != __s && __ld != __builtin_huge_vall()
86           && __ld != -__builtin_huge_vall())
87         __v = __ld;
88       else
89         __err |= ios_base::failbit;
90     }
91
92   void
93   locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s, 
94                                     __c_locale __old)
95   {
96     __cloc = __newlocale(1 << LC_ALL, __s, __old);
97     if (!__cloc)
98       {
99         // This named locale is not supported by the underlying OS.
100         __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
101                               "name not valid"));
102       }
103   }
104   
105   void
106   locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
107   {
108     if (__cloc && _S_get_c_locale() != __cloc)
109       __freelocale(__cloc); 
110   }
111
112   __c_locale
113   locale::facet::_S_clone_c_locale(__c_locale& __cloc)
114   { return __duplocale(__cloc); }
115
116 _GLIBCXX_END_NAMESPACE
117
118 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
119
120   const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
121     {
122       "LC_CTYPE", 
123       "LC_NUMERIC",
124       "LC_TIME", 
125       "LC_COLLATE", 
126       "LC_MONETARY",
127       "LC_MESSAGES", 
128       "LC_PAPER", 
129       "LC_NAME", 
130       "LC_ADDRESS",
131       "LC_TELEPHONE", 
132       "LC_MEASUREMENT", 
133       "LC_IDENTIFICATION" 
134     };
135
136 _GLIBCXX_END_NAMESPACE
137
138 _GLIBCXX_BEGIN_NAMESPACE(std)
139
140   const char* const* const locale::_S_categories = __gnu_cxx::category_names;
141
142 _GLIBCXX_END_NAMESPACE
143
144 // XXX GLIBCXX_ABI Deprecated
145 #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
146 #define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
147   extern "C" void ldbl (void) __attribute__ ((alias (#dbl)))
148 _GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct);
149 #endif // _GLIBCXX_LONG_DOUBLE_COMPAT