Update Copyright years for files modified in 2010.
[official-gcc.git] / libstdc++-v3 / config / os / gnu-linux / ctype_noninline.h
blob45785d4a5e8535c87df8076adac5a0a0041878f7
1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2007, 2009, 2010
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 // <http://www.gnu.org/licenses/>.
27 /** @file bits/ctype_noninline.h
28 * This is an internal header file, included by other library headers.
29 * Do not attempt to use it directly. @headername{locale}
33 // ISO C++ 14882: 22.1 Locales
36 // Information as gleaned from /usr/include/ctype.h
38 #if _GLIBCXX_C_LOCALE_GNU
39 const ctype_base::mask*
40 ctype<char>::classic_table() throw()
41 { return _S_get_c_locale()->__ctype_b; }
42 #else
43 const ctype_base::mask*
44 ctype<char>::classic_table() throw()
46 const ctype_base::mask* __ret;
47 char* __old = setlocale(LC_CTYPE, NULL);
48 char* __sav = NULL;
49 if (__builtin_strcmp(__old, "C"))
51 const size_t __len = __builtin_strlen(__old) + 1;
52 __sav = new char[__len];
53 __builtin_memcpy(__sav, __old, __len);
54 setlocale(LC_CTYPE, "C");
56 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
57 __ret = *__ctype_b_loc();
58 #else
59 __ret = __ctype_b;
60 #endif
61 if (__sav)
63 setlocale(LC_CTYPE, __sav);
64 delete [] __sav;
66 return __ret;
68 #endif
70 #if _GLIBCXX_C_LOCALE_GNU
71 ctype<char>::ctype(__c_locale __cloc, const mask* __table, bool __del,
72 size_t __refs)
73 : facet(__refs), _M_c_locale_ctype(_S_clone_c_locale(__cloc)),
74 _M_del(__table != 0 && __del),
75 _M_toupper(_M_c_locale_ctype->__ctype_toupper),
76 _M_tolower(_M_c_locale_ctype->__ctype_tolower),
77 _M_table(__table ? __table : _M_c_locale_ctype->__ctype_b),
78 _M_widen_ok(0), _M_narrow_ok(0)
80 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
81 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
83 #else
84 ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
85 size_t __refs)
86 : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()),
87 _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0)
89 char* __old = setlocale(LC_CTYPE, NULL);
90 char* __sav = NULL;
91 if (__builtin_strcmp(__old, "C"))
93 const size_t __len = __builtin_strlen(__old) + 1;
94 __sav = new char[__len];
95 __builtin_memcpy(__sav, __old, __len);
96 setlocale(LC_CTYPE, "C");
98 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
99 _M_toupper = *__ctype_toupper_loc();
100 _M_tolower = *__ctype_tolower_loc();
101 _M_table = __table ? __table : *__ctype_b_loc();
102 #else
103 _M_toupper = __ctype_toupper;
104 _M_tolower = __ctype_tolower;
105 _M_table = __table ? __table : __ctype_b;
106 #endif
107 if (__sav)
109 setlocale(LC_CTYPE, __sav);
110 delete [] __sav;
112 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
113 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
115 #endif
117 #if _GLIBCXX_C_LOCALE_GNU
118 ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
119 : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()),
120 _M_del(__table != 0 && __del),
121 _M_toupper(_M_c_locale_ctype->__ctype_toupper),
122 _M_tolower(_M_c_locale_ctype->__ctype_tolower),
123 _M_table(__table ? __table : _M_c_locale_ctype->__ctype_b),
124 _M_widen_ok(0), _M_narrow_ok(0)
126 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
127 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
129 #else
130 ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
131 : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()),
132 _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0)
134 char* __old = setlocale(LC_CTYPE, NULL);
135 char* __sav = NULL;
136 if (__builtin_strcmp(__old, "C"))
138 const size_t __len = __builtin_strlen(__old) + 1;
139 __sav = new char[__len];
140 __builtin_memcpy(__sav, __old, __len);
141 setlocale(LC_CTYPE, "C");
143 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
144 _M_toupper = *__ctype_toupper_loc();
145 _M_tolower = *__ctype_tolower_loc();
146 _M_table = __table ? __table : *__ctype_b_loc();
147 #else
148 _M_toupper = __ctype_toupper;
149 _M_tolower = __ctype_tolower;
150 _M_table = __table ? __table : __ctype_b;
151 #endif
152 if (__sav)
154 setlocale(LC_CTYPE, __sav);
155 delete [] __sav;
157 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
158 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
160 #endif
162 char
163 ctype<char>::do_toupper(char __c) const
164 { return _M_toupper[static_cast<unsigned char>(__c)]; }
166 const char*
167 ctype<char>::do_toupper(char* __low, const char* __high) const
169 while (__low < __high)
171 *__low = _M_toupper[static_cast<unsigned char>(*__low)];
172 ++__low;
174 return __high;
177 char
178 ctype<char>::do_tolower(char __c) const
179 { return _M_tolower[static_cast<unsigned char>(__c)]; }
181 const char*
182 ctype<char>::do_tolower(char* __low, const char* __high) const
184 while (__low < __high)
186 *__low = _M_tolower[static_cast<unsigned char>(*__low)];
187 ++__low;
189 return __high;