2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / config / locale / gnu / c_locale.cc
blobb808f70e5f96da020087e120a001a765cf16fa0c
1 // Wrapper for underlying C-language localization -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
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 2, or (at your option)
9 // any later version.
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 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 22.8 Standard locale categories.
34 // Written by Benjamin Kosnik <bkoz@redhat.com>
36 #include <cerrno> // For errno
37 #include <locale>
38 #include <stdexcept>
39 #include <langinfo.h>
40 #include <bits/c++locale_internal.h>
42 namespace std
44 template<>
45 void
46 __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err,
47 const __c_locale& __cloc)
49 if (!(__err & ios_base::failbit))
51 char* __sanity;
52 errno = 0;
53 float __f = __strtof_l(__s, &__sanity, __cloc);
54 if (__sanity != __s && errno != ERANGE)
55 __v = __f;
56 else
57 __err |= ios_base::failbit;
61 template<>
62 void
63 __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err,
64 const __c_locale& __cloc)
66 if (!(__err & ios_base::failbit))
68 char* __sanity;
69 errno = 0;
70 double __d = __strtod_l(__s, &__sanity, __cloc);
71 if (__sanity != __s && errno != ERANGE)
72 __v = __d;
73 else
74 __err |= ios_base::failbit;
78 template<>
79 void
80 __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
81 const __c_locale& __cloc)
83 if (!(__err & ios_base::failbit))
85 char* __sanity;
86 errno = 0;
87 long double __ld = __strtold_l(__s, &__sanity, __cloc);
88 if (__sanity != __s && errno != ERANGE)
89 __v = __ld;
90 else
91 __err |= ios_base::failbit;
95 void
96 locale::facet::_S_create_c_locale(__c_locale& __cloc, const char* __s,
97 __c_locale __old)
99 __cloc = __newlocale(1 << LC_ALL, __s, __old);
100 if (!__cloc)
102 // This named locale is not supported by the underlying OS.
103 __throw_runtime_error("locale::facet::_S_create_c_locale "
104 "name not valid");
108 void
109 locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
111 if (_S_get_c_locale() != __cloc)
112 __freelocale(__cloc);
115 __c_locale
116 locale::facet::_S_clone_c_locale(__c_locale& __cloc)
117 { return __duplocale(__cloc); }
118 } // namespace std
120 namespace __gnu_cxx
122 const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
124 "LC_CTYPE",
125 "LC_NUMERIC",
126 "LC_TIME",
127 "LC_COLLATE",
128 "LC_MONETARY",
129 "LC_MESSAGES",
130 "LC_PAPER",
131 "LC_NAME",
132 "LC_ADDRESS",
133 "LC_TELEPHONE",
134 "LC_MEASUREMENT",
135 "LC_IDENTIFICATION"
139 namespace std
141 const char* const* const locale::_S_categories = __gnu_cxx::category_names;
142 } // namespace std