]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libstdc++/config/os/generic/ctype_inline.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / libstdc++ / config / os / generic / ctype_inline.h
1 // Locale support -*- C++ -*-
2
3 // Copyright (C) 2000, 2003 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file ctype_inline.h
31  *  This is an internal header file, included by other library headers.
32  *  You should not attempt to use it directly.
33  */
34
35 //
36 // ISO C++ 14882: 22.1  Locales
37 //
38   
39 // ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
40 // functions go in ctype.cc
41   
42 // The following definitions are portable, but insanely slow. If one
43 // cares at all about performance, then specialized ctype
44 // functionality should be added for the native os in question: see
45 // the config/os/bits/ctype_*.h files.
46
47 // Constructing a synthetic "C" table should be seriously considered...
48
49 _GLIBCXX_BEGIN_NAMESPACE(std)
50
51   bool
52   ctype<char>::
53   is(mask __m, char __c) const
54   { 
55     if (_M_table)
56       return _M_table[static_cast<unsigned char>(__c)] & __m;
57     else
58       {
59         bool __ret = false;
60         const size_t __bitmasksize = 15; 
61         size_t __bitcur = 0; // Lowest bitmask in ctype_base == 0
62         for (; __bitcur <= __bitmasksize; ++__bitcur)
63           {
64             const mask __bit = static_cast<mask>(1 << __bitcur);
65             if (__m & __bit)
66               {
67                 bool __testis;
68                 switch (__bit)
69                   {
70                   case space:
71                     __testis = isspace(__c);
72                     break;
73                   case print:
74                     __testis = isprint(__c);
75                     break;
76                   case cntrl:
77                     __testis = iscntrl(__c);
78                     break;
79                   case upper:
80                     __testis = isupper(__c);
81                     break;
82                   case lower:
83                     __testis = islower(__c);
84                     break;
85                   case alpha:
86                     __testis = isalpha(__c);
87                     break;
88                   case digit:
89                     __testis = isdigit(__c);
90                     break;
91                   case punct:
92                     __testis = ispunct(__c);
93                     break;
94                   case xdigit:
95                     __testis = isxdigit(__c);
96                     break;
97                   case alnum:
98                     __testis = isalnum(__c);
99                     break;
100                   case graph:
101                     __testis = isgraph(__c);
102                     break;
103                   default:
104                     __testis = false;
105                     break;
106                   }
107                 __ret |= __testis;
108               }
109           }
110         return __ret;
111       }
112   }
113    
114   const char*
115   ctype<char>::
116   is(const char* __low, const char* __high, mask* __vec) const
117   {
118     if (_M_table)
119       while (__low < __high)
120         *__vec++ = _M_table[static_cast<unsigned char>(*__low++)];
121     else
122       {
123         // Highest bitmask in ctype_base == 10.
124         const size_t __bitmasksize = 15; 
125         for (;__low < __high; ++__vec, ++__low)
126           {
127             mask __m = 0;
128             // Lowest bitmask in ctype_base == 0
129             size_t __i = 0; 
130             for (;__i <= __bitmasksize; ++__i)
131               {
132                 const mask __bit = static_cast<mask>(1 << __i);
133                 if (this->is(__bit, *__low))
134                   __m |= __bit;
135               }
136             *__vec = __m;
137           }
138       }
139     return __high;
140   }
141
142   const char*
143   ctype<char>::
144   scan_is(mask __m, const char* __low, const char* __high) const
145   {
146     if (_M_table)
147       while (__low < __high
148              && !(_M_table[static_cast<unsigned char>(*__low)] & __m))
149         ++__low;
150     else
151       while (__low < __high && !this->is(__m, *__low))
152         ++__low;
153     return __low;
154   }
155
156   const char*
157   ctype<char>::
158   scan_not(mask __m, const char* __low, const char* __high) const
159   {
160     if (_M_table)
161       while (__low < __high
162              && (_M_table[static_cast<unsigned char>(*__low)] & __m) != 0)
163         ++__low;
164     else
165       while (__low < __high && this->is(__m, *__low) != 0)
166         ++__low;
167     return __low;
168   }
169
170 _GLIBCXX_END_NAMESPACE