Revert r135493 & r135463
[official-gcc.git] / libstdc++-v3 / src / ctype.cc
bloba77e8e5b010926941bb8032fb77aa4842b9220e5
1 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005,
2 // 2006, 2007
3 // 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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.
30 #include <locale>
31 #include <cstdlib>
32 #include <cstring>
34 _GLIBCXX_BEGIN_NAMESPACE(std)
36 // Definitions for static const data members of ctype_base.
37 const ctype_base::mask ctype_base::space;
38 const ctype_base::mask ctype_base::print;
39 const ctype_base::mask ctype_base::cntrl;
40 const ctype_base::mask ctype_base::upper;
41 const ctype_base::mask ctype_base::lower;
42 const ctype_base::mask ctype_base::alpha;
43 const ctype_base::mask ctype_base::digit;
44 const ctype_base::mask ctype_base::punct;
45 const ctype_base::mask ctype_base::xdigit;
46 const ctype_base::mask ctype_base::alnum;
47 const ctype_base::mask ctype_base::graph;
49 // Definitions for locale::id of standard facets that are specialized.
50 locale::id ctype<char>::id;
52 #ifdef _GLIBCXX_USE_WCHAR_T
53 locale::id ctype<wchar_t>::id;
54 #endif
56 template<>
57 const ctype<char>&
58 use_facet<ctype<char> >(const locale& __loc)
60 size_t __i = ctype<char>::id._M_id();
61 const locale::_Impl* __tmp = __loc._M_impl;
62 return static_cast<const ctype<char>&>(*(__tmp->_M_facets[__i]));
65 #ifdef _GLIBCXX_USE_WCHAR_T
66 template<>
67 const ctype<wchar_t>&
68 use_facet<ctype<wchar_t> >(const locale& __loc)
70 size_t __i = ctype<wchar_t>::id._M_id();
71 const locale::_Impl* __tmp = __loc._M_impl;
72 return static_cast<const ctype<wchar_t>&>(*(__tmp->_M_facets[__i]));
74 #endif
76 // XXX At some point, just rename this file to ctype_configure_char.cc
77 // and compile it as a separate file instead of including it here.
78 // Platform-specific initialization code for ctype tables.
79 #include <bits/ctype_noninline.h>
81 const size_t ctype<char>::table_size;
83 ctype<char>::~ctype()
85 _S_destroy_c_locale(_M_c_locale_ctype);
86 if (_M_del)
87 delete[] this->table();
90 #ifdef _GLIBCXX_USE_WCHAR_T
91 ctype<wchar_t>::ctype(size_t __refs)
92 : __ctype_abstract_base<wchar_t>(__refs),
93 _M_c_locale_ctype(_S_get_c_locale()), _M_narrow_ok(false)
94 { _M_initialize_ctype(); }
96 ctype<wchar_t>::ctype(__c_locale __cloc, size_t __refs)
97 : __ctype_abstract_base<wchar_t>(__refs),
98 _M_c_locale_ctype(_S_clone_c_locale(__cloc)), _M_narrow_ok(false)
99 { _M_initialize_ctype(); }
101 ctype<wchar_t>::~ctype()
102 { _S_destroy_c_locale(_M_c_locale_ctype); }
104 ctype_byname<wchar_t>::ctype_byname(const char* __s, size_t __refs)
105 : ctype<wchar_t>(__refs)
107 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
109 this->_S_destroy_c_locale(this->_M_c_locale_ctype);
110 this->_S_create_c_locale(this->_M_c_locale_ctype, __s);
111 this->_M_initialize_ctype();
115 ctype_byname<wchar_t>::~ctype_byname()
118 #endif
120 _GLIBCXX_END_NAMESPACE