OSDN Git Service

2007-05-11 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / 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
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 2, 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 // 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,
21 // USA.
22
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.
31
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.
35  */
36
37 //
38 // ISO C++ 14882: 22.1  Locales
39 //
40   
41 // Information as gleaned from /usr/include/ctype.h
42
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; }
47 #else
48   const ctype_base::mask*
49   ctype<char>::classic_table() throw()
50   {
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();
59 #else
60     __ret = __ctype_b;
61 #endif
62     setlocale(LC_CTYPE, __sav);
63     delete [] __sav;
64     return __ret;
65   }
66 #endif
67
68 #if _GLIBCXX_C_LOCALE_GNU
69   ctype<char>::ctype(__c_locale __cloc, const mask* __table, bool __del, 
70                      size_t __refs) 
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) 
77   {
78     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
79     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
80   }
81 #else
82   ctype<char>::ctype(__c_locale, const mask* __table, bool __del, 
83                      size_t __refs) 
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)
86   {
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();
96 #else
97     _M_toupper = __ctype_toupper;
98     _M_tolower = __ctype_tolower;
99     _M_table = __table ? __table : __ctype_b;
100 #endif
101     setlocale(LC_CTYPE, __sav);
102     delete [] __sav;
103     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
104     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
105   }
106 #endif
107
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) 
116   {
117     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
118     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
119   }
120 #else
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)
124   {
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();
134 #else
135     _M_toupper = __ctype_toupper;
136     _M_tolower = __ctype_tolower;
137     _M_table = __table ? __table : __ctype_b;
138 #endif
139     setlocale(LC_CTYPE, __sav);
140     delete [] __sav;
141     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
142     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
143   }
144 #endif
145
146   char
147   ctype<char>::do_toupper(char __c) const
148   { return _M_toupper[static_cast<unsigned char>(__c)]; }
149
150   const char*
151   ctype<char>::do_toupper(char* __low, const char* __high) const
152   {
153     while (__low < __high)
154       {
155         *__low = _M_toupper[static_cast<unsigned char>(*__low)];
156         ++__low;
157       }
158     return __high;
159   }
160
161   char
162   ctype<char>::do_tolower(char __c) const
163   { return _M_tolower[static_cast<unsigned char>(__c)]; }
164
165   const char* 
166   ctype<char>::do_tolower(char* __low, const char* __high) const
167   {
168     while (__low < __high)
169       {
170         *__low = _M_tolower[static_cast<unsigned char>(*__low)];
171         ++__low;
172       }
173     return __high;
174   }