]>
Commit | Line | Data |
---|---|---|
aa118a03 | 1 | // Copyright (C) 1997-2014 Free Software Foundation, Inc. |
38cca750 BK |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
38cca750 BK |
7 | // any later version. |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
748086b7 JJ |
14 | // Under Section 7 of GPL version 3, you are granted additional |
15 | // permissions described in the GCC Runtime Library Exception, version | |
16 | // 3.1, as published by the Free Software Foundation. | |
38cca750 | 17 | |
748086b7 JJ |
18 | // You should have received a copy of the GNU General Public License and |
19 | // a copy of the GCC Runtime Library Exception along with this program; | |
20 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
21 | // <http://www.gnu.org/licenses/>. | |
38cca750 BK |
22 | |
23 | #include <locale> | |
4ba851b5 | 24 | #include <cstdlib> |
538075fe | 25 | #include <cstring> |
38cca750 | 26 | |
12ffa228 BK |
27 | namespace std _GLIBCXX_VISIBILITY(default) |
28 | { | |
29 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 30 | |
82c2e3d4 BK |
31 | // Definitions for static const data members of ctype_base. |
32 | const ctype_base::mask ctype_base::space; | |
33 | const ctype_base::mask ctype_base::print; | |
34 | const ctype_base::mask ctype_base::cntrl; | |
35 | const ctype_base::mask ctype_base::upper; | |
36 | const ctype_base::mask ctype_base::lower; | |
37 | const ctype_base::mask ctype_base::alpha; | |
38 | const ctype_base::mask ctype_base::digit; | |
39 | const ctype_base::mask ctype_base::punct; | |
40 | const ctype_base::mask ctype_base::xdigit; | |
41 | const ctype_base::mask ctype_base::alnum; | |
42 | const ctype_base::mask ctype_base::graph; | |
38cca750 BK |
43 | |
44 | // Definitions for locale::id of standard facets that are specialized. | |
45 | locale::id ctype<char>::id; | |
46 | ||
3d7c150e | 47 | #ifdef _GLIBCXX_USE_WCHAR_T |
38cca750 BK |
48 | locale::id ctype<wchar_t>::id; |
49 | #endif | |
50 | ||
38cca750 BK |
51 | const size_t ctype<char>::table_size; |
52 | ||
53 | ctype<char>::~ctype() | |
54 | { | |
aa53f832 | 55 | _S_destroy_c_locale(_M_c_locale_ctype); |
38cca750 BK |
56 | if (_M_del) |
57 | delete[] this->table(); | |
58 | } | |
59 | ||
1834f167 PC |
60 | // Fill in the narrowing cache and flag whether all values are |
61 | // valid or not. _M_narrow_ok is set to 2 if memcpy can't | |
62 | // be used. | |
63 | void | |
64 | ctype<char>:: | |
65 | _M_narrow_init() const | |
66 | { | |
67 | char __tmp[sizeof(_M_narrow)]; | |
68 | for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i) | |
69 | __tmp[__i] = __i; | |
70 | do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow); | |
71 | ||
72 | _M_narrow_ok = 1; | |
73 | if (__builtin_memcmp(__tmp, _M_narrow, sizeof(_M_narrow))) | |
74 | _M_narrow_ok = 2; | |
75 | else | |
76 | { | |
77 | // Deal with the special case of zero: renarrow with a | |
78 | // different default and compare. | |
79 | char __c; | |
80 | do_narrow(__tmp, __tmp + 1, 1, &__c); | |
81 | if (__c == 1) | |
82 | _M_narrow_ok = 2; | |
83 | } | |
84 | } | |
85 | ||
86 | void | |
87 | ctype<char>:: | |
88 | _M_widen_init() const | |
89 | { | |
90 | char __tmp[sizeof(_M_widen)]; | |
91 | for (size_t __i = 0; __i < sizeof(_M_widen); ++__i) | |
92 | __tmp[__i] = __i; | |
93 | do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen); | |
94 | ||
95 | _M_widen_ok = 1; | |
96 | // Set _M_widen_ok to 2 if memcpy can't be used. | |
97 | if (__builtin_memcmp(__tmp, _M_widen, sizeof(_M_widen))) | |
98 | _M_widen_ok = 2; | |
99 | } | |
100 | ||
3d7c150e | 101 | #ifdef _GLIBCXX_USE_WCHAR_T |
38cca750 | 102 | ctype<wchar_t>::ctype(size_t __refs) |
26c691a8 BK |
103 | : __ctype_abstract_base<wchar_t>(__refs), |
104 | _M_c_locale_ctype(_S_get_c_locale()), _M_narrow_ok(false) | |
105 | { _M_initialize_ctype(); } | |
38cca750 BK |
106 | |
107 | ctype<wchar_t>::ctype(__c_locale __cloc, size_t __refs) | |
26c691a8 BK |
108 | : __ctype_abstract_base<wchar_t>(__refs), |
109 | _M_c_locale_ctype(_S_clone_c_locale(__cloc)), _M_narrow_ok(false) | |
110 | { _M_initialize_ctype(); } | |
38cca750 BK |
111 | |
112 | ctype<wchar_t>::~ctype() | |
aa53f832 | 113 | { _S_destroy_c_locale(_M_c_locale_ctype); } |
38cca750 | 114 | |
681a6919 PC |
115 | ctype_byname<wchar_t>::ctype_byname(const char* __s, size_t __refs) |
116 | : ctype<wchar_t>(__refs) | |
117 | { | |
118 | if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0) | |
119 | { | |
120 | this->_S_destroy_c_locale(this->_M_c_locale_ctype); | |
121 | this->_S_create_c_locale(this->_M_c_locale_ctype, __s); | |
122 | this->_M_initialize_ctype(); | |
123 | } | |
124 | } | |
125 | ||
126 | ctype_byname<wchar_t>::~ctype_byname() | |
127 | { } | |
128 | ||
38cca750 | 129 | #endif |
38cca750 | 130 | |
12ffa228 BK |
131 | _GLIBCXX_END_NAMESPACE_VERSION |
132 | } // namespace |