]>
Commit | Line | Data |
---|---|---|
f7702127 | 1 | // Locale support -*- C++ -*- |
2 | ||
71e45bc2 | 3 | // Copyright (C) 2000, 2003, 2009, 2010, 2011 Free Software Foundation, Inc. |
f7702127 | 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 | |
6bc9506f | 8 | // Free Software Foundation; either version 3, or (at your option) |
f7702127 | 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 | ||
6bc9506f | 16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
f7702127 | 19 | |
6bc9506f | 20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
f7702127 | 24 | |
5846aeac | 25 | /** @file bits/ctype_inline.h |
944beac5 | 26 | * This is an internal header file, included by other library headers. |
5846aeac | 27 | * Do not attempt to use it directly. @headername{locale} |
944beac5 | 28 | */ |
29 | ||
f7702127 | 30 | // |
31 | // ISO C++ 14882: 22.1 Locales | |
32 | // | |
33 | ||
34 | // ctype bits to be inlined go here. Non-inlinable (ie virtual do_*) | |
35 | // functions go in ctype.cc | |
36 | ||
7943f969 | 37 | // The following definitions are portable, but insanely slow. If one |
38 | // cares at all about performance, then specialized ctype | |
39 | // functionality should be added for the native os in question: see | |
40 | // the config/os/bits/ctype_*.h files. | |
41 | ||
3eb7dfb2 | 42 | // Constructing a synthetic "C" table should be seriously considered... |
43 | ||
2948dd21 | 44 | namespace std _GLIBCXX_VISIBILITY(default) |
45 | { | |
46 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
944beac5 | 47 | |
f7702127 | 48 | bool |
49 | ctype<char>:: | |
5bb0adbf | 50 | is(mask __m, char __c) const |
7943f969 | 51 | { |
3eb7dfb2 | 52 | if (_M_table) |
53 | return _M_table[static_cast<unsigned char>(__c)] & __m; | |
54 | else | |
7943f969 | 55 | { |
077dd222 | 56 | bool __ret = false; |
57 | const size_t __bitmasksize = 15; | |
5ce41087 | 58 | size_t __bitcur = 0; // Lowest bitmask in ctype_base == 0 |
077dd222 | 59 | for (; __bitcur <= __bitmasksize; ++__bitcur) |
3eb7dfb2 | 60 | { |
077dd222 | 61 | const mask __bit = static_cast<mask>(1 << __bitcur); |
3eb7dfb2 | 62 | if (__m & __bit) |
63 | { | |
64 | bool __testis; | |
65 | switch (__bit) | |
66 | { | |
67 | case space: | |
68 | __testis = isspace(__c); | |
69 | break; | |
70 | case print: | |
71 | __testis = isprint(__c); | |
72 | break; | |
73 | case cntrl: | |
74 | __testis = iscntrl(__c); | |
75 | break; | |
76 | case upper: | |
77 | __testis = isupper(__c); | |
78 | break; | |
79 | case lower: | |
80 | __testis = islower(__c); | |
81 | break; | |
82 | case alpha: | |
83 | __testis = isalpha(__c); | |
84 | break; | |
85 | case digit: | |
86 | __testis = isdigit(__c); | |
87 | break; | |
88 | case punct: | |
89 | __testis = ispunct(__c); | |
90 | break; | |
91 | case xdigit: | |
92 | __testis = isxdigit(__c); | |
93 | break; | |
94 | case alnum: | |
95 | __testis = isalnum(__c); | |
96 | break; | |
97 | case graph: | |
98 | __testis = isgraph(__c); | |
99 | break; | |
100 | default: | |
101 | __testis = false; | |
102 | break; | |
103 | } | |
077dd222 | 104 | __ret |= __testis; |
3eb7dfb2 | 105 | } |
106 | } | |
077dd222 | 107 | return __ret; |
7943f969 | 108 | } |
7943f969 | 109 | } |
110 | ||
f7702127 | 111 | const char* |
112 | ctype<char>:: | |
5bb0adbf | 113 | is(const char* __low, const char* __high, mask* __vec) const |
f7702127 | 114 | { |
3eb7dfb2 | 115 | if (_M_table) |
116 | while (__low < __high) | |
117 | *__vec++ = _M_table[static_cast<unsigned char>(*__low++)]; | |
118 | else | |
65f26f92 | 119 | { |
3eb7dfb2 | 120 | // Highest bitmask in ctype_base == 10. |
077dd222 | 121 | const size_t __bitmasksize = 15; |
3eb7dfb2 | 122 | for (;__low < __high; ++__vec, ++__low) |
c1d84143 | 123 | { |
3eb7dfb2 | 124 | mask __m = 0; |
125 | // Lowest bitmask in ctype_base == 0 | |
5ce41087 | 126 | size_t __i = 0; |
127 | for (;__i <= __bitmasksize; ++__i) | |
3eb7dfb2 | 128 | { |
077dd222 | 129 | const mask __bit = static_cast<mask>(1 << __i); |
3eb7dfb2 | 130 | if (this->is(__bit, *__low)) |
131 | __m |= __bit; | |
132 | } | |
133 | *__vec = __m; | |
c1d84143 | 134 | } |
65f26f92 | 135 | } |
f7702127 | 136 | return __high; |
137 | } | |
138 | ||
139 | const char* | |
140 | ctype<char>:: | |
5bb0adbf | 141 | scan_is(mask __m, const char* __low, const char* __high) const |
f7702127 | 142 | { |
3eb7dfb2 | 143 | if (_M_table) |
144 | while (__low < __high | |
145 | && !(_M_table[static_cast<unsigned char>(*__low)] & __m)) | |
146 | ++__low; | |
147 | else | |
148 | while (__low < __high && !this->is(__m, *__low)) | |
149 | ++__low; | |
f7702127 | 150 | return __low; |
151 | } | |
152 | ||
153 | const char* | |
154 | ctype<char>:: | |
5bb0adbf | 155 | scan_not(mask __m, const char* __low, const char* __high) const |
f7702127 | 156 | { |
3eb7dfb2 | 157 | if (_M_table) |
158 | while (__low < __high | |
159 | && (_M_table[static_cast<unsigned char>(*__low)] & __m) != 0) | |
160 | ++__low; | |
161 | else | |
162 | while (__low < __high && this->is(__m, *__low) != 0) | |
163 | ++__low; | |
f7702127 | 164 | return __low; |
165 | } | |
944beac5 | 166 | |
2948dd21 | 167 | _GLIBCXX_END_NAMESPACE_VERSION |
168 | } // namespace |