1 // Locale support -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 22.1 Locales
35 // Information as gleaned from /usr/include/ctype.h
37 #if _GLIBCXX_C_LOCALE_GNU
38 const ctype_base::mask
*
39 ctype
<char>::classic_table() throw()
40 { return _S_get_c_locale()->__ctype_b
; }
42 const ctype_base::mask
*
43 ctype
<char>::classic_table() throw()
45 const ctype_base::mask
* __ret
;
46 char* __old
= strdup(setlocale(LC_CTYPE
, NULL
));
47 setlocale(LC_CTYPE
, "C");
48 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
49 __ret
= *__ctype_b_loc();
53 setlocale(LC_CTYPE
, __old
);
59 #if _GLIBCXX_C_LOCALE_GNU
60 ctype
<char>::ctype(__c_locale __cloc
, const mask
* __table
, bool __del
,
62 : facet(__refs
), _M_del(__table
!= 0 && __del
)
64 _M_c_locale_ctype
= _S_clone_c_locale(__cloc
);
65 _M_toupper
= _M_c_locale_ctype
->__ctype_toupper
;
66 _M_tolower
= _M_c_locale_ctype
->__ctype_tolower
;
67 _M_table
= __table
? __table
: _M_c_locale_ctype
->__ctype_b
;
68 memset(_M_widen
, 0, sizeof(_M_widen
));
70 memset(_M_narrow
, 0, sizeof(_M_narrow
));
74 ctype
<char>::ctype(__c_locale
, const mask
* __table
, bool __del
,
76 : facet(__refs
), _M_del(__table
!= 0 && __del
)
78 char* __old
=strdup(setlocale(LC_CTYPE
, NULL
));
79 setlocale(LC_CTYPE
, "C");
80 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
81 _M_toupper
= *__ctype_toupper_loc();
82 _M_tolower
= *__ctype_tolower_loc();
83 _M_table
= __table
? __table
: *__ctype_b_loc();
85 _M_toupper
= __ctype_toupper
;
86 _M_tolower
= __ctype_tolower
;
87 _M_table
= __table
? __table
: __ctype_b
;
89 setlocale(LC_CTYPE
, __old
);
91 _M_c_locale_ctype
= _S_get_c_locale();
92 memset(_M_widen
, 0, sizeof(_M_widen
));
94 memset(_M_narrow
, 0, sizeof(_M_narrow
));
99 #if _GLIBCXX_C_LOCALE_GNU
100 ctype
<char>::ctype(const mask
* __table
, bool __del
, size_t __refs
)
101 : facet(__refs
), _M_del(__table
!= 0 && __del
)
103 _M_c_locale_ctype
= _S_get_c_locale();
104 _M_toupper
= _M_c_locale_ctype
->__ctype_toupper
;
105 _M_tolower
= _M_c_locale_ctype
->__ctype_tolower
;
106 _M_table
= __table
? __table
: _M_c_locale_ctype
->__ctype_b
;
107 memset(_M_widen
, 0, sizeof(_M_widen
));
109 memset(_M_narrow
, 0, sizeof(_M_narrow
));
113 ctype
<char>::ctype(const mask
* __table
, bool __del
, size_t __refs
)
114 : facet(__refs
), _M_del(__table
!= 0 && __del
)
116 char* __old
=strdup(setlocale(LC_CTYPE
, NULL
));
117 setlocale(LC_CTYPE
, "C");
118 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
119 _M_toupper
= *__ctype_toupper_loc();
120 _M_tolower
= *__ctype_tolower_loc();
121 _M_table
= __table
? __table
: *__ctype_b_loc();
123 _M_toupper
= __ctype_toupper
;
124 _M_tolower
= __ctype_tolower
;
125 _M_table
= __table
? __table
: __ctype_b
;
127 setlocale(LC_CTYPE
, __old
);
129 _M_c_locale_ctype
= _S_get_c_locale();
130 memset(_M_widen
, 0, sizeof(_M_widen
));
132 memset(_M_narrow
, 0, sizeof(_M_narrow
));
138 ctype
<char>::do_toupper(char __c
) const
139 { return _M_toupper
[static_cast<unsigned char>(__c
)]; }
142 ctype
<char>::do_toupper(char* __low
, const char* __high
) const
144 while (__low
< __high
)
146 *__low
= _M_toupper
[static_cast<unsigned char>(*__low
)];
153 ctype
<char>::do_tolower(char __c
) const
154 { return _M_tolower
[static_cast<unsigned char>(__c
)]; }
157 ctype
<char>::do_tolower(char* __low
, const char* __high
) const
159 while (__low
< __high
)
161 *__low
= _M_tolower
[static_cast<unsigned char>(*__low
)];