]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/config/os/gnu-linux/ctype_noninline.h
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 3, 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 // 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
; }
43 const ctype_base::mask
*
44 ctype
<char>::classic_table() throw()
46 const ctype_base::mask
* __ret
;
47 char* __old
= setlocale(LC_CTYPE
, 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();
63 setlocale(LC_CTYPE
, __sav
);
70 #if _GLIBCXX_C_LOCALE_GNU
71 ctype
<char>::ctype(__c_locale __cloc
, const mask
* __table
, bool __del
,
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
));
84 ctype
<char>::ctype(__c_locale
, const mask
* __table
, bool __del
,
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
);
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();
103 _M_toupper
= __ctype_toupper
;
104 _M_tolower
= __ctype_tolower
;
105 _M_table
= __table
? __table
: __ctype_b
;
109 setlocale(LC_CTYPE
, __sav
);
112 __builtin_memset(_M_widen
, 0, sizeof(_M_widen
));
113 __builtin_memset(_M_narrow
, 0, sizeof(_M_narrow
));
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
));
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
);
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();
148 _M_toupper
= __ctype_toupper
;
149 _M_tolower
= __ctype_tolower
;
150 _M_table
= __table
? __table
: __ctype_b
;
154 setlocale(LC_CTYPE
, __sav
);
157 __builtin_memset(_M_widen
, 0, sizeof(_M_widen
));
158 __builtin_memset(_M_narrow
, 0, sizeof(_M_narrow
));
163 ctype
<char>::do_toupper(char __c
) const
164 { return _M_toupper
[static_cast<unsigned char>(__c
)]; }
167 ctype
<char>::do_toupper(char* __low
, const char* __high
) const
169 while (__low
< __high
)
171 *__low
= _M_toupper
[static_cast<unsigned char>(*__low
)];
178 ctype
<char>::do_tolower(char __c
) const
179 { return _M_tolower
[static_cast<unsigned char>(__c
)]; }
182 ctype
<char>::do_tolower(char* __low
, const char* __high
) const
184 while (__low
< __high
)
186 *__low
= _M_tolower
[static_cast<unsigned char>(*__low
)];