1 // Locale support -*- C++ -*-
3 // Copyright (C) 2000, 2003, 2009, 2010 Free Software Foundation, Inc.
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 3, or (at your option)
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.
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.
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/>.
25 /** @file bits/ctype_inline.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{locale}
31 // ISO C++ 14882: 22.1 Locales
34 // ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
35 // functions go in ctype.cc
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.
42 // Constructing a synthetic "C" table should be seriously considered...
44 namespace std
_GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 is(mask __m
, char __c
) const
53 return _M_table
[static_cast<unsigned char>(__c
)] & __m
;
57 const size_t __bitmasksize
= 15;
58 size_t __bitcur
= 0; // Lowest bitmask in ctype_base == 0
59 for (; __bitcur
<= __bitmasksize
; ++__bitcur
)
61 const mask __bit
= static_cast<mask
>(1 << __bitcur
);
68 __testis
= isspace(__c
);
71 __testis
= isprint(__c
);
74 __testis
= iscntrl(__c
);
77 __testis
= isupper(__c
);
80 __testis
= islower(__c
);
83 __testis
= isalpha(__c
);
86 __testis
= isdigit(__c
);
89 __testis
= ispunct(__c
);
92 __testis
= isxdigit(__c
);
95 __testis
= isalnum(__c
);
98 __testis
= isgraph(__c
);
113 is(const char* __low
, const char* __high
, mask
* __vec
) const
116 while (__low
< __high
)
117 *__vec
++ = _M_table
[static_cast<unsigned char>(*__low
++)];
120 // Highest bitmask in ctype_base == 10.
121 const size_t __bitmasksize
= 15;
122 for (;__low
< __high
; ++__vec
, ++__low
)
125 // Lowest bitmask in ctype_base == 0
127 for (;__i
<= __bitmasksize
; ++__i
)
129 const mask __bit
= static_cast<mask
>(1 << __i
);
130 if (this->is(__bit
, *__low
))
141 scan_is(mask __m
, const char* __low
, const char* __high
) const
144 while (__low
< __high
145 && !(_M_table
[static_cast<unsigned char>(*__low
)] & __m
))
148 while (__low
< __high
&& !this->is(__m
, *__low
))
155 scan_not(mask __m
, const char* __low
, const char* __high
) const
158 while (__low
< __high
159 && (_M_table
[static_cast<unsigned char>(*__low
)] & __m
) != 0)
162 while (__low
< __high
&& this->is(__m
, *__low
) != 0)
167 _GLIBCXX_END_NAMESPACE_VERSION