]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/config/locale/darwin/ctype_members.cc
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / config / locale / darwin / ctype_members.cc
1 // std::ctype implementation details, GNU version -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11
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.
16
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
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.
30
31 //
32 // ISO C++ 14882: 22.2.1.1.2  ctype virtual functions.
33 //
34
35 // Written by Benjamin Kosnik <bkoz@redhat.com>
36
37 #include <locale>
38 #include <bits/c++locale_internal.h>
39 #include <cstdlib>
40 #include <cstring>
41
42 namespace std
43 {
44   // NB: The other ctype<char> specializations are in src/locale.cc and
45   // various /config/os/* files.
46
47   ctype_byname<char>::ctype_byname(const char* __s, size_t __refs)
48   : ctype<char>(0, false, __refs) 
49   {             
50     if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
51       {
52         this->_S_destroy_c_locale(this->_M_c_locale_ctype);
53         this->_S_create_c_locale(this->_M_c_locale_ctype, __s); 
54       }
55   }
56
57   ctype_byname<char>::~ctype_byname()
58   { }
59
60 #ifdef _GLIBCXX_USE_WCHAR_T  
61   ctype<wchar_t>::__wmask_type
62   ctype<wchar_t>::_M_convert_to_wmask(const mask __m) const
63   {
64     // Darwin uses the same codes for 'char' as 'wchar_t', so this routine
65     // never gets called.
66     return __m;
67   };
68   
69   wchar_t
70   ctype<wchar_t>::do_toupper(wchar_t __c) const
71   { return towupper(__c); }
72
73   const wchar_t*
74   ctype<wchar_t>::do_toupper(wchar_t* __lo, const wchar_t* __hi) const
75   {
76     while (__lo < __hi)
77       {
78         *__lo = towupper(*__lo);
79         ++__lo;
80       }
81     return __hi;
82   }
83   
84   wchar_t
85   ctype<wchar_t>::do_tolower(wchar_t __c) const
86   { return towlower(__c); }
87   
88   const wchar_t*
89   ctype<wchar_t>::do_tolower(wchar_t* __lo, const wchar_t* __hi) const
90   {
91     while (__lo < __hi)
92       {
93         *__lo = towlower(*__lo);
94         ++__lo;
95       }
96     return __hi;
97   }
98
99   wchar_t
100   ctype<wchar_t>::
101   do_widen(char __c) const
102   { return _M_widen[static_cast<unsigned char>(__c)]; }
103
104   const char* 
105   ctype<wchar_t>::
106   do_widen(const char* __lo, const char* __hi, wchar_t* __dest) const
107   {
108     while (__lo < __hi)
109       {
110         *__dest = _M_widen[static_cast<unsigned char>(*__lo)];
111         ++__lo;
112         ++__dest;
113       }
114     return __hi;
115   }
116
117   char
118   ctype<wchar_t>::
119   do_narrow(wchar_t __wc, char __dfault) const
120   { 
121     if (__wc >= 0 && __wc < 128 && _M_narrow_ok)
122       return _M_narrow[__wc];
123     const int __c = wctob(__wc);
124     return (__c == EOF ? __dfault : static_cast<char>(__c)); 
125   }
126
127   const wchar_t*
128   ctype<wchar_t>::
129   do_narrow(const wchar_t* __lo, const wchar_t* __hi, char __dfault, 
130             char* __dest) const
131   {
132     if (_M_narrow_ok)
133       while (__lo < __hi)
134         {
135           if (*__lo >= 0 && *__lo < 128)
136             *__dest = _M_narrow[*__lo];
137           else
138             {
139               const int __c = wctob(*__lo);
140               *__dest = (__c == EOF ? __dfault : static_cast<char>(__c));
141             }
142           ++__lo;
143           ++__dest;
144         }
145     else
146       while (__lo < __hi)
147         {
148           const int __c = wctob(*__lo);
149           *__dest = (__c == EOF ? __dfault : static_cast<char>(__c));
150           ++__lo;
151           ++__dest;
152         }
153     return __hi;
154   }
155
156   void
157   ctype<wchar_t>::_M_initialize_ctype()
158   {
159     wint_t __i;
160     for (__i = 0; __i < 128; ++__i)
161       {
162         const int __c = wctob(__i);
163         if (__c == EOF)
164           break;
165         else
166           _M_narrow[__i] = static_cast<char>(__c);
167       }
168     if (__i == 128)
169       _M_narrow_ok = true;
170     else
171       _M_narrow_ok = false;
172     for (size_t __i = 0;
173          __i < sizeof(_M_widen) / sizeof(wint_t); ++__i)
174       _M_widen[__i] = btowc(__i);
175   }
176 #endif //  _GLIBCXX_USE_WCHAR_T
177 }