1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 // Free Software Foundation, Inc.
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 2, or (at your option)
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 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 // As a special exception, you may use this file as part of a free software
24 // library without restriction. Specifically, if other files instantiate
25 // templates or use macros or inline functions from this file, or you compile
26 // this file and link it with other files to produce an executable, this
27 // file does not by itself cause the resulting executable to be covered by
28 // the GNU General Public License. This exception does not however
29 // invalidate any other reasons why the executable file might be covered by
30 // the GNU General Public License.
32 /** @file ctype_noninline.h
33 * This is an internal header file, included by other library headers.
34 * You should not attempt to use it directly.
38 // ISO C++ 14882: 22.1 Locales
41 // Information as gleaned from /usr/include/ctype.h
43 #if _GLIBCXX_C_LOCALE_GNU
44 const ctype_base::mask*
45 ctype<char>::classic_table() throw()
46 { return _S_get_c_locale()->__ctype_b; }
48 const ctype_base::mask*
49 ctype<char>::classic_table() throw()
51 const ctype_base::mask* __ret;
52 char* __old = setlocale(LC_CTYPE, NULL);
53 const size_t __len = __builtin_strlen(__old) + 1;
54 char* __sav = new char[__len];
55 __builtin_memcpy(__sav, __old, __len);
56 setlocale(LC_CTYPE, "C");
57 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
58 __ret = *__ctype_b_loc();
62 setlocale(LC_CTYPE, __sav);
68 #if _GLIBCXX_C_LOCALE_GNU
69 ctype<char>::ctype(__c_locale __cloc, const mask* __table, bool __del,
71 : facet(__refs), _M_c_locale_ctype(_S_clone_c_locale(__cloc)),
72 _M_del(__table != 0 && __del),
73 _M_toupper(_M_c_locale_ctype->__ctype_toupper),
74 _M_tolower(_M_c_locale_ctype->__ctype_tolower),
75 _M_table(__table ? __table : _M_c_locale_ctype->__ctype_b),
76 _M_widen_ok(0), _M_narrow_ok(0)
78 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
79 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
82 ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
84 : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()),
85 _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0)
87 char* __old = setlocale(LC_CTYPE, NULL);
88 const size_t __len = __builtin_strlen(__old) + 1;
89 char* __sav = new char[__len];
90 __builtin_memcpy(__sav, __old, __len);
91 setlocale(LC_CTYPE, "C");
92 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
93 _M_toupper = *__ctype_toupper_loc();
94 _M_tolower = *__ctype_tolower_loc();
95 _M_table = __table ? __table : *__ctype_b_loc();
97 _M_toupper = __ctype_toupper;
98 _M_tolower = __ctype_tolower;
99 _M_table = __table ? __table : __ctype_b;
101 setlocale(LC_CTYPE, __sav);
103 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
104 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
108 #if _GLIBCXX_C_LOCALE_GNU
109 ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
110 : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()),
111 _M_del(__table != 0 && __del),
112 _M_toupper(_M_c_locale_ctype->__ctype_toupper),
113 _M_tolower(_M_c_locale_ctype->__ctype_tolower),
114 _M_table(__table ? __table : _M_c_locale_ctype->__ctype_b),
115 _M_widen_ok(0), _M_narrow_ok(0)
117 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
118 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
121 ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
122 : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()),
123 _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0)
125 char* __old = setlocale(LC_CTYPE, NULL);
126 const size_t __len = __builtin_strlen(__old) + 1;
127 char* __sav = new char[__len];
128 __builtin_memcpy(__sav, __old, __len);
129 setlocale(LC_CTYPE, "C");
130 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
131 _M_toupper = *__ctype_toupper_loc();
132 _M_tolower = *__ctype_tolower_loc();
133 _M_table = __table ? __table : *__ctype_b_loc();
135 _M_toupper = __ctype_toupper;
136 _M_tolower = __ctype_tolower;
137 _M_table = __table ? __table : __ctype_b;
139 setlocale(LC_CTYPE, __sav);
141 __builtin_memset(_M_widen, 0, sizeof(_M_widen));
142 __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
147 ctype<char>::do_toupper(char __c) const
148 { return _M_toupper[static_cast<unsigned char>(__c)]; }
151 ctype<char>::do_toupper(char* __low, const char* __high) const
153 while (__low < __high)
155 *__low = _M_toupper[static_cast<unsigned char>(*__low)];
162 ctype<char>::do_tolower(char __c) const
163 { return _M_tolower[static_cast<unsigned char>(__c)]; }
166 ctype<char>::do_tolower(char* __low, const char* __high) const
168 while (__low < __high)
170 *__low = _M_tolower[static_cast<unsigned char>(*__low)];