1// Locale support -*- C++ -*- 2 3// Copyright (C) 2000, 2003, 2004 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_GLIBCXX_BEGIN_NAMESPACE(std) 43 44#if BUILDING_LIBSTDCXX 45__attribute__((used)) 46#endif 47bool 48 ctype<char>:: 49 is(mask __m, char __c) const 50 { 51 if (_M_table) 52 return _M_table[static_cast<unsigned char>(__c)] & __m; 53 else 54 return __istype(__c, __m); 55 } 56 57 const char* 58 ctype<char>:: 59 is(const char* __low, const char* __high, mask* __vec) const 60 { 61 if (_M_table) 62 while (__low < __high) 63 *__vec++ = _M_table[static_cast<unsigned char>(*__low++)]; 64 else 65 for (;__low < __high; ++__vec, ++__low) 66 { 67#if defined (_CTYPE_S) || defined (__istype) 68 *__vec = __maskrune (*__low, upper | lower | alpha | digit | xdigit 69 | space | print | graph | cntrl | punct | alnum); 70#else 71 mask __m = 0; 72 if (this->is(upper, *__low)) __m |= upper; 73 if (this->is(lower, *__low)) __m |= lower; 74 if (this->is(alpha, *__low)) __m |= alpha; 75 if (this->is(digit, *__low)) __m |= digit; 76 if (this->is(xdigit, *__low)) __m |= xdigit; 77 if (this->is(space, *__low)) __m |= space; 78 if (this->is(print, *__low)) __m |= print; 79 if (this->is(graph, *__low)) __m |= graph; 80 if (this->is(cntrl, *__low)) __m |= cntrl; 81 if (this->is(punct, *__low)) __m |= punct; 82 // Do not include explicit line for alnum mask since it is a 83 // pure composite of masks on FreeBSD. 84 *__vec = __m; 85#endif 86 } 87 return __high; 88 } 89 90#if BUILDING_LIBSTDCXX 91__attribute__((used)) 92#endif 93const char* 94 ctype<char>:: 95 scan_is(mask __m, const char* __low, const char* __high) const 96 { 97 if (_M_table) 98 while (__low < __high 99 && !(_M_table[static_cast<unsigned char>(*__low)] & __m)) 100 ++__low; 101 else 102 while (__low < __high && !this->is(__m, *__low)) 103 ++__low; 104 return __low; 105 } 106 107#if BUILDING_LIBSTDCXX 108__attribute__((used)) 109#endif 110const char* 111 ctype<char>:: 112 scan_not(mask __m, const char* __low, const char* __high) const 113 { 114 if (_M_table) 115 while (__low < __high 116 && (_M_table[static_cast<unsigned char>(*__low)] & __m) != 0) 117 ++__low; 118 else 119 while (__low < __high && this->is(__m, *__low) != 0) 120 ++__low; 121 return __low; 122 } 123 124#ifdef _GLIBCXX_USE_WCHAR_T 125 inline bool 126 ctype<wchar_t>:: 127 do_is(mask __m, wchar_t __c) const 128 { 129 return __istype (__c, __m); 130 } 131 132 inline const wchar_t* 133 ctype<wchar_t>:: 134 do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const 135 { 136 for (; __lo < __hi; ++__vec, ++__lo) 137 *__vec = __maskrune (*__lo, upper | lower | alpha | digit | xdigit 138 | space | print | graph | cntrl | punct | alnum); 139 return __hi; 140 } 141 142 inline const wchar_t* 143 ctype<wchar_t>:: 144 do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const 145 { 146 while (__lo < __hi && ! __istype (*__lo, __m)) 147 ++__lo; 148 return __lo; 149 } 150 151 inline const wchar_t* 152 ctype<wchar_t>:: 153 do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const 154 { 155 while (__lo < __hi && __istype (*__lo, __m)) 156 ++__lo; 157 return __lo; 158 } 159#endif 160 161_GLIBCXX_END_NAMESPACE 162