1117397Skan// Locale support -*- C++ -*- 2117397Skan 3169691Skan// Copyright (C) 2000, 2003, 2004, 2005 Free Software Foundation, Inc. 4117397Skan// 5117397Skan// This file is part of the GNU ISO C++ Library. This library is free 6117397Skan// software; you can redistribute it and/or modify it under the 7117397Skan// terms of the GNU General Public License as published by the 8117397Skan// Free Software Foundation; either version 2, or (at your option) 9117397Skan// any later version. 10117397Skan 11117397Skan// This library is distributed in the hope that it will be useful, 12117397Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 13117397Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14117397Skan// GNU General Public License for more details. 15117397Skan 16117397Skan// You should have received a copy of the GNU General Public License along 17117397Skan// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19117397Skan// USA. 20117397Skan 21117397Skan// As a special exception, you may use this file as part of a free software 22117397Skan// library without restriction. Specifically, if other files instantiate 23117397Skan// templates or use macros or inline functions from this file, or you compile 24117397Skan// this file and link it with other files to produce an executable, this 25117397Skan// file does not by itself cause the resulting executable to be covered by 26117397Skan// the GNU General Public License. This exception does not however 27117397Skan// invalidate any other reasons why the executable file might be covered by 28117397Skan// the GNU General Public License. 29117397Skan 30169691Skan/** @file ctype_inline.h 31169691Skan * This is an internal header file, included by other library headers. 32169691Skan * You should not attempt to use it directly. 33169691Skan */ 34169691Skan 35117397Skan// 36117397Skan// ISO C++ 14882: 22.1 Locales 37117397Skan// 38117397Skan 39117397Skan// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*) 40117397Skan// functions go in ctype.cc 41117397Skan 42169691Skan_GLIBCXX_BEGIN_NAMESPACE(std) 43169691Skan 44117397Skan bool 45117397Skan ctype<char>:: 46117397Skan is(mask __m, char __c) const 47117397Skan { 48117397Skan if (_M_table) 49117397Skan return _M_table[static_cast<unsigned char>(__c)] & __m; 50117397Skan else 51117397Skan return __istype(__c, __m); 52117397Skan } 53117397Skan 54117397Skan const char* 55117397Skan ctype<char>:: 56117397Skan is(const char* __low, const char* __high, mask* __vec) const 57117397Skan { 58117397Skan if (_M_table) 59117397Skan while (__low < __high) 60117397Skan *__vec++ = _M_table[static_cast<unsigned char>(*__low++)]; 61117397Skan else 62117397Skan for (;__low < __high; ++__vec, ++__low) 63117397Skan { 64117397Skan#if defined (_CTYPE_S) || defined (__istype) 65117397Skan *__vec = __maskrune (*__low, upper | lower | alpha | digit | xdigit 66117397Skan | space | print | graph | cntrl | punct | alnum); 67117397Skan#else 68117397Skan mask __m = 0; 69117397Skan if (this->is(upper, *__low)) __m |= upper; 70117397Skan if (this->is(lower, *__low)) __m |= lower; 71117397Skan if (this->is(alpha, *__low)) __m |= alpha; 72117397Skan if (this->is(digit, *__low)) __m |= digit; 73117397Skan if (this->is(xdigit, *__low)) __m |= xdigit; 74117397Skan if (this->is(space, *__low)) __m |= space; 75117397Skan if (this->is(print, *__low)) __m |= print; 76117397Skan if (this->is(graph, *__low)) __m |= graph; 77117397Skan if (this->is(cntrl, *__low)) __m |= cntrl; 78117397Skan if (this->is(punct, *__low)) __m |= punct; 79117397Skan // Do not include explicit line for alnum mask since it is a 80117397Skan // pure composite of masks on FreeBSD. 81117397Skan *__vec = __m; 82117397Skan#endif 83117397Skan } 84117397Skan return __high; 85117397Skan } 86117397Skan 87117397Skan const char* 88117397Skan ctype<char>:: 89117397Skan scan_is(mask __m, const char* __low, const char* __high) const 90117397Skan { 91117397Skan if (_M_table) 92117397Skan while (__low < __high 93117397Skan && !(_M_table[static_cast<unsigned char>(*__low)] & __m)) 94117397Skan ++__low; 95117397Skan else 96117397Skan while (__low < __high && !this->is(__m, *__low)) 97117397Skan ++__low; 98117397Skan return __low; 99117397Skan } 100117397Skan 101117397Skan const char* 102117397Skan ctype<char>:: 103117397Skan scan_not(mask __m, const char* __low, const char* __high) const 104117397Skan { 105117397Skan if (_M_table) 106117397Skan while (__low < __high 107117397Skan && (_M_table[static_cast<unsigned char>(*__low)] & __m) != 0) 108117397Skan ++__low; 109117397Skan else 110117397Skan while (__low < __high && this->is(__m, *__low) != 0) 111117397Skan ++__low; 112117397Skan return __low; 113117397Skan } 114169691Skan 115169691Skan#ifdef _GLIBCXX_USE_WCHAR_T 116169691Skan inline bool 117169691Skan ctype<wchar_t>:: 118169691Skan do_is(mask __m, wchar_t __c) const 119169691Skan { 120169691Skan return __istype (__c, __m); 121169691Skan } 122169691Skan 123169691Skan inline const wchar_t* 124169691Skan ctype<wchar_t>:: 125169691Skan do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const 126169691Skan { 127169691Skan for (; __lo < __hi; ++__vec, ++__lo) 128169691Skan *__vec = __maskrune (*__lo, upper | lower | alpha | digit | xdigit 129169691Skan | space | print | graph | cntrl | punct | alnum); 130169691Skan return __hi; 131169691Skan } 132169691Skan 133169691Skan inline const wchar_t* 134169691Skan ctype<wchar_t>:: 135169691Skan do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const 136169691Skan { 137169691Skan while (__lo < __hi && ! __istype (*__lo, __m)) 138169691Skan ++__lo; 139169691Skan return __lo; 140169691Skan } 141169691Skan 142169691Skan inline const wchar_t* 143169691Skan ctype<wchar_t>:: 144169691Skan do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const 145169691Skan { 146169691Skan while (__lo < __hi && __istype (*__lo, __m)) 147169691Skan ++__lo; 148169691Skan return __lo; 149169691Skan } 150169691Skan#endif 151169691Skan 152169691Skan_GLIBCXX_END_NAMESPACE 153