]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.6/config/os/gnu-linux/ctype_noninline.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.6 / config / os / gnu-linux / ctype_noninline.h
1 // Locale support -*- C++ -*-
2
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.
12
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.
17
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.
21
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/>.
26
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}
30  */
31
32 //
33 // ISO C++ 14882: 22.1  Locales
34 //
35
36 // Information as gleaned from /usr/include/ctype.h
37
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()
45   {
46     const ctype_base::mask* __ret;
47     char* __old = setlocale(LC_CTYPE, NULL);
48     char* __sav = NULL;
49     if (__builtin_strcmp(__old, "C"))
50       {
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");
55       }
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)
62       {
63         setlocale(LC_CTYPE, __sav);
64         delete [] __sav;
65       }
66     return __ret;
67   }
68 #endif
69
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)
79   {
80     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
81     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
82   }
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)
88   {
89     char* __old = setlocale(LC_CTYPE, NULL);
90     char* __sav = NULL;
91     if (__builtin_strcmp(__old, "C"))
92       {
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");
97       }
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)
108       {
109         setlocale(LC_CTYPE, __sav);
110         delete [] __sav;
111       }
112     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
113     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
114   }
115 #endif
116
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)
125   {
126     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
127     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
128   }
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)
133   {
134     char* __old = setlocale(LC_CTYPE, NULL);
135     char* __sav = NULL;
136     if (__builtin_strcmp(__old, "C"))
137       {
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");
142       }
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)
153       {
154         setlocale(LC_CTYPE, __sav);
155         delete [] __sav;
156       }
157     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
158     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
159   }
160 #endif
161
162   char
163   ctype<char>::do_toupper(char __c) const
164   { return _M_toupper[static_cast<unsigned char>(__c)]; }
165
166   const char*
167   ctype<char>::do_toupper(char* __low, const char* __high) const
168   {
169     while (__low < __high)
170       {
171         *__low = _M_toupper[static_cast<unsigned char>(*__low)];
172         ++__low;
173       }
174     return __high;
175   }
176
177   char
178   ctype<char>::do_tolower(char __c) const
179   { return _M_tolower[static_cast<unsigned char>(__c)]; }
180
181   const char*
182   ctype<char>::do_tolower(char* __low, const char* __high) const
183   {
184     while (__low < __high)
185       {
186         *__low = _M_tolower[static_cast<unsigned char>(*__low)];
187         ++__low;
188       }
189     return __high;
190   }